Allow for using a different set of default behaviors.

The default behavior of dragging and wheel zooming feels specific to 2D maps. So I think it makes sense to introduce a special type of controls (ol.control.DefaultControl) that implement default behaviors. This change also re-introduces the Navigatin control, which is a container for the default behaviors that were previously defined in the map handlers. Maybe this control needs to be renamed to Navigatin2D in the future, and there could be a different Navigation control for 3D maps.
This commit is contained in:
ahocevar
2012-07-12 20:51:47 +02:00
parent 42c4c9d869
commit 3cc069186c
8 changed files with 141 additions and 40 deletions
+5 -24
View File
@@ -47,28 +47,9 @@ 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) {
this.defaultMouseWheel(e);
var defaultControl = this.map_.getDefaultControl();
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();
};
};