You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a user add's event listeners to a layer with map.on(type, layer, listener) and then removes that layer without having removed the event listeners with map.off, GL JS will fire an error when that event listener tries to trigger.
I can't think of any use cases for GL JS to not removing any active event listeners when calling removeLayer.
mapbox-gl-js version: 0.39.1
Steps to Trigger Behavior
addLayer
register an event listener on that layer
remove the layer without removing the event listeners with off
I wouldn't expect it to produce an error, but I also wouldn't expect it to deregister the event listener. Instead, I'd expect the event listener to simply remain dormant until a layer with a matching ID was added again.
The analog this API is modeled on is jQuery delegated events, which works that way. In fact, you can add a delegated event listener prior to there being any matching descendants / layers, which is sometimes handy.
andrewharvey
changed the title
removeLayer should remove any event listeners still active on the layer
event listeners on a layer should be dormant when the layer is removed, and re-activated when the same layer is re-added
Aug 15, 2017
For the background see https://gis.stackexchange.com/questions/251921/how-to-remove-events-map-onclick-from-mapbox-gl
If a user add's event listeners to a layer with
map.on(type, layer, listener)
and then removes that layer without having removed the event listeners withmap.off
, GL JS will fire an error when that event listener tries to trigger.I can't think of any use cases for GL JS to not removing any active event listeners when calling removeLayer.
mapbox-gl-js version: 0.39.1
Steps to Trigger Behavior
off
https://jsbin.com/jecixe/edit?html,console,output
Expected Behavior
Upon removeLayer, GL JS would automatically remove any event listeners.
Actual Behavior
The text was updated successfully, but these errors were encountered: