Skip to content

Commit 687384a

Browse files
authored
Merge pull request #1593 from dfpc-coe/reactive-draw-tools
Reactive Draw Tool State
2 parents 56bcf1b + f42ffd8 commit 687384a

3 files changed

Lines changed: 49 additions & 15 deletions

File tree

api/web/src/stores/modules/draw.ts

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import router from '../../router.ts';
2+
import { ref, reactive, shallowRef, shallowReactive } from 'vue';
23
import { Preferences } from '@capacitor/preferences';
34
import * as terraDraw from 'terra-draw';
45
import * as tilecover from '@mapbox/tile-cover';
@@ -46,12 +47,31 @@ export enum DrawToolMode {
4647

4748
export default class DrawTool {
4849
private draw: terraDraw.TerraDraw;
49-
public editing: COT | null;
5050

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);
5256

5357
// 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+
}
5575

5676
public route: {
5777
graph: Routing;
@@ -79,7 +99,15 @@ export default class DrawTool {
7999
overlay: string;
80100
}
81101

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+
}
83111

84112
public get snappingLayer(): string {
85113
return this.route.layer;
@@ -114,7 +142,7 @@ export default class DrawTool {
114142

115143
public get canFinish(): boolean {
116144
// Access _changeCount to establish reactivity
117-
void this._changeCount;
145+
void this._changeCount.value;
118146

119147
if (this.mode === DrawToolMode.SELECT) {
120148
return !!this.editing;
@@ -200,14 +228,14 @@ export default class DrawTool {
200228
routeFinder: finder
201229
})
202230

203-
this.route = {
231+
this.route = shallowReactive({
204232
finder,
205233
graph,
206234
tiles: new Map(),
207235
zoom: 12,
208236
layer: 'No Snapping',
209237
definitions: new Map()
210-
};
238+
});
211239

212240
const routeSnapMode = new TerraDrawRouteSnapMode({
213241
straightLineFallback: {
@@ -453,21 +481,21 @@ export default class DrawTool {
453481
});
454482

455483
this.draw.on('change', () => {
456-
this._changeCount++;
484+
this._changeCount.value++;
457485
});
458486

459487
this.mode = DrawToolMode.STATIC;
460488
this.snapping = new Set();
461489
this.editing = null;
462490

463-
this.point = {
491+
this.point = reactive({
464492
type: this.mapStore.defaultPointType
465-
}
493+
})
466494

467-
this.lasso = {
495+
this.lasso = reactive({
468496
loading: false,
469497
overlay: 'Map Features'
470-
}
498+
})
471499
}
472500

473501
async populateSnappingLayers(): Promise<void> {

bin/version.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const pkg_root = JSON.parse(String(await fs.readFile(new URL('../package.json',
88
const pkg_api = JSON.parse(String(await fs.readFile(new URL('../api/package.json', import.meta.url))));
99
const pkg_web = JSON.parse(String(await fs.readFile(new URL('../api/web/package.json', import.meta.url))));
1010
const capacitor = JSON.parse(String(await fs.readFile(new URL('../capacitor.config.json', import.meta.url))));
11+
const xcodeproj = String(await fs.readFile(new URL('../ios/App/App.xcodeproj/project.pbxproj', import.meta.url)));
1112

1213
console.error('ok version - ' + pkg_root.version);
1314

@@ -18,12 +19,17 @@ capacitor.plugins.CapacitorUpdater.version = pkg_root.version;
1819
const updated = [
1920
new URL('../api/package.json', import.meta.url),
2021
new URL('../api/web/package.json', import.meta.url),
21-
new URL('../capacitor.config.json', import.meta.url)
22+
new URL('../capacitor.config.json', import.meta.url),
23+
new URL('../ios/App/App.xcodeproj/project.pbxproj', import.meta.url)
2224
];
2325

2426
await fs.writeFile(updated[0], JSON.stringify(pkg_api, null, 4));
2527
await fs.writeFile(updated[1], JSON.stringify(pkg_web, null, 4));
2628
await fs.writeFile(updated[2], JSON.stringify(capacitor, null, 4));
29+
await fs.writeFile(updated[3], xcodeproj.replace(
30+
/MARKETING_VERSION = [^;]+;/g,
31+
`MARKETING_VERSION = ${pkg_root.version};`
32+
));
2733

2834
console.error('ok saved');
2935

ios/App/App.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
"$(inherited)",
335335
"@executable_path/Frameworks",
336336
);
337-
MARKETING_VERSION = 13.50.0;
337+
MARKETING_VERSION = 13.52.0;
338338
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
339339
PRODUCT_BUNDLE_IDENTIFIER = io.cloudtak.app;
340340
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -360,7 +360,7 @@
360360
"$(inherited)",
361361
"@executable_path/Frameworks",
362362
);
363-
MARKETING_VERSION = 13.50.0;
363+
MARKETING_VERSION = 13.52.0;
364364
PRODUCT_BUNDLE_IDENTIFIER = io.cloudtak.app;
365365
PRODUCT_NAME = "$(TARGET_NAME)";
366366
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";

0 commit comments

Comments
 (0)