Reputation: 1687
Is it possible in mapbox to have only one layer on which I'll add many markers dynamically (e.g. when the user will zoom on the map) or remove them dynamically (e.g. when the user zooms out)?
Another question related to the first one: is a marker a layer? If so, what's the difference between the class L.Marker and a layout?
Thanks for your insights.
Upvotes: 4
Views: 2971
Reputation: 49704
Create a L.mapbox.featureLayer
, which is a single layer defined as a group of markers. You can then add and remove markers programmatically like this:
var markerGroup = L.mapbox.featureLayer(geojson).addTo(map);
markerGroup.addLayer(marker);
markerGroup.removeLayer(marker);
As to whether a Marker is a Layer, the answer is sort of...A Marker is a UI Layer, as distinguished from a Raster Layer and a Vector Layer.
Upvotes: 3