Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixin: _showAtPoint is called twice #122

Open
Falke-Design opened this issue Jun 8, 2019 · 2 comments
Open

Mixin: _showAtPoint is called twice #122

Falke-Design opened this issue Jun 8, 2019 · 2 comments

Comments

@Falke-Design
Copy link

Falke-Design commented Jun 8, 2019

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);
    }
};
@trafficonese
Copy link

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

@Falke-Design
Copy link
Author

Falke-Design commented Aug 25, 2020

@trafficonese I added

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

then it should work also with showAt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants