|
1 | 1 | import router from '../../router.ts'; |
| 2 | +import { ref, reactive, shallowRef, shallowReactive } from 'vue'; |
2 | 3 | import { Preferences } from '@capacitor/preferences'; |
3 | 4 | import * as terraDraw from 'terra-draw'; |
4 | 5 | import * as tilecover from '@mapbox/tile-cover'; |
@@ -46,12 +47,31 @@ export enum DrawToolMode { |
46 | 47 |
|
47 | 48 | export default class DrawTool { |
48 | 49 | private draw: terraDraw.TerraDraw; |
49 | | - public editing: COT | null; |
50 | 50 |
|
51 | | - public mode: DrawToolMode; |
| 51 | + // The DrawTool instance is stored with markRaw() in the map store, so any |
| 52 | + // state the UI renders must be individually reactive (refs/reactive objects) |
| 53 | + private _editing = shallowRef<COT | null>(null); |
| 54 | + |
| 55 | + private _mode = ref<DrawToolMode>(DrawToolMode.STATIC); |
52 | 56 |
|
53 | 57 | // Bumped on every TerraDraw change event to drive reactivity for canFinish |
54 | | - public _changeCount: number = 0; |
| 58 | + private _changeCount = ref(0); |
| 59 | + |
| 60 | + public get editing(): COT | null { |
| 61 | + return this._editing.value; |
| 62 | + } |
| 63 | + |
| 64 | + public set editing(cot: COT | null) { |
| 65 | + this._editing.value = cot; |
| 66 | + } |
| 67 | + |
| 68 | + public get mode(): DrawToolMode { |
| 69 | + return this._mode.value; |
| 70 | + } |
| 71 | + |
| 72 | + public set mode(mode: DrawToolMode) { |
| 73 | + this._mode.value = mode; |
| 74 | + } |
55 | 75 |
|
56 | 76 | public route: { |
57 | 77 | graph: Routing; |
@@ -79,7 +99,15 @@ export default class DrawTool { |
79 | 99 | overlay: string; |
80 | 100 | } |
81 | 101 |
|
82 | | - public snappingOptions: string[] = ['No Snapping']; |
| 102 | + private _snappingOptions = ref<string[]>(['No Snapping']); |
| 103 | + |
| 104 | + public get snappingOptions(): string[] { |
| 105 | + return this._snappingOptions.value; |
| 106 | + } |
| 107 | + |
| 108 | + public set snappingOptions(options: string[]) { |
| 109 | + this._snappingOptions.value = options; |
| 110 | + } |
83 | 111 |
|
84 | 112 | public get snappingLayer(): string { |
85 | 113 | return this.route.layer; |
@@ -114,7 +142,7 @@ export default class DrawTool { |
114 | 142 |
|
115 | 143 | public get canFinish(): boolean { |
116 | 144 | // Access _changeCount to establish reactivity |
117 | | - void this._changeCount; |
| 145 | + void this._changeCount.value; |
118 | 146 |
|
119 | 147 | if (this.mode === DrawToolMode.SELECT) { |
120 | 148 | return !!this.editing; |
@@ -200,14 +228,14 @@ export default class DrawTool { |
200 | 228 | routeFinder: finder |
201 | 229 | }) |
202 | 230 |
|
203 | | - this.route = { |
| 231 | + this.route = shallowReactive({ |
204 | 232 | finder, |
205 | 233 | graph, |
206 | 234 | tiles: new Map(), |
207 | 235 | zoom: 12, |
208 | 236 | layer: 'No Snapping', |
209 | 237 | definitions: new Map() |
210 | | - }; |
| 238 | + }); |
211 | 239 |
|
212 | 240 | const routeSnapMode = new TerraDrawRouteSnapMode({ |
213 | 241 | straightLineFallback: { |
@@ -453,21 +481,21 @@ export default class DrawTool { |
453 | 481 | }); |
454 | 482 |
|
455 | 483 | this.draw.on('change', () => { |
456 | | - this._changeCount++; |
| 484 | + this._changeCount.value++; |
457 | 485 | }); |
458 | 486 |
|
459 | 487 | this.mode = DrawToolMode.STATIC; |
460 | 488 | this.snapping = new Set(); |
461 | 489 | this.editing = null; |
462 | 490 |
|
463 | | - this.point = { |
| 491 | + this.point = reactive({ |
464 | 492 | type: this.mapStore.defaultPointType |
465 | | - } |
| 493 | + }) |
466 | 494 |
|
467 | | - this.lasso = { |
| 495 | + this.lasso = reactive({ |
468 | 496 | loading: false, |
469 | 497 | overlay: 'Map Features' |
470 | | - } |
| 498 | + }) |
471 | 499 | } |
472 | 500 |
|
473 | 501 | async populateSnappingLayers(): Promise<void> { |
|
0 commit comments