Remove some of the static members from Interaction

This commit is contained in:
Tim Schaub
2018-02-25 10:17:21 -07:00
parent 3f944ef76e
commit 244fbbbb8d
5 changed files with 20 additions and 25 deletions

View File

@@ -6,7 +6,7 @@ import {disable} from '../rotationconstraint.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js'; import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js';
import {FALSE} from '../functions.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'; import PointerInteraction from '../interaction/Pointer.js';
/** /**
@@ -96,8 +96,7 @@ function handleUpEvent(mapBrowserEvent) {
const view = map.getView(); const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1); view.setHint(ViewHint.INTERACTING, -1);
const rotation = view.getRotation(); const rotation = view.getRotation();
Interaction.rotate(view, rotation, rotate(view, rotation, undefined, this.duration_);
undefined, this.duration_);
return false; return false;
} }

View File

@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import {disable} from '../rotationconstraint.js'; import {disable} from '../rotationconstraint.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {shiftKeyOnly, mouseOnly} from '../events/condition.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'; import PointerInteraction from '../interaction/Pointer.js';
/** /**
@@ -93,7 +93,7 @@ function handleDragEvent(mapBrowserEvent) {
this.lastAngle_ = theta; this.lastAngle_ = theta;
if (this.lastMagnitude_ !== undefined) { if (this.lastMagnitude_ !== undefined) {
const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
Interaction.zoomWithoutConstraints(view, resolution); zoomWithoutConstraints(view, resolution);
} }
if (this.lastMagnitude_ !== undefined) { if (this.lastMagnitude_ !== undefined) {
this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; this.lastScaleDelta_ = this.lastMagnitude_ / magnitude;
@@ -116,9 +116,8 @@ function handleUpEvent(mapBrowserEvent) {
const view = map.getView(); const view = map.getView();
view.setHint(ViewHint.INTERACTING, -1); view.setHint(ViewHint.INTERACTING, -1);
const direction = this.lastScaleDelta_ - 1; const direction = this.lastScaleDelta_ - 1;
Interaction.rotate(view, view.getRotation()); rotate(view, view.getRotation());
Interaction.zoom(view, view.getResolution(), zoom(view, view.getResolution(), undefined, this.duration_, direction);
undefined, this.duration_, direction);
this.lastScaleDelta_ = 0; this.lastScaleDelta_ = 0;
return false; return false;
} }

View File

@@ -132,11 +132,11 @@ Interaction.pan = function(view, delta, opt_duration) {
* @param {ol.Coordinate=} opt_anchor Anchor coordinate. * @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @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); rotation = view.constrainRotation(rotation, 0);
Interaction.rotateWithoutConstraints( Interaction.rotateWithoutConstraints(
view, rotation, opt_anchor, opt_duration); 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 * will select the nearest resolution. If not defined 0 is
* assumed. * 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); resolution = view.constrainResolution(resolution, 0, opt_direction);
Interaction.zoomWithoutConstraints( zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration);
view, resolution, opt_anchor, opt_duration); }
};
/** /**
@@ -218,8 +217,7 @@ Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_duration) {
]; ];
} }
Interaction.zoomWithoutConstraints( zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration);
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 {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration. * @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) { if (resolution) {
const currentResolution = view.getResolution(); const currentResolution = view.getResolution();
const currentCenter = view.getCenter(); const currentCenter = view.getCenter();
@@ -249,5 +247,6 @@ Interaction.zoomWithoutConstraints = function(view, resolution, opt_anchor, opt_
view.setResolution(resolution); view.setResolution(resolution);
} }
} }
}; }
export default Interaction; export default Interaction;

View File

@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.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 PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
import {disable} from '../rotationconstraint.js'; import {disable} from '../rotationconstraint.js';
@@ -132,8 +132,7 @@ function handleUpEvent(mapBrowserEvent) {
view.setHint(ViewHint.INTERACTING, -1); view.setHint(ViewHint.INTERACTING, -1);
if (this.rotating_) { if (this.rotating_) {
const rotation = view.getRotation(); const rotation = view.getRotation();
Interaction.rotate( rotate(view, rotation, this.anchor_, this.duration_);
view, rotation, this.anchor_, this.duration_);
} }
return false; return false;
} else { } else {

View File

@@ -4,7 +4,7 @@
import {inherits} from '../index.js'; import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js'; import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.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'; import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
/** /**
@@ -110,7 +110,7 @@ function handleDragEvent(mapBrowserEvent) {
// scale, bypass the resolution constraint // scale, bypass the resolution constraint
map.render(); 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 not to zoom out/in if user was pinching in/out.
// Direction is > 0 if pinching out, and < 0 if pinching in. // Direction is > 0 if pinching out, and < 0 if pinching in.
const direction = this.lastScaleDelta_ - 1; const direction = this.lastScaleDelta_ - 1;
Interaction.zoom(view, resolution, zoom(view, resolution, this.anchor_, this.duration_, direction);
this.anchor_, this.duration_, direction);
} }
return false; return false;
} else { } else {