ol3 is now internal, ol is now external
As discussed with @ahocevar, @elemoine and @tschaub.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
goog.provide('ol3.interaction.AltDragRotate');
|
||||
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Drag');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.interaction.Drag}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.AltDragRotate = function(constraints) {
|
||||
|
||||
goog.base(this, constraints);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.startRotation_ = 0;
|
||||
|
||||
};
|
||||
goog.inherits(ol3.interaction.AltDragRotate, ol3.interaction.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.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
|
||||
*/
|
||||
ol3.interaction.AltDragRotate.prototype.handleDragStart =
|
||||
function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
var map = mapBrowserEvent.map;
|
||||
if (browserEvent.isMouseActionButton() && browserEvent.altKey &&
|
||||
map.canRotate()) {
|
||||
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;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
goog.provide('ol3.interaction.CenterConstraint');
|
||||
goog.provide('ol3.interaction.CenterConstraintType');
|
||||
|
||||
goog.require('ol3.Coordinate');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((ol3.Coordinate|undefined),
|
||||
* (number|undefined),
|
||||
* ol3.Coordinate): (ol3.Coordinate|undefined)}
|
||||
*/
|
||||
ol3.interaction.CenterConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Coordinate|undefined} center Center.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {ol3.Coordinate} delta Delta.
|
||||
* @return {ol3.Coordinate|undefined} Center.
|
||||
*/
|
||||
ol3.interaction.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 ol3.Coordinate(x, y);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Coordinate|undefined} center Center.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {ol3.Coordinate} delta Delta.
|
||||
* @return {ol3.Coordinate|undefined} Center.
|
||||
*/
|
||||
ol3.interaction.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 ol3.Coordinate(x, y);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
goog.provide('ol3.interaction.Constraints');
|
||||
|
||||
goog.require('ol3.interaction.CenterConstraintType');
|
||||
goog.require('ol3.interaction.ResolutionConstraintType');
|
||||
goog.require('ol3.interaction.RotationConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol3.interaction.CenterConstraintType} centerConstraint
|
||||
* Center constraint.
|
||||
* @param {ol3.interaction.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
* @param {ol3.interaction.RotationConstraintType} rotationConstraint
|
||||
* Rotation constraint.
|
||||
*/
|
||||
ol3.interaction.Constraints =
|
||||
function(centerConstraint, resolutionConstraint, rotationConstraint) {
|
||||
|
||||
/**
|
||||
* @type {ol3.interaction.CenterConstraintType}
|
||||
*/
|
||||
this.center = centerConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol3.interaction.ResolutionConstraintType}
|
||||
*/
|
||||
this.resolution = resolutionConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol3.interaction.RotationConstraintType}
|
||||
*/
|
||||
this.rotation = rotationConstraint;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
goog.provide('ol3.interaction.DblClickZoom');
|
||||
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol3.Interaction');
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.Interaction}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.DblClickZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol3.interaction.DblClickZoom, ol3.Interaction);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.DblClickZoom.prototype.handleMapBrowserEvent =
|
||||
function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
if (browserEvent.type == goog.events.EventType.DBLCLICK &&
|
||||
browserEvent.isMouseActionButton()) {
|
||||
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();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,122 @@
|
||||
|
||||
goog.provide('ol3.interaction.Drag');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.functions');
|
||||
goog.require('ol3.Coordinate');
|
||||
goog.require('ol3.Interaction');
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.Interaction}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.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 {ol3.Coordinate}
|
||||
*/
|
||||
this.startCenter = null;
|
||||
|
||||
/**
|
||||
* @type {ol3.Coordinate}
|
||||
*/
|
||||
this.startCoordinate = null;
|
||||
|
||||
};
|
||||
goog.inherits(ol3.interaction.Drag, ol3.Interaction);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @protected
|
||||
*/
|
||||
ol3.interaction.Drag.prototype.handleDrag = goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @protected
|
||||
*/
|
||||
ol3.interaction.Drag.prototype.handleDragEnd = goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.MapBrowserEvent} mapBrowserEvent Event.
|
||||
* @protected
|
||||
* @return {boolean} Capture dragging.
|
||||
*/
|
||||
ol3.interaction.Drag.prototype.handleDragStart = goog.functions.FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.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 {!ol3.Coordinate} */ map.getCenter();
|
||||
this.startCoordinate = /** @type {ol3.Coordinate} */
|
||||
mapBrowserEvent.getCoordinate();
|
||||
if (this.handleDragStart(mapBrowserEvent)) {
|
||||
this.dragging_ = true;
|
||||
mapBrowserEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
goog.provide('ol3.interaction.DragPan');
|
||||
|
||||
goog.require('ol3.Coordinate');
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
goog.require('ol3.interaction.Drag');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.interaction.Drag}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.DragPan = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol3.interaction.DragPan, ol3.interaction.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.DragPan.prototype.handleDrag = function(mapBrowserEvent) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var resolution = map.getResolution();
|
||||
var rotation = map.getRotation();
|
||||
var delta =
|
||||
new ol3.Coordinate(-resolution * this.deltaX, resolution * this.deltaY);
|
||||
if (map.canRotate() && goog.isDef(rotation)) {
|
||||
delta.rotate(rotation);
|
||||
}
|
||||
this.pan(map, delta, this.startCenter);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.DragPan.prototype.handleDragStart = function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
if (!browserEvent.shiftKey) {
|
||||
browserEvent.preventDefault();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
// FIXME factor out key precondition (shift et. al)
|
||||
|
||||
goog.provide('ol3.Interaction');
|
||||
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.Interaction = function(constraints) {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {ol3.interaction.Constraints}
|
||||
*/
|
||||
this.constraints = constraints;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Map} map Map.
|
||||
* @param {ol3.Extent} extent Extent.
|
||||
*/
|
||||
ol3.Interaction.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, ol3.Coordinate.ZERO);
|
||||
map.withFrozenRendering(function() {
|
||||
map.setCenter(center);
|
||||
map.setResolution(resolution);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.MapBrowserEvent} mapBrowserEvent Map browser event.
|
||||
*/
|
||||
ol3.Interaction.prototype.handleMapBrowserEvent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Map} map Map.
|
||||
* @param {ol3.Coordinate} delta Delta.
|
||||
* @param {ol3.Coordinate=} opt_anchor Anchor.
|
||||
*/
|
||||
ol3.Interaction.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 {ol3.Map} map Map.
|
||||
* @param {number|undefined} rotation Rotation.
|
||||
* @param {number} delta Delta.
|
||||
* @param {ol3.Coordinate=} opt_anchor Anchor.
|
||||
*/
|
||||
ol3.Interaction.prototype.rotate = function(map, rotation, delta, opt_anchor) {
|
||||
// FIXME handle rotation about anchor
|
||||
rotation = this.constraints.rotation(rotation, delta);
|
||||
map.setRotation(rotation);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Map} map Map.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
*/
|
||||
ol3.Interaction.prototype.setResolution = function(map, resolution) {
|
||||
resolution = this.constraints.resolution(resolution, 0);
|
||||
map.setResolution(resolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol3.Map} map Map.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
* @param {number} delta Delta.
|
||||
* @param {ol3.Coordinate=} opt_anchor Anchor.
|
||||
*/
|
||||
ol3.Interaction.prototype.zoom = function(map, resolution, delta, opt_anchor) {
|
||||
if (goog.isDefAndNotNull(opt_anchor)) {
|
||||
var anchor = opt_anchor;
|
||||
var mapCenter = /** @type {!ol3.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 ol3.Coordinate(x, y);
|
||||
center = this.constraints.center(center, resolution, ol3.Coordinate.ZERO);
|
||||
map.withFrozenRendering(function() {
|
||||
map.setCenter(center);
|
||||
map.setResolution(resolution);
|
||||
});
|
||||
} else {
|
||||
resolution = this.constraints.resolution(resolution, delta);
|
||||
map.setResolution(resolution);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
// FIXME this class is ugly and should be removed
|
||||
|
||||
goog.provide('ol3.interaction.Keyboard');
|
||||
|
||||
goog.require('ol3.Interaction');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.Interaction}
|
||||
*/
|
||||
ol3.interaction.Keyboard = function() {
|
||||
|
||||
goog.base(this, null);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<number, Function>}
|
||||
*/
|
||||
this.charCodeCallbacks_ = {};
|
||||
|
||||
};
|
||||
goog.inherits(ol3.interaction.Keyboard, ol3.Interaction);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} s String.
|
||||
* @param {Function} callback Callback.
|
||||
*/
|
||||
ol3.interaction.Keyboard.prototype.addCallback = function(s, callback) {
|
||||
var i;
|
||||
for (i = 0; i < s.length; ++i) {
|
||||
this.charCodeCallbacks_[s.charCodeAt(i)] = callback;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.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();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
goog.provide('ol3.interaction.KeyboardPan');
|
||||
|
||||
goog.require('goog.events.KeyCodes');
|
||||
goog.require('goog.events.KeyHandler.EventType');
|
||||
goog.require('ol3.Interaction');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.Interaction}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
* @param {number} pixelDelta Pixel delta.
|
||||
*/
|
||||
ol3.interaction.KeyboardPan = function(constraints, pixelDelta) {
|
||||
|
||||
goog.base(this, constraints);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.pixelDelta_ = pixelDelta;
|
||||
|
||||
};
|
||||
goog.inherits(ol3.interaction.KeyboardPan, ol3.Interaction);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.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 ol3.Coordinate(0, -mapUnitsDelta);
|
||||
} else if (keyCode == goog.events.KeyCodes.LEFT) {
|
||||
delta = new ol3.Coordinate(-mapUnitsDelta, 0);
|
||||
} else if (keyCode == goog.events.KeyCodes.RIGHT) {
|
||||
delta = new ol3.Coordinate(mapUnitsDelta, 0);
|
||||
} else {
|
||||
goog.asserts.assert(keyCode == goog.events.KeyCodes.UP);
|
||||
delta = new ol3.Coordinate(0, mapUnitsDelta);
|
||||
}
|
||||
this.pan(map, delta);
|
||||
keyEvent.preventDefault();
|
||||
mapBrowserEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
goog.provide('ol3.interaction.KeyboardZoom');
|
||||
|
||||
goog.require('goog.events.KeyCodes');
|
||||
goog.require('goog.events.KeyHandler.EventType');
|
||||
goog.require('ol3.Interaction');
|
||||
goog.require('ol3.interaction.ResolutionConstraintType');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.Interaction}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.KeyboardZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol3.interaction.KeyboardZoom, ol3.Interaction);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.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();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
goog.provide('ol3.interaction.MouseWheelZoom');
|
||||
|
||||
goog.require('goog.events.MouseWheelEvent');
|
||||
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.Interaction}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.MouseWheelZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol3.interaction.MouseWheelZoom, ol3.Interaction);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.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();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
goog.provide('ol3.interaction.ResolutionConstraint');
|
||||
goog.provide('ol3.interaction.ResolutionConstraintType');
|
||||
|
||||
goog.require('goog.math');
|
||||
goog.require('ol3.array');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
*/
|
||||
ol3.interaction.ResolutionConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} power Power.
|
||||
* @param {number} maxResolution Maximum resolution.
|
||||
* @param {number=} opt_minResolution Minimum resolution.
|
||||
* @return {ol3.interaction.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol3.interaction.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 {ol3.interaction.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol3.interaction.ResolutionConstraint.createSnapToResolutions =
|
||||
function(resolutions) {
|
||||
return function(resolution, delta) {
|
||||
if (goog.isDef(resolution)) {
|
||||
var z = ol3.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 {ol3.interaction.ResolutionConstraintType} Zoom function.
|
||||
*/
|
||||
ol3.interaction.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;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,159 @@
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('ol3.interaction.ResolutionConstraint');
|
||||
|
||||
|
||||
function testSnapToResolutionsZero() {
|
||||
var resolutionConstraint =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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 =
|
||||
ol3.interaction.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));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
goog.provide('ol3.interaction.RotationConstraint');
|
||||
goog.provide('ol3.interaction.RotationConstraintType');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||
*/
|
||||
ol3.interaction.RotationConstraintType;
|
||||
|
||||
|
||||
/**
|
||||
* @param {number|undefined} rotation Rotation.
|
||||
* @param {number} delta Delta.
|
||||
* @return {number|undefined} Rotation.
|
||||
*/
|
||||
ol3.interaction.RotationConstraint.none = function(rotation, delta) {
|
||||
if (goog.isDef(rotation)) {
|
||||
return rotation + delta;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} n N.
|
||||
* @return {ol3.interaction.RotationConstraintType} Rotation constraint.
|
||||
*/
|
||||
ol3.interaction.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;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
goog.provide('ol3.interaction.ShiftDragRotateAndZoom');
|
||||
|
||||
goog.require('goog.math.Vec2');
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
goog.require('ol3.interaction.Drag');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.interaction.Drag}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.ShiftDragRotateAndZoom = function(constraints) {
|
||||
|
||||
goog.base(this, constraints);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.startRatio_ = 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.startRotation_ = 0;
|
||||
|
||||
};
|
||||
goog.inherits(ol3.interaction.ShiftDragRotateAndZoom, ol3.interaction.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.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
|
||||
*/
|
||||
ol3.interaction.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;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
// FIXME draw drag box
|
||||
|
||||
goog.provide('ol3.interaction.ShiftDragZoom');
|
||||
|
||||
goog.require('ol3.Extent');
|
||||
goog.require('ol3.MapBrowserEvent');
|
||||
goog.require('ol3.interaction.Constraints');
|
||||
goog.require('ol3.interaction.Drag');
|
||||
|
||||
|
||||
/**
|
||||
* @define {number} Hysterisis pixels.
|
||||
*/
|
||||
ol3.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS = 8;
|
||||
|
||||
|
||||
/**
|
||||
* @const {number}
|
||||
*/
|
||||
ol3.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS_SQUARED =
|
||||
ol3.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS *
|
||||
ol3.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol3.interaction.Drag}
|
||||
* @param {ol3.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol3.interaction.ShiftDragZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
};
|
||||
goog.inherits(ol3.interaction.ShiftDragZoom, ol3.interaction.Drag);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.ShiftDragZoom.prototype.handleDragEnd =
|
||||
function(mapBrowserEvent) {
|
||||
if (this.deltaX * this.deltaX + this.deltaY * this.deltaY >=
|
||||
ol3.SHIFT_DRAG_ZOOM_HYSTERESIS_PIXELS_SQUARED) {
|
||||
var map = mapBrowserEvent.map;
|
||||
var extent = ol3.Extent.boundingExtent(
|
||||
this.startCoordinate,
|
||||
mapBrowserEvent.getCoordinate());
|
||||
this.fitExtent(map, extent);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol3.interaction.ShiftDragZoom.prototype.handleDragStart =
|
||||
function(mapBrowserEvent) {
|
||||
var browserEvent = mapBrowserEvent.browserEvent;
|
||||
if (browserEvent.isMouseActionButton() && browserEvent.shiftKey) {
|
||||
browserEvent.preventDefault();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user