From 35cd0cb173190679c30fab0c5bc3485ab59121a3 Mon Sep 17 00:00:00 2001 From: ivmartel Date: Wed, 5 Jun 2024 11:23:54 +0200 Subject: [PATCH] Add set position on single click, fixes #1675 --- src/tools/zoomPan.js | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/tools/zoomPan.js b/src/tools/zoomPan.js index c72fb49283..de41dd9deb 100644 --- a/src/tools/zoomPan.js +++ b/src/tools/zoomPan.js @@ -55,6 +55,13 @@ export class ZoomAndPan { */ #startPoint; + /** + * Move flag: true if mouse or touch move. + * + * @type {boolean} + */ + #hasMoved; + /** * Line between input points. * @@ -84,6 +91,7 @@ export class ZoomAndPan { #start(point) { this.#started = true; this.#startPoint = point; + this.#hasMoved = false; } /** @@ -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(); @@ -109,6 +118,7 @@ export class ZoomAndPan { if (!this.#started) { return; } + this.#hasMoved = true; // calculate translation const tx = point.getX() - this.#startPoint.getX(); @@ -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(); @@ -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. */ @@ -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(); }; @@ -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(); };