aratcliffe/Leaflet.contextmenu

Unhandled exception when layer deleted while contextmenu open

Opened this issue · 1 comments

Thanks for the great library.

I'm using the contextmenu mixin with geoJSON features. The features are frequently updated by clearing the geoJSON layer and re-adding new features. It sometimes happens that a feature is removed while its context menu is open. When this happens, when the context menu is closed, an exception is thrown in Mixin.ContextMenu.js line 72 because this._map is null. After this, the list of contextmenu items gets out of sync and future contextmenus have spurious items.

The attached patch solves this issue for me.
handle_deleted_layer.patch.txt

+1 on this patch. I am using leaflet-routing-machine with draggable markers, and I find that when I have a contextmenu associated with a marker and long-press the marker on mobile, the menu sometimes gets into a messy state and the callbacks are not fired. It looks like it's caused by the marker being dragged, which fires another event of mine that removes the marker. I tried this patch on a hunch, and it resolved my issue completely.