最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Is it possible to get list of current markers on leaflet Map? - Stack Overflow

matteradmin5PV0评论

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

Post a comment

comment list (0)

  1. No comments so far