Leaflet.contextmenu
Leaflet.contextmenu copied to clipboard
Pass original 'contextmenu' event to item's callback
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...
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.
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).
So if I understand right you would like the callback arguments to include the click event that was triggered on the menu item?
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