问题
I've been searching and trying to use a sample of the select point within a polygon example however I am not drawing a new polygon but rather one is already in the map to use as selection boundary. I have many points on the map as well but some are out of view or possibly hidden due to zoom ratio so I w/ant to ignore all those points from being selected even if they are in the selection polygon. Is this possible?
// 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;
}
TIA! Rick...
回答1:
I managed to figure it out...might not be the best but it does what I need it to do!
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;
}
Hopefully this will help others needing the same functionality, Cheers! Rick...
来源:https://stackoverflow.com/questions/61260445/how-to-get-all-visible-points-in-the-map-view-bounds-in-azure-maps