const poly = turf.polygon(obj.features[0].geometry.coordinates)
const point = turf.point(newPoint)
const isWithinBoundary = turf.booleanPointInPolygon(point, poly)
console.log(isWithinBoundary, '点是否在面内')
ps:需要注意的是,
如果使用turf.polygon([[obj.features[0].geometry.coordinates]])
,
那么他解析出来其实是turf.polygon([[[[[15445,15654],[15445,15654],[15445,15654],[15445,15654]]]]])
,
所以不能额外添加[[]]
,直接turf.polygon(obj.features[0].geometry.coordinates)
即可