Skip to content

Commit 109522b

Browse files
poc(map): fix map
1 parent e99c68c commit 109522b

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

assets/controllers/draw_map_controller.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,27 @@ export default class extends Controller {
213213
// --- Private: mode management ---
214214

215215
#toggleMode(mode) {
216+
if (this.#isDrawing) {
217+
this.#cancelCurrentDrawing();
218+
}
219+
216220
this.#currentMode = this.#currentMode === mode ? null : mode;
217221
this.#updateButtonClasses();
218222
}
219223

224+
#cancelCurrentDrawing() {
225+
if (this.#currentMode === 'road-line') {
226+
this.#draw.waypoints = [];
227+
this.#draw.routedSegments = [];
228+
}
229+
230+
this.#isDrawing = false;
231+
this.#draw.currentCoordinates = [];
232+
this.#draw.clearPreview();
233+
this.#map.dragPan.enable();
234+
this.#setCursor('');
235+
}
236+
220237
#updateButtonClasses() {
221238
this.polygonBtnTarget?.classList.toggle('active', this.#currentMode === 'polygon');
222239
this.lineBtnTarget?.classList.toggle('active', this.#currentMode === 'line');
@@ -306,16 +323,7 @@ export default class extends Controller {
306323
return;
307324
}
308325

309-
if (this.#currentMode === 'road-line') {
310-
this.#draw.waypoints = [];
311-
this.#draw.routedSegments = [];
312-
}
313-
314-
this.#isDrawing = false;
315-
this.#draw.currentCoordinates = [];
316-
this.#draw.clearPreview();
317-
this.#map.dragPan.enable();
318-
this.#setCursor('');
326+
this.#cancelCurrentDrawing();
319327
}
320328

321329
// --- Private: finalize & geometry ---

0 commit comments

Comments
 (0)