From 578f74eb861d6c74cd1fe0b2cef197bb7e29d25e Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 29 Jun 2012 09:44:52 +0200 Subject: [PATCH] Less magic. Each control is responsible for its handlers. And all controls are rendered into an overlay, not any more depending on assumptions about link click handling. --- src/ol/Map.js | 8 -------- src/ol/control/Attribution.js | 24 ++++++++++++++++++++++-- src/ol/control/Zoom.js | 8 ++++---- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/ol/Map.js b/src/ol/Map.js index 8ff0a7da0c..180e5a11c2 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -489,14 +489,6 @@ ol.Map.prototype.createRenderer = function() { 'class': staticCls, 'style': 'width:100%;height:100%;top:0;left:0;position:absolute' }); - // Prevent click events on links in the static overlay from getting - // through to listeners. This is not registered as priority listener, - // so priority listeners can still get the click event. - this.events_.register('click', function(evt) { - var node = evt.target; - return !(node.nodeName === 'A' && - goog.dom.getAncestorByClass(node, staticCls)); - }); } if (!goog.isNull(viewport)) { goog.dom.append(viewport, this.mapOverlay_, this.staticOverlay_); diff --git a/src/ol/control/Attribution.js b/src/ol/control/Attribution.js index 3c4999fb25..0c03182366 100644 --- a/src/ol/control/Attribution.js +++ b/src/ol/control/Attribution.js @@ -31,18 +31,38 @@ ol.control.Attribution = function(opt_autoActivate) { }; goog.inherits(ol.control.Attribution, ol.control.Control); +/** + * @const {string} + */ +ol.control.Attribution.prototype.CLS = 'ol-control-attribution'; + /** * @param {ol.Map} map */ ol.control.Attribution.prototype.setMap = function(map) { - this.container_ = goog.dom.createDom('div', 'ol-control-attribution'); var staticOverlay = map.getStaticOverlay(); - if (!goog.isNull(this.container_) && !goog.isNull(staticOverlay)) { + if (goog.isNull(this.container_)) { + this.container_ = goog.dom.createDom('div', this.CLS); + // This is not registered as priority listener, so priority listeners + // can still get the click event. + map.getEvents().register('click', this.stopLinkClick, this); + } + if (!goog.isNull(staticOverlay)) { goog.dom.append(staticOverlay, this.container_); } goog.base(this, 'setMap', map); }; +/** + * Prevent clicks on links in the attribution from getting through to + * listeners. + */ +ol.control.Attribution.prototype.stopLinkClick = function(evt) { + var node = evt.target; + return node.nodeName !== 'A' || + !goog.dom.getAncestorByClass(node, this.CLS); +}; + /** @inheritDoc */ ol.control.Attribution.prototype.activate = function() { var active = goog.base(this, 'activate'); diff --git a/src/ol/control/Zoom.js b/src/ol/control/Zoom.js index 6aaf378f8f..07010a492a 100644 --- a/src/ol/control/Zoom.js +++ b/src/ol/control/Zoom.js @@ -50,9 +50,9 @@ ol.control.Zoom.prototype.setMap = function(map) { ); goog.dom.append(container, inButton, outButton); - var viewport = /** @type {Node} */ map.getViewport(); - if (goog.isDefAndNotNull(viewport)) { - goog.dom.append(viewport, container); + var overlay = map.getStaticOverlay(); + if (goog.isDefAndNotNull(overlay)) { + goog.dom.append(overlay, container); } }; @@ -106,7 +106,7 @@ ol.control.Zoom.prototype.handle = function(evt) { ol.control.Zoom.prototype.destroy = function() { goog.dom.removeNode(goog.dom.getElementByClass( ol.control.Zoom.RES.CLS, - /** @type {Element} */ (this.map_.getViewport()) + /** @type {Element} */ (this.map_.getStaticOverlay()) )); goog.base(this, 'destroy'); };