我一直在搜索并尝试在多边形示例中使用选择点的样本,但是我没有绘制一个新多边形,而是一个已经在地图中用作选择边界的多边形。我在地图上也有很多点,但有些点因为缩放比例而看不见或可能隐藏,所以我不想忽略所有这些点,即使它们在选择多边形中。这可能吗?// searchArea is populated by click method function searchPolygon(searchArea) { var visiblePointsOnly = ???; var poly = searchArea.toJson(); // This is failing saying toJson not a function? // Calculate all points that are within the polygon area. var ptsWithin = turf.pointsWithinPolygon(visiblePointsOnly, poly); return ptsWithin; }
1 回答
白猪掌柜的
TA贡献1893条经验 获得超10个赞
我设法弄清楚...可能不是最好的,但它可以满足我的需要!
function searchPolygon(searchArea) {
// Get points visible on map
var points = pointLayer.getSource();
if(points){
var poly = searchArea.shapes[0].toJson();
points = points.shapes[0].toJson();
// Calculate all points that are within the polygon area.
var ptsWithin = turf.pointsWithinPolygon(points, poly);
}
return ptsWithin;
}
希望这将帮助其他需要相同功能的人,干杯!瑞克...
添加回答
举报
0/150
提交
取消