aratcliffe/Leaflet.contextmenu

Object contextmenu unbind and rebind

Opened this issue · 3 comments

When binding a contextmenu to a object-layer and unbinding it when the object-layer is removed from the map or a layer in the map(my way of hiding it) and then calling bindContextMenu again when the object-layer is readded. The relatedTarget will be undefined, this is because the map contextmenu triggers on the contextmenu event after the object-layer reacts to the same event. Now when opening the context menu first it will show the contextmenu for the object and setts the relatedObject to the object but the map contextmenu is also triggered and tets the relatedTarget to undefined but the contextmenu is visible so it will not open a new one. Now the contextmenu for the object is open and when clicking any option the relatedTarget is undefined.
My quickfix for this is:
_showAtPoint: function (pt, data) {
if (this._visible)//HACK HACK
return;

This is a bit of a problem for me and I will be very gratefull if you could solve this.
Keep up the good work ane thanks for a great plugin!

Hi, what is the "object-layer" type you refer to? A Path type or something else?

A marker, a line etc...
In my case the result adding GeoJSON data to a GeoJSON layer(featuregroup)

This is probably late, but it seems that you can avoid the trigger for the map's contextmenu by setting bubblingMouseEvents=false on your path/marker options.