Move interaction event handlers to class methods
This commit is contained in:
@@ -38,9 +38,6 @@ class DragRotate extends PointerInteraction {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
handleDownEvent: handleDownEvent,
|
||||
handleDragEvent: handleDragEvent,
|
||||
handleUpEvent: handleUpEvent,
|
||||
stopDown: FALSE
|
||||
});
|
||||
|
||||
@@ -64,73 +61,66 @@ class DragRotate extends PointerInteraction {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleDragEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @this {DragRotate}
|
||||
*/
|
||||
function handleDragEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const map = mapBrowserEvent.map;
|
||||
const view = map.getView();
|
||||
if (view.getConstraints().rotation === disable) {
|
||||
return;
|
||||
}
|
||||
const size = map.getSize();
|
||||
const offset = mapBrowserEvent.pixel;
|
||||
const theta =
|
||||
Math.atan2(size[1] / 2 - offset[1], offset[0] - size[0] / 2);
|
||||
if (this.lastAngle_ !== undefined) {
|
||||
const delta = theta - this.lastAngle_;
|
||||
const rotation = view.getRotation();
|
||||
rotateWithoutConstraints(view, rotation - delta);
|
||||
}
|
||||
this.lastAngle_ = theta;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @return {boolean} Stop drag sequence?
|
||||
* @this {DragRotate}
|
||||
*/
|
||||
function handleUpEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const map = mapBrowserEvent.map;
|
||||
const view = map.getView();
|
||||
view.setHint(ViewHint.INTERACTING, -1);
|
||||
const rotation = view.getRotation();
|
||||
rotate(view, rotation, undefined, this.duration_);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
|
||||
* @return {boolean} Start drag sequence?
|
||||
* @this {DragRotate}
|
||||
*/
|
||||
function handleDownEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mouseActionButton(mapBrowserEvent) && this.condition_(mapBrowserEvent)) {
|
||||
const map = mapBrowserEvent.map;
|
||||
map.getView().setHint(ViewHint.INTERACTING, 1);
|
||||
this.lastAngle_ = undefined;
|
||||
return true;
|
||||
} else {
|
||||
const view = map.getView();
|
||||
if (view.getConstraints().rotation === disable) {
|
||||
return;
|
||||
}
|
||||
const size = map.getSize();
|
||||
const offset = mapBrowserEvent.pixel;
|
||||
const theta =
|
||||
Math.atan2(size[1] / 2 - offset[1], offset[0] - size[0] / 2);
|
||||
if (this.lastAngle_ !== undefined) {
|
||||
const delta = theta - this.lastAngle_;
|
||||
const rotation = view.getRotation();
|
||||
rotateWithoutConstraints(view, rotation - delta);
|
||||
}
|
||||
this.lastAngle_ = theta;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleUpEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const map = mapBrowserEvent.map;
|
||||
const view = map.getView();
|
||||
view.setHint(ViewHint.INTERACTING, -1);
|
||||
const rotation = view.getRotation();
|
||||
rotate(view, rotation, undefined, this.duration_);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
handleDownEvent(mapBrowserEvent) {
|
||||
if (!mouseOnly(mapBrowserEvent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mouseActionButton(mapBrowserEvent) && this.condition_(mapBrowserEvent)) {
|
||||
const map = mapBrowserEvent.map;
|
||||
map.getView().setHint(ViewHint.INTERACTING, 1);
|
||||
this.lastAngle_ = undefined;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default DragRotate;
|
||||
|
||||
Reference in New Issue
Block a user