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

Mixin: _showAtPoint is called twice

Open Falke-Design opened this issue 5 years ago • 2 comments

If I open the MixinContextmenu with a click on a layer, the layer self call _showAtPoint and then the map also calls _showAtPoint. Because of this, the target in the contextmenu.show event is not the layer, it's the map. It can fixed with L.DomEvent.stopPropagation(data):

_showAtPoint: function(pt, data) {
    if (this._items.length) {
        var map = this._map,
            event = L.extend(data || {}, {contextmenu: this});

        this._showLocation = {
            containerPoint: pt
        };

        if (data && data.relatedTarget){
            this._showLocation.relatedTarget = data.relatedTarget;
        }

        this._setPosition(pt);

        if (!this._visible) {
            this._container.style.display = 'block';
            this._visible = true;
        }

        this._map.fire('contextmenu.show', event);
    }
    if(data){
        L.DomEvent.stopPropagation(data);
    }
};

Falke-Design avatar Jun 08 '19 09:06 Falke-Design

I can confirm, that it is triggered twice for Lines/Polygons. Markers seem to fire only once.

Using L.DomEvent.stopPropagation(data); fixes the problem at first glance, but throws the following error if you use showAt manually:

Uncaught TypeError: t is undefined

trafficonese avatar Aug 25 '20 06:08 trafficonese

@trafficonese I added

    if(data){
        L.DomEvent.stopPropagation(data);
    }

then it should work also with showAt

Falke-Design avatar Aug 25 '20 06:08 Falke-Design