esri-leaflet-vector icon indicating copy to clipboard operation
esri-leaflet-vector copied to clipboard

Error when calling `onRemove` if the creation failed

Open gavinr opened this issue 3 years ago • 2 comments

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.removeLayer to clear layers before re-adding them. This triggers the onRemove function in vectorTileLayer and map.removeLayer(this._mapboxGL) was called. The the problem was that this._mapboxGL was never initialized because the _createLayer function was exited early. So a check was added to make use that this.mapboxGL exists 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

gavinr avatar Sep 02 '22 18:09 gavinr

I´m not @corrigancd but I think blocking the VectorTileServer?f=json call from the DevTools is enough to replicate.

xantao avatar Jan 23 '25 08:01 xantao

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;

martingraham avatar Mar 28 '25 10:03 martingraham