create parent event target for the map, to allow stopping event propagation

This commit is contained in:
Éric Lemoine
2012-07-05 13:55:57 +02:00
parent 410d79faa1
commit 8e36850e7f
2 changed files with 16 additions and 6 deletions
+7
View File
@@ -108,6 +108,13 @@ ol.Map = function() {
* @type {Element} * @type {Element}
*/ */
this.container_ = null; 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); goog.inherits(ol.Map, goog.events.EventTarget);
+9 -6
View File
@@ -27,9 +27,12 @@ goog.inherits(ol.control.Navigation, ol.control.Control);
ol.control.Navigation.prototype.activate = function() { ol.control.Navigation.prototype.activate = function() {
var active = goog.base(this, 'activate'); var active = goog.base(this, 'activate');
if (active) { if (active) {
var map = this.map_; // Listen to the map's parent EventTarget here. This is to
goog.events.listen(map, 'drag', this.moveMap, false, this); // give other, higher-level, controls a chance to stop the
goog.events.listen(map, 'scroll', this.zoomMap, false, this); // 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; return active;
}; };
@@ -38,9 +41,9 @@ ol.control.Navigation.prototype.activate = function() {
ol.control.Navigation.prototype.deactivate = function() { ol.control.Navigation.prototype.deactivate = function() {
var inactive = goog.base(this, 'deactivate'); var inactive = goog.base(this, 'deactivate');
if (inactive) { if (inactive) {
var map = this.map_; var target = this.map_.getParentEventTarget();
goog.events.unlisten(map, 'drag', this.moveMap, false, this); goog.events.unlisten(target, 'drag', this.moveMap, false, this);
goog.events.unlisten(map, 'scroll', this.zoomMap, false, this); goog.events.unlisten(target, 'scroll', this.zoomMap, false, this);
} }
return inactive; return inactive;
}; };