0
votes

Looking for a way to add an empty overlay to a Leaflet map. I have multiple Leaflet overlays that load in their data from a realtime server. Because I am using a custom UI control and not the default Leaflet one, I have a listener that every time new markers are created, checks to see whether their associated layer is active, and if it is, adds the markers to that layer.

$rootScope.on('newMarkers',markers)->
  type = *fn to find type*
  if mapFactory.currentLayers[type]?.active
     mapFactory.addLayer(markers, type)
)

I don't think building in logic to see whether it's the first time a marker is being added to that layer makes sense, and would rather create an empty layer and add data to it after. I know you can do this with the L.geoJson type, but this layer is made entirely of plain markers. Any suggestions

1

1 Answers

1
votes

You could use L.LayerGroupfor this:

Used to group several layers and handle them as one. If you add it to the map, any layers added or removed from the group will be added/removed on the map as well. Implements ILayer interface.

Reference: http://leafletjs.com/reference.html#layergroup

Or L.FeatureGroup:

Extended layerGroup that also has mouse events (propagated from members of the group) and a shared bindPopup method. Implements ILayer interface.

Reference: http://leafletjs.com/reference.html#featuregroup