Reputation: 21
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
});
Upvotes: 1
Views: 4740
Reputation: 2618
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;
}
Upvotes: 4
Reputation: 53215
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
Upvotes: 1