Add ol.control.MouseWheelZoom
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
goog.provide('ol.control.MouseWheelZoom');
|
||||||
|
|
||||||
|
goog.require('goog.events.MouseWheelEvent');
|
||||||
|
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||||
|
goog.require('ol.MapBrowserEvent');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.Control}
|
||||||
|
*/
|
||||||
|
ol.control.MouseWheelZoom = function() {
|
||||||
|
goog.base(this);
|
||||||
|
};
|
||||||
|
goog.inherits(ol.control.MouseWheelZoom, ol.Control);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.control.MouseWheelZoom.prototype.handleMapBrowserEvent = function(event) {
|
||||||
|
if (event.type == goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) {
|
||||||
|
var map = event.map;
|
||||||
|
var mouseWheelEvent = /** @type {goog.events.MouseWheelEvent} */
|
||||||
|
event.getBrowserEventObject();
|
||||||
|
goog.asserts.assert(mouseWheelEvent instanceof goog.events.MouseWheelEvent);
|
||||||
|
if (mouseWheelEvent.deltaY !== 0) {
|
||||||
|
map.whileFrozen(function() {
|
||||||
|
// FIXME compute correct center for zoom
|
||||||
|
map.setCenter(event.getCoordinate());
|
||||||
|
var scale = mouseWheelEvent.deltaY < 0 ? 0.5 : 2;
|
||||||
|
map.setResolution(scale * map.getResolution());
|
||||||
|
});
|
||||||
|
event.preventDefault();
|
||||||
|
mouseWheelEvent.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -7,6 +7,7 @@ goog.require('ol.Map');
|
|||||||
goog.require('ol.MapProperty');
|
goog.require('ol.MapProperty');
|
||||||
goog.require('ol.Projection');
|
goog.require('ol.Projection');
|
||||||
goog.require('ol.control.DblClickZoom');
|
goog.require('ol.control.DblClickZoom');
|
||||||
|
goog.require('ol.control.MouseWheelZoom');
|
||||||
goog.require('ol.dom');
|
goog.require('ol.dom');
|
||||||
goog.require('ol.dom.Map');
|
goog.require('ol.dom.Map');
|
||||||
goog.require('ol.webgl');
|
goog.require('ol.webgl');
|
||||||
@@ -66,6 +67,7 @@ ol.createMap = function(target, opt_values, opt_rendererHints) {
|
|||||||
if (!goog.object.containsKey(values, ol.MapProperty.CONTROLS)) {
|
if (!goog.object.containsKey(values, ol.MapProperty.CONTROLS)) {
|
||||||
var controls = new ol.Array();
|
var controls = new ol.Array();
|
||||||
controls.push(new ol.control.DblClickZoom());
|
controls.push(new ol.control.DblClickZoom());
|
||||||
|
controls.push(new ol.control.MouseWheelZoom());
|
||||||
values[ol.MapProperty.CONTROLS] = controls;
|
values[ol.MapProperty.CONTROLS] = controls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ goog.require('goog.events');
|
|||||||
goog.require('goog.events.BrowserEvent');
|
goog.require('goog.events.BrowserEvent');
|
||||||
goog.require('goog.events.Event');
|
goog.require('goog.events.Event');
|
||||||
goog.require('goog.events.EventType');
|
goog.require('goog.events.EventType');
|
||||||
|
goog.require('goog.events.MouseWheelEvent');
|
||||||
|
goog.require('goog.events.MouseWheelHandler');
|
||||||
|
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||||
goog.require('goog.fx.anim');
|
goog.require('goog.fx.anim');
|
||||||
goog.require('goog.fx.anim.Animated');
|
goog.require('goog.fx.anim.Animated');
|
||||||
goog.require('goog.math.Coordinate');
|
goog.require('goog.math.Coordinate');
|
||||||
@@ -73,6 +76,12 @@ ol.Map = function(target, opt_values, opt_viewportSizeMonitor) {
|
|||||||
goog.events.EventType.CLICK
|
goog.events.EventType.CLICK
|
||||||
], this.handleBrowserEvent, false, this);
|
], this.handleBrowserEvent, false, this);
|
||||||
|
|
||||||
|
var mouseWheelHandler = new goog.events.MouseWheelHandler(this.eventsPane_);
|
||||||
|
goog.events.listen(mouseWheelHandler,
|
||||||
|
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL,
|
||||||
|
this.handleBrowserEvent, false, this);
|
||||||
|
this.registerDisposable(mouseWheelHandler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {goog.fx.anim.Animated}
|
* @type {goog.fx.anim.Animated}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ goog.require('ol.TileUrlFunction');
|
|||||||
goog.require('ol.TileUrlFunctionType');
|
goog.require('ol.TileUrlFunctionType');
|
||||||
goog.require('ol.TransformFunction');
|
goog.require('ol.TransformFunction');
|
||||||
goog.require('ol.control.DblClickZoom');
|
goog.require('ol.control.DblClickZoom');
|
||||||
|
goog.require('ol.control.MouseWheelZoom');
|
||||||
goog.require('ol.createMap');
|
goog.require('ol.createMap');
|
||||||
goog.require('ol.dom');
|
goog.require('ol.dom');
|
||||||
goog.require('ol.dom.LayerRenderer');
|
goog.require('ol.dom.LayerRenderer');
|
||||||
|
|||||||
Reference in New Issue
Block a user