Add map as layer event parent
This commit is contained in:
parent
d67cbb24c1
commit
54c8925818
@ -211,6 +211,7 @@ L.Evented = L.Class.extend({
|
|||||||
|
|
||||||
_propagateEvent: function (e) {
|
_propagateEvent: function (e) {
|
||||||
for (var id in this._eventParents) {
|
for (var id in this._eventParents) {
|
||||||
|
if (e._stopped) { break; }
|
||||||
this._eventParents[id].fire(e.type, L.extend({layer: e.target}, e), true);
|
this._eventParents[id].fire(e.type, L.extend({layer: e.target}, e), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,14 +128,13 @@ L.DomEvent = {
|
|||||||
|
|
||||||
stopPropagation: function (e) {
|
stopPropagation: function (e) {
|
||||||
|
|
||||||
L.DomEvent._skipped(e);
|
|
||||||
if (e.stopPropagation) {
|
if (e.stopPropagation) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
} else {
|
} else {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
// In case of Leaflet event.
|
e._stopped = true; // In case of Leaflet event.
|
||||||
L.DomEvent._fakeStop(e);
|
|
||||||
}
|
}
|
||||||
|
L.DomEvent._skipped(e);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
@ -67,6 +67,9 @@ L.Layer = L.Evented.extend({
|
|||||||
L.Map.include({
|
L.Map.include({
|
||||||
addLayer: function (layer) {
|
addLayer: function (layer) {
|
||||||
var id = L.stamp(layer);
|
var id = L.stamp(layer);
|
||||||
|
|
||||||
|
layer.addEventParent(this);
|
||||||
|
|
||||||
if (this._layers[id]) { return layer; }
|
if (this._layers[id]) { return layer; }
|
||||||
this._layers[id] = layer;
|
this._layers[id] = layer;
|
||||||
|
|
||||||
@ -84,6 +87,8 @@ L.Map.include({
|
|||||||
removeLayer: function (layer) {
|
removeLayer: function (layer) {
|
||||||
var id = L.stamp(layer);
|
var id = L.stamp(layer);
|
||||||
|
|
||||||
|
layer.removeEventParent(this);
|
||||||
|
|
||||||
if (!this._layers[id]) { return this; }
|
if (!this._layers[id]) { return this; }
|
||||||
|
|
||||||
if (this._loaded) {
|
if (this._loaded) {
|
||||||
|
@ -660,13 +660,7 @@ L.Map = L.Evented.extend({
|
|||||||
L.DomUtil.preventOutline(e.target || e.srcElement);
|
L.DomUtil.preventOutline(e.target || e.srcElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target && target !== this) {
|
this._fireDOMEvent(target || this, e, type);
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_fireDOMEvent: function (target, 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; }
|
if (e.type === 'click' && !e._simulated && this._draggableMoved(target)) { return; }
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
originalEvent: e
|
originalEvent: e
|
||||||
};
|
},
|
||||||
|
propagate = (type !== 'mouseover' && type !== 'mouseout');
|
||||||
if (e.type !== 'keypress') {
|
if (e.type !== 'keypress') {
|
||||||
data.containerPoint = target instanceof L.Marker ?
|
data.containerPoint = target instanceof L.Marker ?
|
||||||
this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e);
|
this.latLngToContainerPoint(target.getLatLng()) : this.mouseEventToContainerPoint(e);
|
||||||
data.layerPoint = this.containerPointToLayerPoint(data.containerPoint);
|
data.layerPoint = this.containerPointToLayerPoint(data.containerPoint);
|
||||||
data.latlng = this.layerPointToLatLng(data.layerPoint);
|
data.latlng = this.layerPointToLatLng(data.layerPoint);
|
||||||
}
|
}
|
||||||
target.fire(type, data, true);
|
target.fire(type, data, propagate);
|
||||||
},
|
},
|
||||||
|
|
||||||
_draggableMoved: function (obj) {
|
_draggableMoved: function (obj) {
|
||||||
|
Loading…
Reference in New Issue
Block a user