It would be nice to be able to check for a layer presence or remove it without having to keep an explicit reference to it. To that extent I would like to use ad id for the layer that I can compute myself from my data. Is this feasible with leaflet? If no, do you have any clean workaround?
For example with a LayerGroup, the idea is to have a
setId(<String> id) function that would allow leveraging the native
removeLayer( <String> id ) and
getLayer( <String> id ) methods to work on the LayerGroup content by user defined identifiers. Example below:
marker = L.circleMarker(...); marker.setId('my_marker_id'); lg = L.layerGroup(...); lg.addLayer(marker); ... lg.removeLayer('my_marker_id');