Error when calling `onRemove` if the creation failed
Describe the bug
From @corrigancd in #140:
When a layer fails to load, even if the error is handled (#146), in our app there is a function which calls
leafletMap.removeLayerto clear layers before re-adding them. This triggers theonRemovefunction invectorTileLayerandmap.removeLayer(this._mapboxGL)was called. The the problem was thatthis._mapboxGLwas never initialized because the_createLayerfunction was exited early. So a check was added to make use thatthis.mapboxGLexists before calling remove.
Reproduction
tbd ... I'll try to follow up with this, or @corrigancd are you able to provide reproduction steps?
Logs
tbd
System Info
coming soon
Additional Information
Proposed solution from @corrigancd in #140: https://github.com/Esri/esri-leaflet-vector/pull/140/files#diff-d87a7a0181c4fb7f5a10b32e3494597f82c320b55306aa848df45d586513b30eR144-R146
I´m not @corrigancd but I think blocking the VectorTileServer?f=json call from the DevTools is enough to replicate.
Have noticed this
It's enough to give a working vector tile url a tweak to get the error i.e. use this URL with the _BreaksRemove added in -->
https://vectortileservices3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_Mountains_Parcels_VTL_BreaksRemove/VectorTileServer,
make a vector tile layer with that URL add it to the map and then attempt to remove it
I arrived at pretty much doing @corrigancd 's fix externally but it would be great if his push could be merged
works but nasty -->
const oldOnRemove = vlayer.onRemove;
vlayer.onRemove = function (this: any, map: L.Map) { // typescript this fix
if (this._maplibreGL) {
return oldOnRemove.bind(this)(map);
}
return null;
} as any;