Revert "Allow for using a different set of default behaviors."
This reverts commit 3cc069186c.
This commit is contained in:
@@ -2,7 +2,6 @@ goog.provide("ol");
|
|||||||
|
|
||||||
goog.require('ol.base');
|
goog.require('ol.base');
|
||||||
goog.require('ol.bounds');
|
goog.require('ol.bounds');
|
||||||
goog.require('ol.control.Navigation');
|
|
||||||
goog.require('ol.control.Attribution');
|
goog.require('ol.control.Attribution');
|
||||||
goog.require('ol.control.Zoom');
|
goog.require('ol.control.Zoom');
|
||||||
goog.require('ol.handler.Drag');
|
goog.require('ol.handler.Drag');
|
||||||
|
|||||||
+2
-22
@@ -88,12 +88,6 @@ ol.Map = function() {
|
|||||||
* @type {Array}
|
* @type {Array}
|
||||||
*/
|
*/
|
||||||
this.controls_ = null;
|
this.controls_ = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ol.control.DefaultControl}
|
|
||||||
*/
|
|
||||||
this.defaultControl_ = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -163,7 +157,7 @@ ol.Map.DEFAULT_TILE_SIZE = 256;
|
|||||||
@const
|
@const
|
||||||
@type {Array.<string>}
|
@type {Array.<string>}
|
||||||
*/
|
*/
|
||||||
ol.Map.CONTROLS = ["navigation", "attribution", "zoom"];
|
ol.Map.DEFAULT_CONTROLS = ["attribution", "zoom"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.Loc} Map center in map projection.
|
* @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.<ol.control.Control>|undefined} opt_controls
|
* @param {Array.<ol.control.Control>|undefined} opt_controls
|
||||||
*/
|
*/
|
||||||
@@ -503,7 +483,7 @@ ol.Map.prototype.setContainer = function(container) {
|
|||||||
this.createRenderer();
|
this.createRenderer();
|
||||||
//TODO Controls could be set earlier, but we need to deal with content that
|
//TODO Controls could be set earlier, but we need to deal with content that
|
||||||
// controls place on overlays.
|
// controls place on overlays.
|
||||||
this.setControls(ol.Map.CONTROLS);
|
this.setControls(ol.Map.DEFAULT_CONTROLS);
|
||||||
// conditionally render
|
// conditionally render
|
||||||
this.conditionallyRender();
|
this.conditionallyRender();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ ol.control.Control = function(opt_autoActivate) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {boolean} active
|
* @type {boolean} active
|
||||||
* @protected
|
* @private
|
||||||
*/
|
*/
|
||||||
this.active_ = false;
|
this.active_ = false;
|
||||||
|
|
||||||
@@ -42,7 +42,6 @@ ol.control.Control = function(opt_autoActivate) {
|
|||||||
*/
|
*/
|
||||||
this.autoActivate_ =
|
this.autoActivate_ =
|
||||||
goog.isDef(opt_autoActivate) ? opt_autoActivate : false;
|
goog.isDef(opt_autoActivate) ? opt_autoActivate : false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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) {};
|
|
||||||
@@ -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);
|
|
||||||
+12
-6
@@ -95,19 +95,25 @@ ol.handler.Drag.prototype.handleDragStart = function(e) {
|
|||||||
ol.handler.Drag.prototype.handleDrag = function(e) {
|
ol.handler.Drag.prototype.handleDrag = function(e) {
|
||||||
this.states_.dragged = true;
|
this.states_.dragged = true;
|
||||||
var newE = new ol.events.MapEvent(ol.events.MapEventType.DRAG, e);
|
var newE = new ol.events.MapEvent(ol.events.MapEventType.DRAG, e);
|
||||||
newE.deltaX = e.clientX - this.prevX_;
|
newE.delementaX = e.clientX - this.prevX_;
|
||||||
newE.deltaY = e.clientY - this.prevY_;
|
newE.delementaY = e.clientY - this.prevY_;
|
||||||
this.prevX_ = e.clientX;
|
this.prevX_ = e.clientX;
|
||||||
this.prevY_ = e.clientY;
|
this.prevY_ = e.clientY;
|
||||||
var rt = goog.events.dispatchEvent(this.map_, newE);
|
var rt = goog.events.dispatchEvent(this.map_, newE);
|
||||||
if (rt) {
|
if (rt) {
|
||||||
var defaultControl = this.map_.getDefaultControl();
|
this.defaultDrag(newE);
|
||||||
if (defaultControl) {
|
|
||||||
defaultControl.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
|
* @param {goog.fx.DragEvent} e
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* Type definitions and base class for map event handlers that share states,
|
* 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),
|
* 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
|
* 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');
|
goog.provide('ol.handler.states');
|
||||||
|
|||||||
@@ -47,9 +47,28 @@ ol.handler.MouseWheel.prototype.handleMouseWheel = function(e) {
|
|||||||
var newE = new ol.events.MapEvent(ol.events.MapEventType.MOUSEWHEEL, e);
|
var newE = new ol.events.MapEvent(ol.events.MapEventType.MOUSEWHEEL, e);
|
||||||
var rt = goog.events.dispatchEvent(this.map_, newE);
|
var rt = goog.events.dispatchEvent(this.map_, newE);
|
||||||
if (rt) {
|
if (rt) {
|
||||||
var defaultControl = this.map_.getDefaultControl();
|
this.defaultMouseWheel(e);
|
||||||
if (defaultControl) {
|
|
||||||
defaultControl.defaultMouseWheel(newE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user