检测交叉点 Turf.js,第一个和最后一个位置不相等

Detect intersection Turf.js, First and last Position are not equivalent

使用 Turf.js 版本 3.0.12。下面的函数应该 return 两个多边形之间的交点,如果它们不相交则为 null。多边形确实相交。我尝试了几种不同的多边形并收到相同的错误:

"Error: First and last Position are not equivalent."

我引用了这个例子:http://turfjs.org/docs#intersect

checkForIntersection = () => {
    const boundingBox1 = turf.polygon([
      [
        [-11638128.151894445, 4697704.8042823635],
        [-11538591.465504704, 4932847.347657125],
        [-11773734.008879466, 5032384.034046866],
        [-11873270.695269207, 4797241.490672104]
      ]
    ]);

    const boundingBox2 = turf.polygon([
      [
        [-11545948.977350365, 4658759.839788924],
        [-11483057.72508946, 5032936.709591224],
        [-11857234.59489176, 5095827.961852129],
        [-11920125.847152665, 4721651.092049829]
      ]
    ]);

    const intersection = turf.intersect(boundingBox1, boundingBox2);

    console.log("intersection: ", intersection);
  };

感谢观看!

这是因为每个多边形的第一个和最后一个点或位置必须相同。所以 boundingBox1 和 boundingBox2 将是:

checkForIntersection = () => {
    const boundingBox1 = turf.polygon([
      [
        [-11638128.151894445, 4697704.8042823635],
        [-11538591.465504704, 4932847.347657125],
        [-11773734.008879466, 5032384.034046866],
        [-11873270.695269207, 4797241.490672104],
        [-11638128.151894445, 4697704.8042823635],
      ]
    ]);

    const boundingBox2 = turf.polygon([
      [
        [-11545948.977350365, 4658759.839788924],
        [-11483057.72508946, 5032936.709591224],
        [-11857234.59489176, 5095827.961852129],
        [-11920125.847152665, 4721651.092049829],
        [-11545948.977350365, 4658759.839788924],
      ]
    ]);

    const intersection = turf.intersect(boundingBox1, boundingBox2);

    console.log("intersection: ", intersection);
  };