Mixin: _showAtPoint is called twice
Falke-Design opened this issue · 2 comments
Falke-Design commented
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 commented
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 commented
@trafficonese I added
if(data){
L.DomEvent.stopPropagation(data);
}
then it should work also with showAt