How to get all visible points in the map view bounds in Azure Maps

时光总嘲笑我的痴心妄想 提交于 2021-01-29 13:17:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!