Skip to content

Commit

Permalink
Add set position on single click, fixes #1675
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jun 5, 2024
1 parent 803bdf8 commit 35cd0cb
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions src/tools/zoomPan.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export class ZoomAndPan {
*/
#startPoint;

/**
* Move flag: true if mouse or touch move.
*
* @type {boolean}
*/
#hasMoved;

/**
* Line between input points.
*
Expand Down Expand Up @@ -84,6 +91,7 @@ export class ZoomAndPan {
#start(point) {
this.#started = true;
this.#startPoint = point;
this.#hasMoved = false;
}

/**
Expand All @@ -94,6 +102,7 @@ export class ZoomAndPan {
#twoTouchStart = (points) => {
this.#started = true;
this.#startPoint = points[0];
this.#hasMoved = false;
// points line
this.#pointsLine = new Line(points[0], points[1]);
this.#midPoint = this.#pointsLine.getMidpoint();
Expand All @@ -109,6 +118,7 @@ export class ZoomAndPan {
if (!this.#started) {
return;
}
this.#hasMoved = true;

// calculate translation
const tx = point.getX() - this.#startPoint.getX();
Expand Down Expand Up @@ -144,6 +154,7 @@ export class ZoomAndPan {
if (!this.#started) {
return;
}
this.#hasMoved = true;

const newLine = new Line(points[0], points[1]);
const lineRatio = newLine.getLength() / this.#pointsLine.getLength();
Expand Down Expand Up @@ -187,6 +198,21 @@ export class ZoomAndPan {
}
};

/**
* Set the current position.
*
* @param {Point2D} point The update point.
* @param {string} divId The layer group divId.
*/
#setCurrentPosition(point, divId) {
const layerGroup = this.#app.getLayerGroupByDivId(divId);
const viewLayer = layerGroup.getActiveViewLayer();
const viewController = viewLayer.getViewController();
const planePos = viewLayer.displayToPlanePos(point);
const position = viewController.getPositionFromPlanePoint(planePos);
viewController.setCurrentPosition(position);
}

/**
* Finish tool interaction.
*/
Expand Down Expand Up @@ -220,9 +246,15 @@ export class ZoomAndPan {
/**
* Handle mouse up event.
*
* @param {object} _event The mouse up event.
* @param {object} event The mouse up event.
*/
mouseup = (_event) => {
mouseup = (event) => {
// update position if no move
if (!this.#hasMoved) {
const mousePoint = getMousePoint(event);
const layerDetails = getLayerDetailsFromEvent(event);
this.#setCurrentPosition(mousePoint, layerDetails.groupDivId);
}
this.#finish();
};

Expand Down Expand Up @@ -267,9 +299,15 @@ export class ZoomAndPan {
/**
* Handle touch end event.
*
* @param {object} _event The touch end event.
* @param {object} event The touch end event.
*/
touchend = (_event) => {
touchend = (event) => {
// update position if no move
if (!this.#hasMoved) {
const mousePoint = getMousePoint(event);
const layerDetails = getLayerDetailsFromEvent(event);
this.#setCurrentPosition(mousePoint, layerDetails.groupDivId);
}
this.#finish();
};

Expand Down

0 comments on commit 35cd0cb

Please sign in to comment.