admin管理员组

文章数量:1434934

Example I have create 6 markers on and after zoom change on the current view of map I have 3 markers So how can I get list of current onscreen markers list after zoom change?

 map.on('zoomend', function(e) {
     // want to get current onscreen markers list
 });

Example I have create 6 markers on and after zoom change on the current view of map I have 3 markers So how can I get list of current onscreen markers list after zoom change?

 map.on('zoomend', function(e) {
     // want to get current onscreen markers list
 });
Share Improve this question edited Dec 26, 2019 at 12:01 adiga 35.3k9 gold badges65 silver badges87 bronze badges asked Dec 26, 2019 at 11:46 ashu0047ashu0047 211 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Here's one way of doing it..... iterate the layers on the map, check each one for being a marker and then for being within the current bounds.

function getVisibleMarkers(map) {
    var markerList = [];
    map.eachLayer(function(layer) {
        if ((layer instanceOf L.Marker) && (map.getBounds().contains(layer.getLatLng())){
            markerList.push(layer);
        };
    };
return markerList;
}

Loop on your 6 Markers.

For each Marker, check if it is within current map view port: Check if marker is in view (map) - mapbox

本文标签: javascriptIs it possible to get list of current markers on leaflet MapStack Overflow