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_); }