D
D
dom1n1k2017-03-20 01:39:08
leaflet
dom1n1k, 2017-03-20 01:39:08

How to catch events in Leaflet when a layer is added or removed from the map?

As if everything is simple, there are events layeraddand layerremove:
leafletjs.com/reference-1.0.3.html#map-event
But these are map events and they are hung on the map. That is, the card knows when something was added or removed.
And I need in terms of layer . Here I have a layer:
var layer = L.tilelayer(...);
And my code does not know where the layer will be added (maybe it will happen in another module). And he doesn’t know in advance which cards will be on the page, how many of them there will be, and so on.
How can you catch the moments of adding / deleting and understand where / from where?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2017-03-20
@freeExec

Not a big connoisseur of JS, but in theory create your own event handler for layer. And in the processing of layeradd, call your handler on the added layer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question