Skip to content

Commit

Permalink
Add map as layer event parent
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface committed Jul 6, 2015
1 parent d67cbb2 commit 54c8925
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/core/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/dom/DomEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
5 changes: 5 additions & 0 deletions src/layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
15 changes: 5 additions & 10 deletions src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 54c8925

Please sign in to comment.