aratcliffe / Leaflet.contextmenu

A context menu for Leaflet.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mixin: _showAtPoint is called twice

Falke-Design opened this issue · 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);
    }
};

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 I added

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

then it should work also with showAt