s/Control/Interaction/, thanks @elemoine
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
goog.provide('ol.control.AltDragRotate');
|
||||
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Drag');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Drag}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.AltDragRotate = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol.control.AltDragRotate, ol.control.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
ol.control.AltDragRotate.prototype.startRotation_;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.AltDragRotate.prototype.handleDrag = function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
var map = mapBrowserEvent.map;
|
||||
var size = map.getSize();
|
||||
var theta = Math.atan2(
|
||||
size.height / 2 - browserEvent.offsetY,
|
||||
browserEvent.offsetX - size.width / 2);
|
||||
this.rotate(map, this.startRotation_, -theta);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.AltDragRotate.prototype.handleDragStart =
|
||||
function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
var map = mapBrowserEvent.map;
|
||||
if (map.canRotate() && browserEvent.altKey) {
|
||||
var size = map.getSize();
|
||||
var theta = Math.atan2(
|
||||
size.height / 2 - browserEvent.offsetY,
|
||||
browserEvent.offsetX - size.width / 2);
|
||||
this.startRotation_ = (map.getRotation() || 0) + theta;
|
||||
browserEvent.preventDefault();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -1,46 +0,0 @@
|
||||
goog.provide('ol.control.CenterConstraint');
|
||||
goog.provide('ol.control.CenterConstraintType');
|
||||
|
||||
goog.require('ol.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((ol.Coordinate|undefined),
|
||||
* (number|undefined),
|
||||
* ol.Coordinate): (ol.Coordinate|undefined)}
|
||||
*/
|
||||
ol.control.CenterConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} center Center.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {ol.Coordinate} delta Delta.
|
||||
* @return {ol.Coordinate|undefined} Center.
|
||||
*/
|
||||
ol.control.CenterConstraint.none = function(center, resolution, delta) {
|
||||
if (goog.isDefAndNotNull(center) && goog.isDef(resolution)) {
|
||||
var x = center.x + delta.x;
|
||||
var y = center.y + delta.y;
|
||||
return new ol.Coordinate(x, y);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} center Center.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {ol.Coordinate} delta Delta.
|
||||
* @return {ol.Coordinate|undefined} Center.
|
||||
*/
|
||||
ol.control.CenterConstraint.snapToPixel = function(center, resolution, delta) {
|
||||
if (goog.isDefAndNotNull(center) && goog.isDef(resolution)) {
|
||||
var x = Math.floor((center.x + delta.x) / resolution + 0.5) * resolution;
|
||||
var y = Math.floor((center.y + delta.y) / resolution + 0.5) * resolution;
|
||||
return new ol.Coordinate(x, y);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
goog.provide('ol.control.Constraints');
|
||||
|
||||
goog.require('ol.control.CenterConstraintType');
|
||||
goog.require('ol.control.ResolutionConstraintType');
|
||||
goog.require('ol.control.RotationConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.control.CenterConstraintType} centerConstraint Center constraint.
|
||||
* @param {ol.control.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
* @param {ol.control.RotationConstraintType} rotationConstraint
|
||||
* Rotation constraint.
|
||||
*/
|
||||
ol.control.Constraints =
|
||||
function(centerConstraint, resolutionConstraint, rotationConstraint) {
|
||||
|
||||
/**
|
||||
* @type {ol.control.CenterConstraintType}
|
||||
*/
|
||||
this.center = centerConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol.control.ResolutionConstraintType}
|
||||
*/
|
||||
this.resolution = resolutionConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol.control.RotationConstraintType}
|
||||
*/
|
||||
this.rotation = rotationConstraint;
|
||||
|
||||
};
|
||||
@@ -1,107 +0,0 @@
|
||||
// FIXME factor out key precondition (shift et. al)
|
||||
|
||||
goog.provide('ol.Control');
|
||||
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.Control = function(constraints) {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol.control.Constraints}
|
||||
*/
|
||||
this.constraints = constraints;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
|
||||
*/
|
||||
ol.Control.prototype.handleMapBrowserEvent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {ol.Extent} extent Extent.
|
||||
*/
|
||||
ol.Control.prototype.fitExtent = function(map, extent) {
|
||||
var resolution = map.getResolutionForExtent(extent);
|
||||
resolution = this.constraints.resolution(resolution, 0);
|
||||
var center = extent.getCenter();
|
||||
center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
|
||||
map.withFrozenRendering(function() {
|
||||
map.setCenter(center);
|
||||
map.setResolution(resolution);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {ol.Coordinate} delta Delta.
|
||||
* @param {ol.Coordinate=} opt_anchor Anchor.
|
||||
*/
|
||||
ol.Control.prototype.pan = function(map, delta, opt_anchor) {
|
||||
var center = opt_anchor ? opt_anchor : map.getCenter();
|
||||
var resolution = map.getResolution();
|
||||
center = this.constraints.center(center, resolution, delta);
|
||||
map.setCenter(center);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {number|undefined} rotation Rotation.
|
||||
* @param {number} delta Delta.
|
||||
* @param {ol.Coordinate=} opt_anchor Anchor.
|
||||
*/
|
||||
ol.Control.prototype.rotate = function(map, rotation, delta, opt_anchor) {
|
||||
// FIXME handle rotation about anchor
|
||||
rotation = this.constraints.rotation(rotation, delta);
|
||||
map.setRotation(rotation);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
*/
|
||||
ol.Control.prototype.setResolution = function(map, resolution) {
|
||||
resolution = this.constraints.resolution(resolution, 0);
|
||||
map.setResolution(resolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Map} map Map.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {number} delta Delta.
|
||||
* @param {ol.Coordinate=} opt_anchor Anchor.
|
||||
*/
|
||||
ol.Control.prototype.zoom = function(map, resolution, delta, opt_anchor) {
|
||||
if (goog.isDefAndNotNull(opt_anchor)) {
|
||||
var anchor = opt_anchor;
|
||||
var mapCenter = /** @type {!ol.Coordinate} */ map.getCenter();
|
||||
var mapResolution = map.getResolution();
|
||||
resolution = this.constraints.resolution(resolution, delta);
|
||||
var x = anchor.x - resolution * (anchor.x - mapCenter.x) / mapResolution;
|
||||
var y = anchor.y - resolution * (anchor.y - mapCenter.y) / mapResolution;
|
||||
var center = new ol.Coordinate(x, y);
|
||||
center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
|
||||
map.withFrozenRendering(function() {
|
||||
map.setCenter(center);
|
||||
map.setResolution(resolution);
|
||||
});
|
||||
} else {
|
||||
resolution = this.constraints.resolution(resolution, delta);
|
||||
map.setResolution(resolution);
|
||||
}
|
||||
};
|
||||
@@ -1,34 +0,0 @@
|
||||
goog.provide('ol.control.DblClickZoom');
|
||||
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Control');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.DblClickZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol.control.DblClickZoom, ol.Control);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.DblClickZoom.prototype.handleMapBrowserEvent =
|
||||
function(mapBrowserEvent) {
|
||||
if (mapBrowserEvent.type == goog.events.EventType.DBLCLICK) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var resolution = map.getResolution();
|
||||
var delta = mapBrowserEvent.browserEvent.shiftKey ? -1 : 1;
|
||||
var anchor = mapBrowserEvent.getCoordinate();
|
||||
this.zoom(map, resolution, delta, anchor);
|
||||
mapBrowserEvent.preventDefault();
|
||||
}
|
||||
};
|
||||
@@ -1,121 +0,0 @@
|
||||
|
||||
goog.provide('ol.control.Drag');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol.Control');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.Drag = function(constraints) {
|
||||
|
||||
goog.base(this, constraints);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.dragging_ = false;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.startX = 0;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.startY = 0;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.offsetX = 0;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.offsetY = 0;
|
||||
|
||||
/**
|
||||
* @type {ol.Coordinate}
|
||||
*/
|
||||
this.startCenter = null;
|
||||
|
||||
/**
|
||||
* @type {ol.Coordinate}
|
||||
*/
|
||||
this.startCoordinate = null;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.Drag, ol.Control);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @protected
|
||||
*/
|
||||
ol.control.Drag.prototype.handleDrag = goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @protected
|
||||
* @return {boolean} Capture dragging.
|
||||
*/
|
||||
ol.control.Drag.prototype.handleDragStart = goog.functions.FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @protected
|
||||
*/
|
||||
ol.control.Drag.prototype.handleDragEnd = goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.Drag.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
|
||||
var map = mapBrowserEvent.map;
|
||||
if (!map.isDef()) {
|
||||
return;
|
||||
}
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
if (this.dragging_) {
|
||||
if (mapBrowserEvent.type == goog.fx.Dragger.EventType.DRAG) {
|
||||
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
|
||||
this.deltaX = browserEvent.clientX - this.startX;
|
||||
this.deltaY = browserEvent.clientY - this.startY;
|
||||
this.handleDrag(mapBrowserEvent);
|
||||
} else if (mapBrowserEvent.type == goog.fx.Dragger.EventType.END) {
|
||||
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
|
||||
this.deltaX = browserEvent.clientX - this.startX;
|
||||
this.deltaY = browserEvent.clientY - this.startY;
|
||||
this.handleDragEnd(mapBrowserEvent);
|
||||
this.dragging_ = false;
|
||||
}
|
||||
} else if (mapBrowserEvent.type == goog.fx.Dragger.EventType.START) {
|
||||
goog.asserts.assert(browserEvent instanceof goog.events.BrowserEvent);
|
||||
this.startX = browserEvent.clientX;
|
||||
this.startY = browserEvent.clientY;
|
||||
this.deltaX = 0;
|
||||
this.deltaY = 0;
|
||||
this.startCenter = /** @type {!ol.Coordinate} */ map.getCenter();
|
||||
this.startCoordinate = /** @type {ol.Coordinate} */
|
||||
mapBrowserEvent.getCoordinate();
|
||||
if (this.handleDragStart(mapBrowserEvent)) {
|
||||
this.dragging_ = true;
|
||||
mapBrowserEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,46 +0,0 @@
|
||||
// FIXME cope with rotation
|
||||
|
||||
goog.provide('ol.control.DragPan');
|
||||
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Constraints');
|
||||
goog.require('ol.control.Drag');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Drag}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.DragPan = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol.control.DragPan, ol.control.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.DragPan.prototype.handleDrag = function(mapBrowserEvent) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var resolution = map.getResolution();
|
||||
var delta =
|
||||
new ol.Coordinate(-resolution * this.deltaX, resolution * this.deltaY);
|
||||
this.pan(map, delta, this.startCenter);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.DragPan.prototype.handleDragStart = function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
if (!browserEvent.shiftKey) {
|
||||
browserEvent.preventDefault();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -1,53 +0,0 @@
|
||||
// FIXME this class is ugly and should be removed
|
||||
|
||||
goog.provide('ol.control.Keyboard');
|
||||
|
||||
goog.require('ol.Control');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
*/
|
||||
ol.control.Keyboard = function() {
|
||||
|
||||
goog.base(this, null);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<number, Function>}
|
||||
*/
|
||||
this.charCodeCallbacks_ = {};
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.Keyboard, ol.Control);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} s String.
|
||||
* @param {Function} callback Callback.
|
||||
*/
|
||||
ol.control.Keyboard.prototype.addCallback = function(s, callback) {
|
||||
var i;
|
||||
for (i = 0; i < s.length; ++i) {
|
||||
this.charCodeCallbacks_[s.charCodeAt(i)] = callback;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.Keyboard.prototype.handleMapBrowserEvent =
|
||||
function(mapBrowserEvent) {
|
||||
if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) {
|
||||
var keyEvent = /** @type {goog.events.KeyEvent} */
|
||||
mapBrowserEvent.browserEvent;
|
||||
var callback = this.charCodeCallbacks_[keyEvent.charCode];
|
||||
if (callback) {
|
||||
callback();
|
||||
mapBrowserEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
goog.provide('ol.control.KeyboardPan');
|
||||
|
||||
goog.require('goog.events.KeyCodes');
|
||||
goog.require('goog.events.KeyHandler.EventType');
|
||||
goog.require('ol.Control');
|
||||
goog.require('ol.control.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
* @param {number} pixelDelta Pixel delta.
|
||||
*/
|
||||
ol.control.KeyboardPan = function(constraints, pixelDelta) {
|
||||
|
||||
goog.base(this, constraints);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.pixelDelta_ = pixelDelta;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.KeyboardPan, ol.Control);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.KeyboardPan.prototype.handleMapBrowserEvent =
|
||||
function(mapBrowserEvent) {
|
||||
if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) {
|
||||
var keyEvent = /** @type {goog.events.KeyEvent} */
|
||||
mapBrowserEvent.browserEvent;
|
||||
var keyCode = keyEvent.keyCode;
|
||||
if (keyCode == goog.events.KeyCodes.DOWN ||
|
||||
keyCode == goog.events.KeyCodes.LEFT ||
|
||||
keyCode == goog.events.KeyCodes.RIGHT ||
|
||||
keyCode == goog.events.KeyCodes.UP) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var resolution = map.getResolution();
|
||||
var delta;
|
||||
var mapUnitsDelta = resolution * this.pixelDelta_;
|
||||
if (keyCode == goog.events.KeyCodes.DOWN) {
|
||||
delta = new ol.Coordinate(0, -mapUnitsDelta);
|
||||
} else if (keyCode == goog.events.KeyCodes.LEFT) {
|
||||
delta = new ol.Coordinate(-mapUnitsDelta, 0);
|
||||
} else if (keyCode == goog.events.KeyCodes.RIGHT) {
|
||||
delta = new ol.Coordinate(mapUnitsDelta, 0);
|
||||
} else {
|
||||
goog.asserts.assert(keyCode == goog.events.KeyCodes.UP);
|
||||
delta = new ol.Coordinate(0, mapUnitsDelta);
|
||||
}
|
||||
this.pan(map, delta);
|
||||
keyEvent.preventDefault();
|
||||
mapBrowserEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
goog.provide('ol.control.KeyboardZoom');
|
||||
|
||||
goog.require('goog.events.KeyCodes');
|
||||
goog.require('goog.events.KeyHandler.EventType');
|
||||
goog.require('ol.Control');
|
||||
goog.require('ol.control.ResolutionConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.KeyboardZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol.control.KeyboardZoom, ol.Control);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.KeyboardZoom.prototype.handleMapBrowserEvent =
|
||||
function(mapBrowserEvent) {
|
||||
if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) {
|
||||
var keyEvent = /** @type {goog.events.KeyEvent} */
|
||||
mapBrowserEvent.browserEvent;
|
||||
var charCode = keyEvent.charCode;
|
||||
if (charCode == '+'.charCodeAt(0) || charCode == '-'.charCodeAt(0)) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var resolution = map.getResolution();
|
||||
var delta = charCode == '+'.charCodeAt(0) ? 1 : -1;
|
||||
this.zoom(map, resolution, delta);
|
||||
keyEvent.preventDefault();
|
||||
mapBrowserEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
goog.provide('ol.control.MouseWheelZoom');
|
||||
|
||||
goog.require('goog.events.MouseWheelEvent');
|
||||
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.Control}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.MouseWheelZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol.control.MouseWheelZoom, ol.Control);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.MouseWheelZoom.prototype.handleMapBrowserEvent =
|
||||
function(mapBrowserEvent) {
|
||||
if (mapBrowserEvent.type ==
|
||||
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var mouseWheelEvent = /** @type {goog.events.MouseWheelEvent} */
|
||||
mapBrowserEvent.browserEvent;
|
||||
goog.asserts.assert(mouseWheelEvent instanceof goog.events.MouseWheelEvent);
|
||||
if (mouseWheelEvent.deltaY !== 0) {
|
||||
var delta = mouseWheelEvent.deltaY < 0 ? 1 : -1;
|
||||
var resolution = map.getResolution();
|
||||
var anchor = mapBrowserEvent.getCoordinate();
|
||||
this.zoom(map, resolution, delta, anchor);
|
||||
mapBrowserEvent.preventDefault();
|
||||
mouseWheelEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,73 +0,0 @@
|
||||
goog.provide('ol.control.ResolutionConstraint');
|
||||
goog.provide('ol.control.ResolutionConstraintType');
|
||||
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.array');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
*/
|
||||
ol.control.ResolutionConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} power Power.
|
||||
* @param {number} maxResolution Maximum resolution.
|
||||
* @param {number=} opt_minResolution Minimum resolution.
|
||||
* @return {ol.control.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.control.ResolutionConstraint.createContinuous =
|
||||
function(power, maxResolution, opt_minResolution) {
|
||||
var minResolution = opt_minResolution || 0;
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
resolution /= Math.pow(power, delta);
|
||||
return goog.math.clamp(resolution, minResolution, maxResolution);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>} resolutions Resolutions.
|
||||
* @return {ol.control.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions =
|
||||
function(resolutions) {
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var z = ol.array.linearFindNearest(resolutions, resolution);
|
||||
z = goog.math.clamp(z + delta, 0, resolutions.length - 1);
|
||||
return resolutions[z];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} power Power.
|
||||
* @param {number} maxResolution Maximum resolution.
|
||||
* @param {number=} opt_maxLevel Maximum level.
|
||||
* @return {ol.control.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol.control.ResolutionConstraint.createSnapToPower =
|
||||
function(power, maxResolution, opt_maxLevel) {
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var oldLevel = Math.floor(
|
||||
Math.log(maxResolution / resolution) / Math.log(power) + 0.5);
|
||||
var newLevel = Math.max(oldLevel + delta, 0);
|
||||
if (goog.isDef(opt_maxLevel)) {
|
||||
newLevel = Math.min(newLevel, opt_maxLevel);
|
||||
}
|
||||
return maxResolution / Math.pow(power, newLevel);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,159 +0,0 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol.control.ResolutionConstraint');
|
||||
|
||||
|
||||
function testSnapToResolutionsZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1000, 0));
|
||||
assertEquals(500, resolutionConstraint(500, 0));
|
||||
assertEquals(250, resolutionConstraint(250, 0));
|
||||
assertEquals(100, resolutionConstraint(100, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsZoomIn() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(500, resolutionConstraint(1000, 1));
|
||||
assertEquals(250, resolutionConstraint(500, 1));
|
||||
assertEquals(100, resolutionConstraint(250, 1));
|
||||
assertEquals(100, resolutionConstraint(100, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsZoomOut() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1000, -1));
|
||||
assertEquals(1000, resolutionConstraint(500, -1));
|
||||
assertEquals(500, resolutionConstraint(250, -1));
|
||||
assertEquals(250, resolutionConstraint(100, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1050, 0));
|
||||
assertEquals(1000, resolutionConstraint(950, 0));
|
||||
assertEquals(500, resolutionConstraint(550, 0));
|
||||
assertEquals(500, resolutionConstraint(400, 0));
|
||||
assertEquals(250, resolutionConstraint(300, 0));
|
||||
assertEquals(250, resolutionConstraint(200, 0));
|
||||
assertEquals(100, resolutionConstraint(150, 0));
|
||||
assertEquals(100, resolutionConstraint(50, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZoomIn() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(500, resolutionConstraint(1050, 1));
|
||||
assertEquals(500, resolutionConstraint(950, 1));
|
||||
assertEquals(250, resolutionConstraint(550, 1));
|
||||
assertEquals(250, resolutionConstraint(450, 1));
|
||||
assertEquals(100, resolutionConstraint(300, 1));
|
||||
assertEquals(100, resolutionConstraint(200, 1));
|
||||
assertEquals(100, resolutionConstraint(150, 1));
|
||||
assertEquals(100, resolutionConstraint(50, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToResolutionsNearestZoomOut() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToResolutions(
|
||||
[1000, 500, 250, 100]);
|
||||
assertEquals(1000, resolutionConstraint(1050, -1));
|
||||
assertEquals(1000, resolutionConstraint(950, -1));
|
||||
assertEquals(1000, resolutionConstraint(550, -1));
|
||||
assertEquals(1000, resolutionConstraint(450, -1));
|
||||
assertEquals(500, resolutionConstraint(300, -1));
|
||||
assertEquals(500, resolutionConstraint(200, -1));
|
||||
assertEquals(250, resolutionConstraint(150, -1));
|
||||
assertEquals(250, resolutionConstraint(50, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, resolutionConstraint(1024, 0));
|
||||
assertEquals(512, resolutionConstraint(512, 0));
|
||||
assertEquals(256, resolutionConstraint(256, 0));
|
||||
assertEquals(128, resolutionConstraint(128, 0));
|
||||
assertEquals(64, resolutionConstraint(64, 0));
|
||||
assertEquals(32, resolutionConstraint(32, 0));
|
||||
assertEquals(16, resolutionConstraint(16, 0));
|
||||
assertEquals(8, resolutionConstraint(8, 0));
|
||||
assertEquals(4, resolutionConstraint(4, 0));
|
||||
assertEquals(2, resolutionConstraint(2, 0));
|
||||
assertEquals(1, resolutionConstraint(1, 0));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZoomIn() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(512, resolutionConstraint(1024, 1));
|
||||
assertEquals(256, resolutionConstraint(512, 1));
|
||||
assertEquals(128, resolutionConstraint(256, 1));
|
||||
assertEquals(64, resolutionConstraint(128, 1));
|
||||
assertEquals(32, resolutionConstraint(64, 1));
|
||||
assertEquals(16, resolutionConstraint(32, 1));
|
||||
assertEquals(8, resolutionConstraint(16, 1));
|
||||
assertEquals(4, resolutionConstraint(8, 1));
|
||||
assertEquals(2, resolutionConstraint(4, 1));
|
||||
assertEquals(1, resolutionConstraint(2, 1));
|
||||
assertEquals(1, resolutionConstraint(1, 1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerZoomOut() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, resolutionConstraint(1024, -1));
|
||||
assertEquals(1024, resolutionConstraint(512, -1));
|
||||
assertEquals(512, resolutionConstraint(256, -1));
|
||||
assertEquals(256, resolutionConstraint(128, -1));
|
||||
assertEquals(128, resolutionConstraint(64, -1));
|
||||
assertEquals(64, resolutionConstraint(32, -1));
|
||||
assertEquals(32, resolutionConstraint(16, -1));
|
||||
assertEquals(16, resolutionConstraint(8, -1));
|
||||
assertEquals(8, resolutionConstraint(4, -1));
|
||||
assertEquals(4, resolutionConstraint(2, -1));
|
||||
assertEquals(2, resolutionConstraint(1, -1));
|
||||
}
|
||||
|
||||
|
||||
function testSnapToPowerNearestZero() {
|
||||
var resolutionConstraint =
|
||||
ol.control.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
||||
assertEquals(1024, resolutionConstraint(1050, 0));
|
||||
assertEquals(1024, resolutionConstraint(9050, 0));
|
||||
assertEquals(512, resolutionConstraint(550, 0));
|
||||
assertEquals(512, resolutionConstraint(450, 0));
|
||||
assertEquals(256, resolutionConstraint(300, 0));
|
||||
assertEquals(256, resolutionConstraint(250, 0));
|
||||
assertEquals(128, resolutionConstraint(150, 0));
|
||||
assertEquals(128, resolutionConstraint(100, 0));
|
||||
assertEquals(64, resolutionConstraint(75, 0));
|
||||
assertEquals(64, resolutionConstraint(50, 0));
|
||||
assertEquals(32, resolutionConstraint(40, 0));
|
||||
assertEquals(32, resolutionConstraint(30, 0));
|
||||
assertEquals(16, resolutionConstraint(20, 0));
|
||||
assertEquals(16, resolutionConstraint(12, 0));
|
||||
assertEquals(8, resolutionConstraint(9, 0));
|
||||
assertEquals(8, resolutionConstraint(7, 0));
|
||||
assertEquals(4, resolutionConstraint(5, 0));
|
||||
assertEquals(4, resolutionConstraint(3.5, 0));
|
||||
assertEquals(2, resolutionConstraint(2.1, 0));
|
||||
assertEquals(2, resolutionConstraint(1.9, 0));
|
||||
assertEquals(1, resolutionConstraint(1.1, 0));
|
||||
assertEquals(1, resolutionConstraint(0.9, 0));
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
goog.provide('ol.control.RotationConstraint');
|
||||
goog.provide('ol.control.RotationConstraintType');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
*/
|
||||
ol.control.RotationConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {number|undefined} rotation Rotation.
|
||||
* @param {number} delta Delta.
|
||||
* @return {number|undefined} Rotation.
|
||||
*/
|
||||
ol.control.RotationConstraint.none = function(rotation, delta) {
|
||||
if (goog.isDef(rotation)) {
|
||||
return rotation + delta;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} n N.
|
||||
* @return {ol.control.RotationConstraintType} Rotation constraint.
|
||||
*/
|
||||
ol.control.RotationConstraint.createSnapToN = function(n) {
|
||||
var theta = 2 * Math.PI / n;
|
||||
return function(rotation, delta) {
|
||||
if (goog.isDef(rotation)) {
|
||||
rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
|
||||
return rotation;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,75 +0,0 @@
|
||||
goog.provide('ol.control.ShiftDragRotateAndZoom');
|
||||
|
||||
goog.require('goog.math.Vec2');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Constraints');
|
||||
goog.require('ol.control.Drag');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Drag}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.ShiftDragRotateAndZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol.control.ShiftDragRotateAndZoom, ol.control.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
ol.control.ShiftDragRotateAndZoom.prototype.startRatio_;
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
ol.control.ShiftDragRotateAndZoom.prototype.startRotation_;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.ShiftDragRotateAndZoom.prototype.handleDrag =
|
||||
function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
var map = mapBrowserEvent.map;
|
||||
var size = map.getSize();
|
||||
var delta = new goog.math.Vec2(
|
||||
browserEvent.offsetX - size.width / 2,
|
||||
size.height / 2 - browserEvent.offsetY);
|
||||
var theta = Math.atan2(delta.y, delta.x);
|
||||
// FIXME this should use map.withFrozenRendering but an assertion fails :-(
|
||||
this.rotate(map, this.startRotation_, -theta);
|
||||
var resolution = this.startRatio_ * delta.magnitude();
|
||||
this.setResolution(map, resolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.ShiftDragRotateAndZoom.prototype.handleDragStart =
|
||||
function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
var map = mapBrowserEvent.map;
|
||||
if (map.canRotate() && browserEvent.shiftKey) {
|
||||
var resolution = map.getResolution();
|
||||
var size = map.getSize();
|
||||
var delta = new goog.math.Vec2(
|
||||
browserEvent.offsetX - size.width / 2,
|
||||
size.height / 2 - browserEvent.offsetY);
|
||||
var theta = Math.atan2(delta.y, delta.x);
|
||||
this.startRotation_ = (map.getRotation() || 0) + theta;
|
||||
this.startRatio_ = resolution / delta.magnitude();
|
||||
browserEvent.preventDefault();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
// FIXME draw drag box
|
||||
|
||||
goog.provide('ol.control.ShiftDragZoom');
|
||||
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.control.Constraints');
|
||||
goog.require('ol.control.Drag');
|
||||
|
||||
|
||||
/**
|
||||
* @define {number} Hysterisis pixels.
|
||||
*/
|
||||
ol.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS = 8;
|
||||
|
||||
|
||||
/**
|
||||
* @const {number}
|
||||
*/
|
||||
ol.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS_SQUARED =
|
||||
ol.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS * ol.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.control.Drag}
|
||||
* @param {ol.control.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.control.ShiftDragZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol.control.ShiftDragZoom, ol.control.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.ShiftDragZoom.prototype.handleDragEnd = function(mapBrowserEvent) {
|
||||
if (this.deltaX * this.deltaX + this.deltaY * this.deltaY >=
|
||||
ol.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS_SQUARED) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var extent = ol.Extent.boundingExtent(
|
||||
this.startCoordinate,
|
||||
mapBrowserEvent.getCoordinate());
|
||||
this.fitExtent(map, extent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.control.ShiftDragZoom.prototype.handleDragStart = function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
if (browserEvent.shiftKey) {
|
||||
browserEvent.preventDefault();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user