diff --git a/src/core/Events.js b/src/core/Events.js index 6702d2ae..9452124e 100644 --- a/src/core/Events.js +++ b/src/core/Events.js @@ -211,6 +211,7 @@ L.Evented = L.Class.extend({ _propagateEvent: function (e) { for (var id in this._eventParents) { + if (e._stopped) { break; } this._eventParents[id].fire(e.type, L.extend({layer: e.target}, e), true); } } diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 0e0d049a..4f078437 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -128,14 +128,13 @@ L.DomEvent = { stopPropagation: function (e) { - L.DomEvent._skipped(e); if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; - // In case of Leaflet event. - L.DomEvent._fakeStop(e); + e._stopped = true; // In case of Leaflet event. } + L.DomEvent._skipped(e); return this; }, diff --git a/src/layer/Layer.js b/src/layer/Layer.js index b34dcc96..352f6c40 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -67,6 +67,9 @@ L.Layer = L.Evented.extend({ L.Map.include({ addLayer: function (layer) { var id = L.stamp(layer); + + layer.addEventParent(this); + if (this._layers[id]) { return layer; } this._layers[id] = layer; @@ -84,6 +87,8 @@ L.Map.include({ removeLayer: function (layer) { var id = L.stamp(layer); + layer.removeEventParent(this); + if (!this._layers[id]) { return this; } if (this._loaded) { diff --git a/src/map/Map.js b/src/map/Map.js index 9318e7f7..9b9373a2 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -660,13 +660,7 @@ L.Map = L.Evented.extend({ L.DomUtil.preventOutline(e.target || e.srcElement); } - if (target && target !== this) { - this._fireDOMEvent(target, e, type); - if (type === 'mouseover' || type === 'mouseout') { return; } - } - if (!L.DomEvent._skipped(e)) { // In case the Leaflet event has been stopped on some target listener. - this._fireDOMEvent(this, e, type); - } + this._fireDOMEvent(target || this, e, type); }, _fireDOMEvent: function (target, e, type) { @@ -680,15 +674,16 @@ L.Map = L.Evented.extend({ if (e.type === 'click' && !e._simulated && this._draggableMoved(target)) { return; } var data = { - originalEvent: e - }; + originalEvent: e + }, + propagate = (type !== 'mouseover' && type !== 'mouseout'); if (e.type !== 'keypress') { data.containerPoint = target instanceof L.Marker ? this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e); data.layerPoint = this.containerPointToLayerPoint(data.containerPoint); data.latlng = this.layerPointToLatLng(data.layerPoint); } - target.fire(type, data, true); + target.fire(type, data, propagate); }, _draggableMoved: function (obj) {