Move interaction event handlers to class methods
This commit is contained in:
@@ -38,11 +38,7 @@ class DragRotateAndZoom extends PointerInteraction {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
super(options);
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -76,80 +72,71 @@ class DragRotateAndZoom extends PointerInteraction {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleDragEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @this {DragRotateAndZoom}
|
||||
*/
|
||||
function handleDragEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return;
|
||||
const map = mapBrowserEvent.map;
|
||||
const size = map.getSize();
|
||||
const offset = mapBrowserEvent.pixel;
|
||||
const deltaX = offset[0] - size[0] / 2;
|
||||
const deltaY = size[1] / 2 - offset[1];
|
||||
const theta = Math.atan2(deltaY, deltaX);
|
||||
const magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
const view = map.getView();
|
||||
if (view.getConstraints().rotation !== disable && this.lastAngle_ !== undefined) {
|
||||
const angleDelta = theta - this.lastAngle_;
|
||||
rotateWithoutConstraints(view, view.getRotation() - angleDelta);
|
||||
}
|
||||
this.lastAngle_ = theta;
|
||||
if (this.lastMagnitude_ !== undefined) {
|
||||
const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
|
||||
zoomWithoutConstraints(view, resolution);
|
||||
}
|
||||
if (this.lastMagnitude_ !== undefined) {
|
||||
this.lastScaleDelta_ = this.lastMagnitude_ / magnitude;
|
||||
}
|
||||
this.lastMagnitude_ = magnitude;
|
||||
}
|
||||
|
||||
const map = mapBrowserEvent.map;
|
||||
const size = map.getSize();
|
||||
const offset = mapBrowserEvent.pixel;
|
||||
const deltaX = offset[0] - size[0] / 2;
|
||||
const deltaY = size[1] / 2 - offset[1];
|
||||
const theta = Math.atan2(deltaY, deltaX);
|
||||
const magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
const view = map.getView();
|
||||
if (view.getConstraints().rotation !== disable && this.lastAngle_ !== undefined) {
|
||||
const angleDelta = theta - this.lastAngle_;
|
||||
rotateWithoutConstraints(view, view.getRotation() - angleDelta);
|
||||
}
|
||||
this.lastAngle_ = theta;
|
||||
if (this.lastMagnitude_ !== undefined) {
|
||||
const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude);
|
||||
zoomWithoutConstraints(view, resolution);
|
||||
}
|
||||
if (this.lastMagnitude_ !== undefined) {
|
||||
this.lastScaleDelta_ = this.lastMagnitude_ / magnitude;
|
||||
}
|
||||
this.lastMagnitude_ = magnitude;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleUpEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @return {boolean} Stop drag sequence?
|
||||
* @this {DragRotateAndZoom}
|
||||
*/
|
||||
function handleUpEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const map = mapBrowserEvent.map;
|
||||
const view = map.getView();
|
||||
view.setHint(ViewHint.INTERACTING, -1);
|
||||
const direction = this.lastScaleDelta_ - 1;
|
||||
rotate(view, view.getRotation());
|
||||
zoom(view, view.getResolution(), undefined, this.duration_, direction);
|
||||
this.lastScaleDelta_ = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @return {boolean} Start drag sequence?
|
||||
* @this {DragRotateAndZoom}
|
||||
*/
|
||||
function handleDownEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
const map = mapBrowserEvent.map;
|
||||
const view = map.getView();
|
||||
view.setHint(ViewHint.INTERACTING, -1);
|
||||
const direction = this.lastScaleDelta_ - 1;
|
||||
rotate(view, view.getRotation());
|
||||
zoom(view, view.getResolution(), undefined, this.duration_, direction);
|
||||
this.lastScaleDelta_ = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.condition_(mapBrowserEvent)) {
|
||||
mapBrowserEvent.map.getView().setHint(ViewHint.INTERACTING, 1);
|
||||
this.lastAngle_ = undefined;
|
||||
this.lastMagnitude_ = undefined;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleDownEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.condition_(mapBrowserEvent)) {
|
||||
mapBrowserEvent.map.getView().setHint(ViewHint.INTERACTING, 1);
|
||||
this.lastAngle_ = undefined;
|
||||
this.lastMagnitude_ = undefined;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user