From 171dec15e8e8ec2af98c40312c7cd9c3a9450715 Mon Sep 17 00:00:00 2001 From: till_schuetze Date: Fri, 15 Nov 2024 11:12:21 +0100 Subject: [PATCH] Fix: Clear timeout if it exists as we are now dealing with a double click event --- ui/src/draw/CesiumDraw.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ui/src/draw/CesiumDraw.ts b/ui/src/draw/CesiumDraw.ts index 4d09dedae..0c75b8b11 100644 --- a/ui/src/draw/CesiumDraw.ts +++ b/ui/src/draw/CesiumDraw.ts @@ -74,7 +74,7 @@ export class CesiumDraw extends EventTarget { private leftPressedPixel_: Cartesian2 | undefined; private sketchPoints_: Entity[] = []; private isDoubleClick = false; - private singleClickTimer; + private singleClickTimer: NodeJS.Timeout | null = null; private segmentsInfo: SegmentInfo[] = []; type: GeometryTypes | undefined; julianDate = new JulianDate(); @@ -462,11 +462,17 @@ export class CesiumDraw extends EventTarget { this.finishDrawing(); } else if (this.type === 'line') { if (!this.isDoubleClick) { - this.singleClickTimer = setTimeout(() => { - this.isDoubleClick = false; - const prevPoint = Cartesian3.clone(this.activePoints_[this.activePoints_.length - 1]); - this.sketchPoints_.push(this.createSketchPoint_(prevPoint)); - }, 250); + if (this.singleClickTimer) { + clearTimeout(this.singleClickTimer); + this.singleClickTimer = null; + } else { + this.singleClickTimer = setTimeout(() => { + this.isDoubleClick = false; + const prevPoint = Cartesian3.clone(this.activePoints_[this.activePoints_.length - 1]); + this.sketchPoints_.push(this.createSketchPoint_(prevPoint)); + this.singleClickTimer = null; + }, 250); + } } } } @@ -616,7 +622,9 @@ export class CesiumDraw extends EventTarget { onDoubleClick_() { this.isDoubleClick = true; - clearTimeout(this.singleClickTimer); + if (this.singleClickTimer) { + clearTimeout(this.singleClickTimer); + } if (!this.activeDistances_.includes(this.activeDistance_)) { this.activeDistances_.push(this.activeDistance_); }