Add map as layer event parent

This commit is contained in:
Yohan Boniface 2015-06-01 22:32:50 +02:00
parent d67cbb24c1
commit 54c8925818
4 changed files with 13 additions and 13 deletions

View File

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

View File

@ -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;
},

View File

@ -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) {

View File

@ -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) {