remove the navigation control and the event target hierarchy
This commit is contained in:
@@ -115,13 +115,6 @@ ol.Map = function() {
|
|||||||
* @type {Element}
|
* @type {Element}
|
||||||
*/
|
*/
|
||||||
this.container_ = null;
|
this.container_ = null;
|
||||||
|
|
||||||
// Create an EventTarget and set it as the map's parent EventTarget. With
|
|
||||||
// this we can have two groups of listeners: "map listeners" and "map
|
|
||||||
// parent listeners". And map listeners can stop event propagation, and
|
|
||||||
// thereby prevent map parent listeners from receiving events.
|
|
||||||
this.setParentEventTarget(new goog.events.EventTarget());
|
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.Map, goog.events.EventTarget);
|
goog.inherits(ol.Map, goog.events.EventTarget);
|
||||||
|
|
||||||
@@ -149,7 +142,7 @@ ol.Map.DEFAULT_TILE_SIZE = 256;
|
|||||||
@const
|
@const
|
||||||
@type {Array.<string>}
|
@type {Array.<string>}
|
||||||
*/
|
*/
|
||||||
ol.Map.DEFAULT_CONTROLS = ["attribution", "navigation", "zoom"];
|
ol.Map.DEFAULT_CONTROLS = ["attribution", "zoom"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.Loc} Map center in map projection.
|
* @return {ol.Loc} Map center in map projection.
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
goog.provide('ol.control.Navigation');
|
|
||||||
|
|
||||||
goog.require('ol.control.Control');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.control.Control}
|
|
||||||
* @param {boolean|undefined} opt_autoActivate
|
|
||||||
*/
|
|
||||||
ol.control.Navigation = 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {number?}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
this.zoomBlocked_ = null;
|
|
||||||
|
|
||||||
};
|
|
||||||
goog.inherits(ol.control.Navigation, ol.control.Control);
|
|
||||||
|
|
||||||
/** @inheritDoc */
|
|
||||||
ol.control.Navigation.prototype.activate = function() {
|
|
||||||
var active = goog.base(this, 'activate');
|
|
||||||
if (active) {
|
|
||||||
// Listen to the map's parent EventTarget here. This is to
|
|
||||||
// give other, higher-level, controls a chance to stop the
|
|
||||||
// navigation control.
|
|
||||||
var target = this.map_.getParentEventTarget();
|
|
||||||
//goog.events.listen(target, 'drag', this.moveMap, false, this);
|
|
||||||
goog.events.listen(target, 'mousewheel', this.zoomMap, false, this);
|
|
||||||
}
|
|
||||||
return active;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @inheritDoc */
|
|
||||||
ol.control.Navigation.prototype.deactivate = function() {
|
|
||||||
var inactive = goog.base(this, 'deactivate');
|
|
||||||
if (inactive) {
|
|
||||||
var target = this.map_.getParentEventTarget();
|
|
||||||
//goog.events.unlisten(target, 'drag', this.moveMap, false, this);
|
|
||||||
goog.events.unlisten(target, 'mousewheel', this.zoomMap, false, this);
|
|
||||||
}
|
|
||||||
return inactive;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {{deltaX, deltaY}} evt
|
|
||||||
*/
|
|
||||||
ol.control.Navigation.prototype.moveMap = function(evt) {
|
|
||||||
this.map_.moveByViewportPx(evt.deltaX, evt.deltaY);
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {goog.events.MouseWheelEvent} evt
|
|
||||||
*/
|
|
||||||
ol.control.Navigation.prototype.zoomMap = function(evt) {
|
|
||||||
var me = this;
|
|
||||||
if (evt.deltaY === 0 || me.zoomBlocked_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
me.zoomBlocked_ = window.setTimeout(function() {
|
|
||||||
me.zoomBlocked_ = null;
|
|
||||||
}, 200);
|
|
||||||
|
|
||||||
var map = me.map_,
|
|
||||||
step = evt.deltaY / Math.abs(evt.deltaY);
|
|
||||||
map.setZoom(map.getZoom()-step, evt.position);
|
|
||||||
// We don't want the page to scroll.
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.control.addControl('navigation', ol.control.Navigation);
|
|
||||||
Reference in New Issue
Block a user