From 2b9df6442bd0edd714356d3acebab2971f5c41c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 13 Jul 2012 15:38:06 +0200 Subject: [PATCH] Revert "Allow for using a different set of default behaviors." This reverts commit 3cc069186c7b5aeb73103c83c94ba511143d34c7. --- src/ol.js | 1 - src/ol/Map.js | 24 ++------------ src/ol/control/Control.js | 3 +- src/ol/control/DefaultControl.js | 50 ----------------------------- src/ol/control/Navigation.js | 54 -------------------------------- src/ol/handler/Drag.js | 18 +++++++---- src/ol/handler/MapHandler.js | 2 +- src/ol/handler/MouseWheel.js | 29 ++++++++++++++--- 8 files changed, 40 insertions(+), 141 deletions(-) delete mode 100644 src/ol/control/DefaultControl.js delete mode 100644 src/ol/control/Navigation.js diff --git a/src/ol.js b/src/ol.js index 2ff8dfea9a..8c936f0329 100644 --- a/src/ol.js +++ b/src/ol.js @@ -2,7 +2,6 @@ goog.provide("ol"); goog.require('ol.base'); goog.require('ol.bounds'); -goog.require('ol.control.Navigation'); goog.require('ol.control.Attribution'); goog.require('ol.control.Zoom'); goog.require('ol.handler.Drag'); diff --git a/src/ol/Map.js b/src/ol/Map.js index b4dd0d3c8b..cadf228e04 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -88,12 +88,6 @@ ol.Map = function() { * @type {Array} */ this.controls_ = null; - - /** - * @private - * @type {ol.control.DefaultControl} - */ - this.defaultControl_ = null; /** * @private @@ -163,7 +157,7 @@ ol.Map.DEFAULT_TILE_SIZE = 256; @const @type {Array.} */ -ol.Map.CONTROLS = ["navigation", "attribution", "zoom"]; +ol.Map.DEFAULT_CONTROLS = ["attribution", "zoom"]; /** * @return {ol.Loc} Map center in map projection. @@ -449,20 +443,6 @@ ol.Map.prototype.addLayers = function(layers) { }; -/** - * @returns {ol.control.DefaultControl} - */ -ol.Map.prototype.getDefaultControl = function() { - return this.defaultControl_; -}; - -/** - * @param {ol.control.DefaultControl} control - */ -ol.Map.prototype.setDefaultControl = function(control) { - this.defaultControl_ = control; -}; - /** * @param {Array.|undefined} opt_controls */ @@ -503,7 +483,7 @@ ol.Map.prototype.setContainer = function(container) { this.createRenderer(); //TODO Controls could be set earlier, but we need to deal with content that // controls place on overlays. - this.setControls(ol.Map.CONTROLS); + this.setControls(ol.Map.DEFAULT_CONTROLS); // conditionally render this.conditionallyRender(); }; diff --git a/src/ol/control/Control.js b/src/ol/control/Control.js index b6d1264ac9..eaa1c693d6 100644 --- a/src/ol/control/Control.js +++ b/src/ol/control/Control.js @@ -31,7 +31,7 @@ ol.control.Control = function(opt_autoActivate) { /** * @type {boolean} active - * @protected + * @private */ this.active_ = false; @@ -42,7 +42,6 @@ ol.control.Control = function(opt_autoActivate) { */ this.autoActivate_ = goog.isDef(opt_autoActivate) ? opt_autoActivate : false; - }; /** diff --git a/src/ol/control/DefaultControl.js b/src/ol/control/DefaultControl.js deleted file mode 100644 index 683171017d..0000000000 --- a/src/ol/control/DefaultControl.js +++ /dev/null @@ -1,50 +0,0 @@ -goog.provide('ol.control.DefaultControl'); - -goog.require('ol.control.Control'); - -/** - * @constructor - * @extends {ol.control.Control} - * @param {boolean|undefined} opt_autoActivate - */ -ol.control.DefaultControl = function(opt_autoActivate) { - goog.base(this, opt_autoActivate); - - /** - * Activate this control when it is added to a map. Default is true. - * - * @type {boolean} autoActivate - */ - this.autoActivate_ = - goog.isDef(opt_autoActivate) ? opt_autoActivate : true; - -}; -goog.inherits(ol.control.DefaultControl, ol.control.Control); - -/** @inheritDoc */ -ol.control.DefaultControl.prototype.activate = function() { - var active = goog.base(this, 'activate'); - if (active) { - this.map_.setDefaultControl(this); - } - return active; -}; - -/** @inheritDoc */ -ol.control.DefaultControl.prototype.deactivate = function() { - var inactive = goog.base(this, 'deactivate'); - if (inactive) { - this.map_.setDefaultControl(null); - } - return inactive; -}; - -/** - * @param {ol.events.MapEvent} e - */ -ol.control.DefaultControl.prototype.defaultDrag = function(e) {}; - -/** - * @param {ol.events.MapEvent} e - */ -ol.control.DefaultControl.prototype.defaultMouseWheel = function(e) {}; diff --git a/src/ol/control/Navigation.js b/src/ol/control/Navigation.js deleted file mode 100644 index 9255b412aa..0000000000 --- a/src/ol/control/Navigation.js +++ /dev/null @@ -1,54 +0,0 @@ -goog.provide('ol.control.Navigation'); - -goog.require('ol.control.DefaultControl'); -goog.require('ol.Map'); - -/** - * @constructor - * @extends {ol.control.DefaultControl} - * @param {boolean|undefined} opt_autoActivate - */ -ol.control.Navigation = function(opt_autoActivate) { - goog.base(this, opt_autoActivate); -}; -goog.inherits(ol.control.Navigation, ol.control.DefaultControl); - - -/** - * @inheritDoc - */ -ol.control.Navigation.prototype.defaultDrag = function(e) { - if (ol.ENABLE_DRAG_HANDLER) { - var deltaX = /** @type {number} */ e.deltaX; - var deltaY = /** @type {number} */ e.deltaY; - this.map_.moveByViewportPx(deltaX, deltaY); - } -}; - -/** - * @inheritDoc - */ -ol.control.Navigation.prototype.defaultMouseWheel = function(e) { - if (ol.ENABLE_MOUSEWHEEL_HANDLER) { - var me = this, - originalE = e.originalEvent; - if (originalE.deltaY === 0 || me.zoomBlocked_) { - return; - } - me.zoomBlocked_ = window.setTimeout(function() { - me.zoomBlocked_ = null; - }, 200); - - var map = me.map_, - step = originalE.deltaY / Math.abs(originalE.deltaY), - position = goog.style.getRelativePosition(originalE, - map.getViewport()); - map.setZoom(map.getZoom() - step, position); - - // We don't want the page to scroll. - // (MouseWheelEvent is a originalEvent) - e.preventDefault(); - } -}; - -ol.control.addControl('navigation', ol.control.Navigation); diff --git a/src/ol/handler/Drag.js b/src/ol/handler/Drag.js index 0b04294823..ecd97a992f 100644 --- a/src/ol/handler/Drag.js +++ b/src/ol/handler/Drag.js @@ -95,19 +95,25 @@ ol.handler.Drag.prototype.handleDragStart = function(e) { ol.handler.Drag.prototype.handleDrag = function(e) { this.states_.dragged = true; var newE = new ol.events.MapEvent(ol.events.MapEventType.DRAG, e); - newE.deltaX = e.clientX - this.prevX_; - newE.deltaY = e.clientY - this.prevY_; + newE.delementaX = e.clientX - this.prevX_; + newE.delementaY = e.clientY - this.prevY_; this.prevX_ = e.clientX; this.prevY_ = e.clientY; var rt = goog.events.dispatchEvent(this.map_, newE); if (rt) { - var defaultControl = this.map_.getDefaultControl(); - if (defaultControl) { - defaultControl.defaultDrag(newE); - } + this.defaultDrag(newE); } }; +/** + * @param {ol.events.MapEvent} e + */ +ol.handler.Drag.prototype.defaultDrag = function(e) { + var delementaX = /** @type {number} */ e.delementaX; + var delementaY = /** @type {number} */ e.delementaY; + this.map_.moveByViewportPx(delementaX, delementaY); +}; + /** * @param {goog.fx.DragEvent} e */ diff --git a/src/ol/handler/MapHandler.js b/src/ol/handler/MapHandler.js index 243380cc5f..188fd03288 100644 --- a/src/ol/handler/MapHandler.js +++ b/src/ol/handler/MapHandler.js @@ -4,7 +4,7 @@ * Type definitions and base class for map event handlers that share states, * listen for events on a map related dom element (usually the map's viewport), * dispatch events to an ol.Map instance, and optionally perform default - * actions on the map's default control. + * actions on an ol.Map instance. */ goog.provide('ol.handler.states'); diff --git a/src/ol/handler/MouseWheel.js b/src/ol/handler/MouseWheel.js index 042fd7423e..48b483294c 100644 --- a/src/ol/handler/MouseWheel.js +++ b/src/ol/handler/MouseWheel.js @@ -47,9 +47,28 @@ ol.handler.MouseWheel.prototype.handleMouseWheel = function(e) { var newE = new ol.events.MapEvent(ol.events.MapEventType.MOUSEWHEEL, e); var rt = goog.events.dispatchEvent(this.map_, newE); if (rt) { - var defaultControl = this.map_.getDefaultControl(); - if (defaultControl) { - defaultControl.defaultMouseWheel(newE); - } + this.defaultMouseWheel(e); } -}; \ No newline at end of file +}; + +/** + * @param {goog.events.MouseWheelEvent} e + */ +ol.handler.MouseWheel.prototype.defaultMouseWheel = function(e) { + var me = this; + if (e.deltaY === 0 || me.zoomBlocked_) { + return; + } + me.zoomBlocked_ = window.setTimeout(function() { + me.zoomBlocked_ = null; + }, 200); + + var map = me.map_, + step = e.deltaY / Math.abs(e.deltaY); + map.setZoom(map.getZoom() - step, + goog.style.getRelativePosition(e, this.element_)); + + // We don't want the page to scroll. + // (MouseWheelEvent is a BrowserEvent) + e.preventDefault(); +};