diff --git a/src/ol/Map.js b/src/ol/Map.js index d4326e4ec7..a90674e76f 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -108,6 +108,13 @@ ol.Map = function() { * @type {Element} */ this.container_ = null; + + // Create an EventTarget and set it as the map's parent EventTarget. With + // this we can have two groups of listeners: "map listeners" and "map + // parent listeners". And map listeners can stop event propagation, and + // thereby prevent map parent listeners from receiving events. + this.setParentEventTarget(new goog.events.EventTarget()); + }; goog.inherits(ol.Map, goog.events.EventTarget); diff --git a/src/ol/control/Navigation.js b/src/ol/control/Navigation.js index c1b2ff05d8..2a3eb0b070 100644 --- a/src/ol/control/Navigation.js +++ b/src/ol/control/Navigation.js @@ -27,9 +27,12 @@ goog.inherits(ol.control.Navigation, ol.control.Control); ol.control.Navigation.prototype.activate = function() { var active = goog.base(this, 'activate'); if (active) { - var map = this.map_; - goog.events.listen(map, 'drag', this.moveMap, false, this); - goog.events.listen(map, 'scroll', this.zoomMap, false, this); + // Listen to the map's parent EventTarget here. This is to + // give other, higher-level, controls a chance to stop the + // navigation control. + var target = this.map_.getParentEventTarget(); + goog.events.listen(target, 'drag', this.moveMap, false, this); + goog.events.listen(target, 'scroll', this.zoomMap, false, this); } return active; }; @@ -38,9 +41,9 @@ ol.control.Navigation.prototype.activate = function() { ol.control.Navigation.prototype.deactivate = function() { var inactive = goog.base(this, 'deactivate'); if (inactive) { - var map = this.map_; - goog.events.unlisten(map, 'drag', this.moveMap, false, this); - goog.events.unlisten(map, 'scroll', this.zoomMap, false, this); + var target = this.map_.getParentEventTarget(); + goog.events.unlisten(target, 'drag', this.moveMap, false, this); + goog.events.unlisten(target, 'scroll', this.zoomMap, false, this); } return inactive; };