Leaflet.contextmenu icon indicating copy to clipboard operation
Leaflet.contextmenu copied to clipboard

Pass original 'contextmenu' event to item's callback

Open aparshin opened this issue 8 years ago • 4 comments

I use context menu mixin on my own layer (it extends L.TileLayer, but it's not important). My layer fires contextmenu event, which includes some additional information about click location.

I want to get access to this information in callback of context menu item. Maybe, it can be original contextmenu event in callback attributes or something like that...

What do you thing about this improvement? I can make PR if you agree with it in general...

aparshin avatar Mar 03 '16 13:03 aparshin

I've changed the contextmenu.show event to extend the original contextmenu MouseEvent if the context menu was shown in response to a contextmenu event on the map or layer. Let me know if that solves your problem.

aratcliffe avatar Jun 22 '16 12:06 aratcliffe

Unfortunately, I don't use contextmenu events. Instead, I add L.Mixin.ContextMenu to my layer class and set corresponding options during layer instantiation.

So, the problem is that I can't get original contextmenu event from menu item callback (https://github.com/aratcliffe/Leaflet.contextmenu#menu-item-options).

aparshin avatar Jun 30 '16 10:06 aparshin

So if I understand right you would like the callback arguments to include the click event that was triggered on the menu item?

aratcliffe avatar Jul 01 '16 01:07 aratcliffe

No, not click event on menu item, but contextmenu event on the layer.

I use L.Mixin.ContextMenu to add context menu to several layers on my map. These layers are custom layers implemented by myself, not L.Marker or L.path instances. And these layers trigger contextmenu event (which is used in L.Mixin.ContextMenu: https://github.com/aratcliffe/Leaflet.contextmenu/blob/master/src/Mixin.ContextMenu.js#L19). The problem is that I add additional information in that contextmenu event of my layers and want to get assess to that information in context menu item callback.

So, is it possible to add original contextmenu event to callback arguments? For example as additional property of the first argument (in addition to latlng, layerPoint and containerPoint properties).

I've implemented this variant in my fork (can create PR if you think it is appropriate solution): https://github.com/ScanEx/Leaflet.contextmenu/commit/32840d17b07a4057a06d3fbe2941cab60fc1f7b8

aparshin avatar Jul 01 '16 13:07 aparshin