From 244fbbbb8dc705a0a2425a8b99a78a82497af327 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 10:17:21 -0700 Subject: [PATCH] Remove some of the static members from Interaction --- src/ol/interaction/DragRotate.js | 5 ++--- src/ol/interaction/DragRotateAndZoom.js | 9 ++++----- src/ol/interaction/Interaction.js | 19 +++++++++---------- src/ol/interaction/PinchRotate.js | 5 ++--- src/ol/interaction/PinchZoom.js | 7 +++---- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/ol/interaction/DragRotate.js b/src/ol/interaction/DragRotate.js index 65916b323e..689a60554a 100644 --- a/src/ol/interaction/DragRotate.js +++ b/src/ol/interaction/DragRotate.js @@ -6,7 +6,7 @@ import {disable} from '../rotationconstraint.js'; import ViewHint from '../ViewHint.js'; import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js'; import {FALSE} from '../functions.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {rotate} from '../interaction/Interaction.js'; import PointerInteraction from '../interaction/Pointer.js'; /** @@ -96,8 +96,7 @@ function handleUpEvent(mapBrowserEvent) { const view = map.getView(); view.setHint(ViewHint.INTERACTING, -1); const rotation = view.getRotation(); - Interaction.rotate(view, rotation, - undefined, this.duration_); + rotate(view, rotation, undefined, this.duration_); return false; } diff --git a/src/ol/interaction/DragRotateAndZoom.js b/src/ol/interaction/DragRotateAndZoom.js index 482b6fc54a..39a68a52f0 100644 --- a/src/ol/interaction/DragRotateAndZoom.js +++ b/src/ol/interaction/DragRotateAndZoom.js @@ -5,7 +5,7 @@ import {inherits} from '../index.js'; import {disable} from '../rotationconstraint.js'; import ViewHint from '../ViewHint.js'; import {shiftKeyOnly, mouseOnly} from '../events/condition.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {rotate, zoom, zoomWithoutConstraints} from '../interaction/Interaction.js'; import PointerInteraction from '../interaction/Pointer.js'; /** @@ -93,7 +93,7 @@ function handleDragEvent(mapBrowserEvent) { this.lastAngle_ = theta; if (this.lastMagnitude_ !== undefined) { const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); - Interaction.zoomWithoutConstraints(view, resolution); + zoomWithoutConstraints(view, resolution); } if (this.lastMagnitude_ !== undefined) { this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; @@ -116,9 +116,8 @@ function handleUpEvent(mapBrowserEvent) { const view = map.getView(); view.setHint(ViewHint.INTERACTING, -1); const direction = this.lastScaleDelta_ - 1; - Interaction.rotate(view, view.getRotation()); - Interaction.zoom(view, view.getResolution(), - undefined, this.duration_, direction); + rotate(view, view.getRotation()); + zoom(view, view.getResolution(), undefined, this.duration_, direction); this.lastScaleDelta_ = 0; return false; } diff --git a/src/ol/interaction/Interaction.js b/src/ol/interaction/Interaction.js index 604f9433fb..893d64f989 100644 --- a/src/ol/interaction/Interaction.js +++ b/src/ol/interaction/Interaction.js @@ -132,11 +132,11 @@ Interaction.pan = function(view, delta, opt_duration) { * @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {number=} opt_duration Duration. */ -Interaction.rotate = function(view, rotation, opt_anchor, opt_duration) { +export function rotate(view, rotation, opt_anchor, opt_duration) { rotation = view.constrainRotation(rotation, 0); Interaction.rotateWithoutConstraints( view, rotation, opt_anchor, opt_duration); -}; +} /** @@ -177,11 +177,10 @@ Interaction.rotateWithoutConstraints = function(view, rotation, opt_anchor, opt_ * will select the nearest resolution. If not defined 0 is * assumed. */ -Interaction.zoom = function(view, resolution, opt_anchor, opt_duration, opt_direction) { +export function zoom(view, resolution, opt_anchor, opt_duration, opt_direction) { resolution = view.constrainResolution(resolution, 0, opt_direction); - Interaction.zoomWithoutConstraints( - view, resolution, opt_anchor, opt_duration); -}; + zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration); +} /** @@ -218,8 +217,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) { ]; } - Interaction.zoomWithoutConstraints( - view, resolution, opt_anchor, opt_duration); + zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration); }; @@ -229,7 +227,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) { * @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {number=} opt_duration Duration. */ -Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_duration) { +export function zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration) { if (resolution) { const currentResolution = view.getResolution(); const currentCenter = view.getCenter(); @@ -249,5 +247,6 @@ Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_ view.setResolution(resolution); } } -}; +} + export default Interaction; diff --git a/src/ol/interaction/PinchRotate.js b/src/ol/interaction/PinchRotate.js index 88dfe0dd49..9948f51fb4 100644 --- a/src/ol/interaction/PinchRotate.js +++ b/src/ol/interaction/PinchRotate.js @@ -4,7 +4,7 @@ import {inherits} from '../index.js'; import ViewHint from '../ViewHint.js'; import {FALSE} from '../functions.js'; -import Interaction from '../interaction/Interaction.js'; +import Interaction, {rotate} from '../interaction/Interaction.js'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js'; import {disable} from '../rotationconstraint.js'; @@ -132,8 +132,7 @@ function handleUpEvent(mapBrowserEvent) { view.setHint(ViewHint.INTERACTING, -1); if (this.rotating_) { const rotation = view.getRotation(); - Interaction.rotate( - view, rotation, this.anchor_, this.duration_); + rotate(view, rotation, this.anchor_, this.duration_); } return false; } else { diff --git a/src/ol/interaction/PinchZoom.js b/src/ol/interaction/PinchZoom.js index 13989c7538..ea69a9d363 100644 --- a/src/ol/interaction/PinchZoom.js +++ b/src/ol/interaction/PinchZoom.js @@ -4,7 +4,7 @@ import {inherits} from '../index.js'; import ViewHint from '../ViewHint.js'; import {FALSE} from '../functions.js'; -import Interaction from '../interaction/Interaction.js'; +import {zoom, zoomWithoutConstraints} from '../interaction/Interaction.js'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js'; /** @@ -110,7 +110,7 @@ function handleDragEvent(mapBrowserEvent) { // scale, bypass the resolution constraint map.render(); - Interaction.zoomWithoutConstraints(view, newResolution, this.anchor_); + zoomWithoutConstraints(view, newResolution, this.anchor_); } @@ -132,8 +132,7 @@ function handleUpEvent(mapBrowserEvent) { // direction not to zoom out/in if user was pinching in/out. // Direction is > 0 if pinching out, and < 0 if pinching in. const direction = this.lastScaleDelta_ - 1; - Interaction.zoom(view, resolution, - this.anchor_, this.duration_, direction); + zoom(view, resolution, this.anchor_, this.duration_, direction); } return false; } else {