Gabriel S
Gabriel S

Reputation: 83

How to add a event handler to catch leaflet contextmenu events?

I create a context menu like this:

var map = L.map('map', {
    minZoom: 2,
    maxZoom: 15,
    gestureHandling: ControlGestual,
    contextmenu: true,
        contextmenuWidth: 300,
    contextmenuItems: MenuContextual
});

but I also need some code to be executed when the context menu is closed(hidden). I see in the documentation that there is a contextmenu.hide event, but I don't know how to create a handler for this event.

I would appreciate your help. Many thanks in advance.

Upvotes: 0

Views: 658

Answers (1)

Falke Design
Falke Design

Reputation: 11338

The event is fired on the map, so add:

map.on('contextmenu.hide', (e)=>{
    console.log(e)
});

Upvotes: 1

Related Questions