Disable rotation for views with enableRotation: false

This commit is contained in:
Andreas Hocevar
2017-06-08 17:29:19 +02:00
parent 9691130b83
commit 00c8a5845e
7 changed files with 104 additions and 35 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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,