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.
This commit is contained in:
ahocevar
2012-07-12 20:44:32 +02:00
parent f672303f0a
commit 42c4c9d869
5 changed files with 17 additions and 17 deletions

View File

@@ -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);
}
};

View File

@@ -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);

View File

@@ -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() {};

View File

@@ -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;

View File

@@ -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,