Merge pull request #6887 from ahocevar/disable-rotation
Disable rotation for views with enableRotation: false
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
goog.provide('ol.Constraints');
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.CenterConstraintType} centerConstraint Center constraint.
|
||||
* @param {ol.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
* @param {ol.RotationConstraintType} rotationConstraint
|
||||
* Rotation constraint.
|
||||
*/
|
||||
ol.Constraints = function(centerConstraint, resolutionConstraint, rotationConstraint) {
|
||||
|
||||
/**
|
||||
* @type {ol.CenterConstraintType}
|
||||
*/
|
||||
this.center = centerConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol.ResolutionConstraintType}
|
||||
*/
|
||||
this.resolution = resolutionConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol.RotationConstraintType}
|
||||
*/
|
||||
this.rotation = rotationConstraint;
|
||||
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.interaction.DragRotate');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.RotationConstraint');
|
||||
goog.require('ol.ViewHint');
|
||||
goog.require('ol.events.condition');
|
||||
goog.require('ol.functions');
|
||||
@@ -64,13 +65,16 @@ ol.interaction.DragRotate.handleDragEvent_ = function(mapBrowserEvent) {
|
||||
}
|
||||
|
||||
var map = mapBrowserEvent.map;
|
||||
var view = map.getView();
|
||||
if (view.getConstraints().rotation === ol.RotationConstraint.disable) {
|
||||
return;
|
||||
}
|
||||
var size = map.getSize();
|
||||
var offset = mapBrowserEvent.pixel;
|
||||
var theta =
|
||||
Math.atan2(size[1] / 2 - offset[1], offset[0] - size[0] / 2);
|
||||
if (this.lastAngle_ !== undefined) {
|
||||
var delta = theta - this.lastAngle_;
|
||||
var view = map.getView();
|
||||
var rotation = view.getRotation();
|
||||
ol.interaction.Interaction.rotateWithoutConstraints(
|
||||
view, rotation - delta);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.interaction.DragRotateAndZoom');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.RotationConstraint');
|
||||
goog.require('ol.ViewHint');
|
||||
goog.require('ol.events.condition');
|
||||
goog.require('ol.interaction.Interaction');
|
||||
@@ -85,7 +86,7 @@ ol.interaction.DragRotateAndZoom.handleDragEvent_ = function(mapBrowserEvent) {
|
||||
var theta = Math.atan2(deltaY, deltaX);
|
||||
var magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
var view = map.getView();
|
||||
if (this.lastAngle_ !== undefined) {
|
||||
if (view.getConstraints().rotation !== ol.RotationConstraint.disable && this.lastAngle_ !== undefined) {
|
||||
var angleDelta = theta - this.lastAngle_;
|
||||
ol.interaction.Interaction.rotateWithoutConstraints(
|
||||
view, view.getRotation() - angleDelta);
|
||||
|
||||
@@ -5,6 +5,7 @@ goog.require('ol.ViewHint');
|
||||
goog.require('ol.functions');
|
||||
goog.require('ol.interaction.Interaction');
|
||||
goog.require('ol.interaction.Pointer');
|
||||
goog.require('ol.RotationConstraint');
|
||||
|
||||
|
||||
/**
|
||||
@@ -95,6 +96,10 @@ ol.interaction.PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
|
||||
this.lastAngle_ = angle;
|
||||
|
||||
var map = mapBrowserEvent.map;
|
||||
var view = map.getView();
|
||||
if (view.getConstraints().rotation === ol.RotationConstraint.disable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// rotate anchor point.
|
||||
// FIXME: should be the intersection point between the lines:
|
||||
@@ -107,7 +112,6 @@ ol.interaction.PinchRotate.handleDragEvent_ = function(mapBrowserEvent) {
|
||||
|
||||
// rotate
|
||||
if (this.rotating_) {
|
||||
var view = map.getView();
|
||||
var rotation = view.getRotation();
|
||||
map.render();
|
||||
ol.interaction.Interaction.rotateWithoutConstraints(view,
|
||||
|
||||
@@ -130,6 +130,16 @@ ol.Color;
|
||||
ol.ColorLike;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* center: ol.CenterConstraintType,
|
||||
* resolution: ol.ResolutionConstraintType,
|
||||
* rotation: ol.RotationConstraintType
|
||||
* }}
|
||||
*/
|
||||
ol.Constraints;
|
||||
|
||||
|
||||
/**
|
||||
* An array of numbers representing an xy coordinate. Example: `[16, 48]`.
|
||||
* @typedef {Array.<number>}
|
||||
|
||||
@@ -2,7 +2,6 @@ goog.provide('ol.View');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.CenterConstraint');
|
||||
goog.require('ol.Constraints');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.ResolutionConstraint');
|
||||
goog.require('ol.RotationConstraint');
|
||||
@@ -169,8 +168,11 @@ ol.View.prototype.applyOptions_ = function(options) {
|
||||
* @private
|
||||
* @type {ol.Constraints}
|
||||
*/
|
||||
this.constraints_ = new ol.Constraints(
|
||||
centerConstraint, resolutionConstraint, rotationConstraint);
|
||||
this.constraints_ = {
|
||||
center: centerConstraint,
|
||||
resolution: resolutionConstraint,
|
||||
rotation: rotationConstraint
|
||||
};
|
||||
|
||||
if (options.resolution !== undefined) {
|
||||
properties[ol.ViewProperty.RESOLUTION] = options.resolution;
|
||||
@@ -528,6 +530,14 @@ ol.View.prototype.getCenter = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Constraints} Constraints.
|
||||
*/
|
||||
ol.View.prototype.getConstraints = function() {
|
||||
return this.constraints_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<number>=} opt_hints Destination array.
|
||||
* @return {Array.<number>} Hint.
|
||||
|
||||
Reference in New Issue
Block a user