From 42c4c9d86968bd29cefaf224234d3893be4fca83 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 12 Jul 2012 20:44:32 +0200 Subject: [PATCH] No need to pass the element to the constructor. If MapHandler subclasses could live without a map, it would make sense to have a constructor with a target and an element. But because the target is always the map, and the handler need to know about the map for performing default behavior, we always assume the map's viewport as element. --- src/ol/Map.js | 6 +++--- src/ol/handler/Click.js | 5 ++--- src/ol/handler/Drag.js | 7 +++---- src/ol/handler/MapHandler.js | 8 +++++--- src/ol/handler/MouseWheel.js | 8 ++++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ol/Map.js b/src/ol/Map.js index 382c71890f..cadf228e04 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -528,15 +528,15 @@ ol.Map.prototype.initHandlers = function() { states = /** @type {ol.handler.states} */ ({}); if (ol.ENABLE_DRAG_HANDLER) { - handler = new ol.handler.Drag(this, this.viewport_, states); + handler = new ol.handler.Drag(this, states); this.registerDisposable(handler); } if (ol.ENABLE_MOUSEWHEEL_HANDLER) { - handler = new ol.handler.MouseWheel(this, this.viewport_, states); + handler = new ol.handler.MouseWheel(this, states); this.registerDisposable(handler); } if (ol.ENABLE_CLICK_HANDLER) { - handler = new ol.handler.Click(this, this.viewport_, states); + handler = new ol.handler.Click(this, states); this.registerDisposable(handler); } }; diff --git a/src/ol/handler/Click.js b/src/ol/handler/Click.js index 4fb3626fcb..991175ec2d 100644 --- a/src/ol/handler/Click.js +++ b/src/ol/handler/Click.js @@ -21,12 +21,11 @@ goog.require('goog.events.EventType'); * @constructor * @extends {ol.handler.MapHandler} * @param {ol.Map} map The map instance. - * @param {Element} element The element we listen for click on. * @param {ol.handler.states} states An object for the handlers to share * states. */ -ol.handler.Click = function(map, element, states) { - goog.base(this, map, element, states); +ol.handler.Click = function(map, states) { + goog.base(this, map, states); goog.events.listen(this.element_, goog.events.EventType.CLICK, this.handleClick, undefined, this); diff --git a/src/ol/handler/Drag.js b/src/ol/handler/Drag.js index be682bc4fb..ecd97a992f 100644 --- a/src/ol/handler/Drag.js +++ b/src/ol/handler/Drag.js @@ -22,17 +22,16 @@ goog.require('goog.fx.Dragger'); * @constructor * @extends {ol.handler.MapHandler} * @param {ol.Map} map The map instance. - * @param {Element} element The element we listen for click on. * @param {ol.handler.states} states An object for the handlers to share * states. */ -ol.handler.Drag = function(map, element, states) { - goog.base(this, map, element, states); +ol.handler.Drag = function(map, states) { + goog.base(this, map, states); /** * @type {goog.fx.Dragger} */ - this.dragger_ = new goog.fx.Dragger(element); + this.dragger_ = new goog.fx.Dragger(this.element_); var dragger = this.dragger_; dragger.defaultAction = function() {}; diff --git a/src/ol/handler/MapHandler.js b/src/ol/handler/MapHandler.js index 8b99594873..188fd03288 100644 --- a/src/ol/handler/MapHandler.js +++ b/src/ol/handler/MapHandler.js @@ -28,25 +28,27 @@ ol.handler.states; * @constructor * @extends {goog.Disposable} * @param {ol.Map} map The map instance. - * @param {Element} element The element we listen for browser events on. * @param {ol.handler.states} states An object for the handlers to share * states. */ -ol.handler.MapHandler = function(map, element, states) { +ol.handler.MapHandler = function(map, states) { goog.base(this); /** * @type {ol.Map} + * @protected */ this.map_ = map; /** * @type {Element} + * @protected */ - this.element_ = element; + this.element_ = map.getViewport(); /** * @type {ol.handler.states} + * @protected */ this.states_ = states; diff --git a/src/ol/handler/MouseWheel.js b/src/ol/handler/MouseWheel.js index 53dca0672a..48b483294c 100644 --- a/src/ol/handler/MouseWheel.js +++ b/src/ol/handler/MouseWheel.js @@ -13,6 +13,7 @@ goog.require('ol.handler.MapHandler'); goog.require('ol.events.MapEvent'); goog.require('ol.events.MapEventType'); +goog.require('goog.asserts'); goog.require('goog.events'); goog.require('goog.style'); goog.require('goog.events.MouseWheelHandler'); @@ -23,14 +24,13 @@ goog.require('goog.events.MouseWheelHandler.EventType'); * @constructor * @extends {ol.handler.MapHandler} * @param {ol.Map} map The map instance. - * @param {Element} element The element we listen for click on. * @param {ol.handler.states} states An object for the handlers to share * states. */ -ol.handler.MouseWheel = function(map, element, states) { - goog.base(this, map, element, states); +ol.handler.MouseWheel = function(map, states) { + goog.base(this, map, states); - var handler = new goog.events.MouseWheelHandler(element); + var handler = new goog.events.MouseWheelHandler(this.element_); this.registerDisposable(handler); goog.events.listen(handler,