@trackunit/react-map-draw 0.0.0-stage → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +191 -0
- package/README.md +44 -2
- package/index.cjs.js +226 -0
- package/index.d.ts +1 -0
- package/index.esm.js +218 -0
- package/migrations/entry.js +3 -0
- package/migrations.json +3 -0
- package/package.json +19 -3
- package/src/DrawController.d.ts +52 -0
- package/src/drawEngine.d.ts +25 -0
- package/src/drawStyle.d.ts +23 -0
- package/src/drawValue.d.ts +22 -0
- package/src/index.d.ts +5 -0
- package/src/loadTerraDrawEngine.d.ts +18 -0
- package/src/terraDrawEngine.d.ts +11 -0
- package/src/testing/FakeTerraDrawAdapter.d.ts +47 -0
- package/src/testing/drawPortContract.d.ts +11 -0
- package/terraDrawEngine.cjs.js +277 -0
- package/terraDrawEngine.esm.js +275 -0
package/index.esm.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { EMPTY_DRAW_VALUE } from '@trackunit/react-map-adapter-shared';
|
|
2
|
+
import { geoJsonPolygonSchema } from '@trackunit/geo-json-utils';
|
|
3
|
+
import { isEqual } from 'es-toolkit';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A feature the drawing engine can hold: a valid, closed `Polygon` with exactly one
|
|
7
|
+
* ring. Sites have no holes (SAGA-196 decision), so inner rings are rejected rather
|
|
8
|
+
* than silently dropped.
|
|
9
|
+
*/
|
|
10
|
+
const isDrawablePolygonFeature = (feature) => {
|
|
11
|
+
const geometry = feature.geometry;
|
|
12
|
+
if (geometry === null || geometry.type !== "Polygon")
|
|
13
|
+
return false;
|
|
14
|
+
if (geometry.coordinates.length !== 1)
|
|
15
|
+
return false;
|
|
16
|
+
return geoJsonPolygonSchema.safeParse(geometry).success;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Keeps only drawable polygon features. Returns the input reference when nothing
|
|
20
|
+
* was dropped so controlled-input round trips keep identity, and the shared
|
|
21
|
+
* `EMPTY_DRAW_VALUE` when nothing remains.
|
|
22
|
+
*/
|
|
23
|
+
const normalizeDrawValue = (value) => {
|
|
24
|
+
const features = value.features.filter(isDrawablePolygonFeature);
|
|
25
|
+
if (features.length === 0)
|
|
26
|
+
return EMPTY_DRAW_VALUE;
|
|
27
|
+
if (features.length === value.features.length)
|
|
28
|
+
return value;
|
|
29
|
+
return { type: "FeatureCollection", features };
|
|
30
|
+
};
|
|
31
|
+
/** Full feature equality (ids, properties and geometry). Used for controlled-input updates. */
|
|
32
|
+
const drawValuesIdentical = (a, b) => a === b || isEqual(a.features, b.features);
|
|
33
|
+
/**
|
|
34
|
+
* Geometry-only equality. Ids and properties are ignored because the engine assigns
|
|
35
|
+
* its own ids and bookkeeping properties; two drawings are "the same" when their
|
|
36
|
+
* polygons have the same rings in the same order.
|
|
37
|
+
*/
|
|
38
|
+
const drawValuesEqual = (a, b) => {
|
|
39
|
+
if (a === b)
|
|
40
|
+
return true;
|
|
41
|
+
if (a.features.length !== b.features.length)
|
|
42
|
+
return false;
|
|
43
|
+
return isEqual(a.features.map(feature => feature.geometry), b.features.map(feature => feature.geometry));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Provider-agnostic `DrawPort` implementation (ADR 0030).
|
|
48
|
+
*
|
|
49
|
+
* The controller is the source of truth for `mode` and `value`. It owns no native
|
|
50
|
+
* resources itself: adapters call `connect(loader)` whenever they have a native map
|
|
51
|
+
* to draw on (first connect, and again after every recreation or style reload) and
|
|
52
|
+
* `disconnect()` when the native map goes away. The engine is created lazily, only
|
|
53
|
+
* once the drawing needs one (non-idle mode or a non-empty value), so maps that never
|
|
54
|
+
* draw never load Terra Draw.
|
|
55
|
+
*/
|
|
56
|
+
class DrawController {
|
|
57
|
+
constructor(options = {}) {
|
|
58
|
+
this.options = options;
|
|
59
|
+
this.mode = "idle";
|
|
60
|
+
this.value = EMPTY_DRAW_VALUE;
|
|
61
|
+
this.listeners = new Set();
|
|
62
|
+
this.loader = null;
|
|
63
|
+
this.engine = null;
|
|
64
|
+
this.engineUnsubscribe = null;
|
|
65
|
+
/** Incremented on every connect/disconnect so a slow loader cannot attach a stale engine. */
|
|
66
|
+
this.generation = 0;
|
|
67
|
+
this.loading = false;
|
|
68
|
+
}
|
|
69
|
+
// ---- Adapter lifecycle ----
|
|
70
|
+
/**
|
|
71
|
+
* Bind to a native map. Destroys any previous engine and, if the current mode or
|
|
72
|
+
* value needs one, builds a fresh engine from the committed value.
|
|
73
|
+
*/
|
|
74
|
+
connect(loader) {
|
|
75
|
+
this.releaseEngine();
|
|
76
|
+
this.loader = loader;
|
|
77
|
+
this.ensureEngine();
|
|
78
|
+
}
|
|
79
|
+
/** Unbind from the native map. Mode and value are kept for the next `connect`. */
|
|
80
|
+
disconnect() {
|
|
81
|
+
this.releaseEngine();
|
|
82
|
+
this.loader = null;
|
|
83
|
+
}
|
|
84
|
+
/** True between `connect` and `disconnect`, whether or not an engine has been loaded yet. */
|
|
85
|
+
isConnected() {
|
|
86
|
+
return this.loader !== null;
|
|
87
|
+
}
|
|
88
|
+
// ---- DrawPort ----
|
|
89
|
+
setMode(mode) {
|
|
90
|
+
if (this.mode === mode)
|
|
91
|
+
return;
|
|
92
|
+
this.mode = mode;
|
|
93
|
+
this.notify();
|
|
94
|
+
if (this.engine !== null) {
|
|
95
|
+
this.engine.setMode(mode);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.ensureEngine();
|
|
99
|
+
}
|
|
100
|
+
setValue(value) {
|
|
101
|
+
const normalized = normalizeDrawValue(value);
|
|
102
|
+
// Full comparison here: a consumer may legitimately re-label ids or properties
|
|
103
|
+
// without touching geometry. Engine echoes are filtered geometry-only below.
|
|
104
|
+
if (drawValuesIdentical(this.value, normalized))
|
|
105
|
+
return;
|
|
106
|
+
const sameGeometry = drawValuesEqual(this.value, normalized);
|
|
107
|
+
this.value = normalized;
|
|
108
|
+
this.notify();
|
|
109
|
+
// The engine renders geometry only. A value that merely re-labels ids or
|
|
110
|
+
// properties (a consumer round-tripping through form state) must not clear and
|
|
111
|
+
// redraw the store, which would drop the selection or interrupt a drag.
|
|
112
|
+
if (sameGeometry)
|
|
113
|
+
return;
|
|
114
|
+
if (this.engine !== null) {
|
|
115
|
+
this.engine.setValue(normalized);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this.ensureEngine();
|
|
119
|
+
}
|
|
120
|
+
getMode() {
|
|
121
|
+
return this.mode;
|
|
122
|
+
}
|
|
123
|
+
getValue() {
|
|
124
|
+
return this.value;
|
|
125
|
+
}
|
|
126
|
+
subscribe(listener) {
|
|
127
|
+
this.listeners.add(listener);
|
|
128
|
+
return () => {
|
|
129
|
+
this.listeners.delete(listener);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// ---- Internals ----
|
|
133
|
+
needsEngine() {
|
|
134
|
+
return this.mode !== "idle" || this.value.features.length > 0;
|
|
135
|
+
}
|
|
136
|
+
ensureEngine() {
|
|
137
|
+
const loader = this.loader;
|
|
138
|
+
if (loader === null || this.engine !== null || this.loading || !this.needsEngine())
|
|
139
|
+
return;
|
|
140
|
+
const generation = this.generation;
|
|
141
|
+
this.loading = true;
|
|
142
|
+
// Promise.resolve().then(loader) also routes a synchronously throwing loader
|
|
143
|
+
// into the rejection path, so `loading` never sticks.
|
|
144
|
+
Promise.resolve()
|
|
145
|
+
.then(loader)
|
|
146
|
+
.then(engine => {
|
|
147
|
+
if (generation !== this.generation) {
|
|
148
|
+
// connect/disconnect happened while loading: this engine targets a dead map
|
|
149
|
+
engine.destroy();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this.loading = false;
|
|
153
|
+
this.attachEngine(engine);
|
|
154
|
+
}, (error) => {
|
|
155
|
+
if (generation !== this.generation)
|
|
156
|
+
return;
|
|
157
|
+
this.loading = false;
|
|
158
|
+
this.options.onEngineError?.(error);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
attachEngine(engine) {
|
|
162
|
+
this.engine = engine;
|
|
163
|
+
this.engineUnsubscribe = engine.onChange(value => {
|
|
164
|
+
if (drawValuesEqual(this.value, value))
|
|
165
|
+
return;
|
|
166
|
+
this.value = value;
|
|
167
|
+
// Select mode has nothing left to select once the last polygon is deleted,
|
|
168
|
+
// so drop back to idle instead of leaving the map in a dead drawing mode.
|
|
169
|
+
if (value.features.length === 0 && this.mode === "select") {
|
|
170
|
+
this.mode = "idle";
|
|
171
|
+
engine.setMode("idle");
|
|
172
|
+
}
|
|
173
|
+
this.notify();
|
|
174
|
+
});
|
|
175
|
+
engine.setValue(this.value);
|
|
176
|
+
engine.setMode(this.mode);
|
|
177
|
+
}
|
|
178
|
+
releaseEngine() {
|
|
179
|
+
this.generation += 1;
|
|
180
|
+
this.loading = false;
|
|
181
|
+
this.engineUnsubscribe?.();
|
|
182
|
+
this.engineUnsubscribe = null;
|
|
183
|
+
this.engine?.destroy();
|
|
184
|
+
this.engine = null;
|
|
185
|
+
}
|
|
186
|
+
notify() {
|
|
187
|
+
this.listeners.forEach(listener => listener());
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Decimal places kept in the Terra Draw store and demanded by its provider
|
|
193
|
+
* adapters. One constant for the engine and every bridge: Terra Draw rejects a
|
|
194
|
+
* feature whose coordinates carry more decimals than the adapter's precision.
|
|
195
|
+
*/
|
|
196
|
+
const DRAW_COORDINATE_PRECISION = 9;
|
|
197
|
+
const DEFAULT_DRAW_STYLE = {
|
|
198
|
+
fillColor: "#2563eb",
|
|
199
|
+
fillOpacity: 0.2,
|
|
200
|
+
outlineColor: "#2563eb",
|
|
201
|
+
outlineWidth: 2,
|
|
202
|
+
vertexColor: "#ffffff",
|
|
203
|
+
vertexOutlineColor: "#2563eb",
|
|
204
|
+
vertexWidth: 5,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Dynamic-imports Terra Draw and creates a `DrawEngine` on the given provider
|
|
209
|
+
* adapter. This is the only runtime entry into Terra Draw; everything reachable
|
|
210
|
+
* from the package index is type-only, so consumers that never draw never download
|
|
211
|
+
* the engine (same route as deck.gl in the Google adapter, ADR 0030).
|
|
212
|
+
*/
|
|
213
|
+
const loadTerraDrawEngine = async (options) => {
|
|
214
|
+
const { createTerraDrawEngine } = await import('./terraDrawEngine.esm.js');
|
|
215
|
+
return createTerraDrawEngine(options);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export { DEFAULT_DRAW_STYLE, DRAW_COORDINATE_PRECISION, DrawController, drawValuesEqual, isDrawablePolygonFeature, loadTerraDrawEngine, normalizeDrawValue };
|
package/migrations.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-map-draw",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"repository": "https://github.com/Trackunit/manager",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=24.x"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@trackunit/react-map-adapter-shared": "0.0.165",
|
|
11
|
+
"@trackunit/geo-json-utils": "1.20.0",
|
|
12
|
+
"es-toolkit": "^1.52.0",
|
|
13
|
+
"terra-draw": "^1.36.0"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": "^19.0.0"
|
|
17
|
+
},
|
|
18
|
+
"migrations": "./migrations.json",
|
|
19
|
+
"module": "./index.esm.js",
|
|
20
|
+
"main": "./index.cjs.js",
|
|
21
|
+
"types": "./index.d.ts"
|
|
6
22
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type DrawMode, type DrawPort, type DrawValue } from "@trackunit/react-map-adapter-shared";
|
|
2
|
+
import type { DrawEngineLoader } from "./drawEngine";
|
|
3
|
+
export type DrawControllerOptions = Readonly<{
|
|
4
|
+
/**
|
|
5
|
+
* Called when the engine loader rejects (for example the dynamic import failed).
|
|
6
|
+
* The controller keeps its mode and value and loads again on the next `connect`,
|
|
7
|
+
* `setMode` or `setValue` that needs an engine.
|
|
8
|
+
*/
|
|
9
|
+
onEngineError?: (error: unknown) => void;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Provider-agnostic `DrawPort` implementation (ADR 0030).
|
|
13
|
+
*
|
|
14
|
+
* The controller is the source of truth for `mode` and `value`. It owns no native
|
|
15
|
+
* resources itself: adapters call `connect(loader)` whenever they have a native map
|
|
16
|
+
* to draw on (first connect, and again after every recreation or style reload) and
|
|
17
|
+
* `disconnect()` when the native map goes away. The engine is created lazily, only
|
|
18
|
+
* once the drawing needs one (non-idle mode or a non-empty value), so maps that never
|
|
19
|
+
* draw never load Terra Draw.
|
|
20
|
+
*/
|
|
21
|
+
export declare class DrawController implements DrawPort {
|
|
22
|
+
private readonly options;
|
|
23
|
+
private mode;
|
|
24
|
+
private value;
|
|
25
|
+
private readonly listeners;
|
|
26
|
+
private loader;
|
|
27
|
+
private engine;
|
|
28
|
+
private engineUnsubscribe;
|
|
29
|
+
/** Incremented on every connect/disconnect so a slow loader cannot attach a stale engine. */
|
|
30
|
+
private generation;
|
|
31
|
+
private loading;
|
|
32
|
+
constructor(options?: DrawControllerOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Bind to a native map. Destroys any previous engine and, if the current mode or
|
|
35
|
+
* value needs one, builds a fresh engine from the committed value.
|
|
36
|
+
*/
|
|
37
|
+
connect(loader: DrawEngineLoader): void;
|
|
38
|
+
/** Unbind from the native map. Mode and value are kept for the next `connect`. */
|
|
39
|
+
disconnect(): void;
|
|
40
|
+
/** True between `connect` and `disconnect`, whether or not an engine has been loaded yet. */
|
|
41
|
+
isConnected(): boolean;
|
|
42
|
+
setMode(mode: DrawMode): void;
|
|
43
|
+
setValue(value: DrawValue): void;
|
|
44
|
+
getMode(): DrawMode;
|
|
45
|
+
getValue(): DrawValue;
|
|
46
|
+
subscribe(listener: () => void): () => void;
|
|
47
|
+
private needsEngine;
|
|
48
|
+
private ensureEngine;
|
|
49
|
+
private attachEngine;
|
|
50
|
+
private releaseEngine;
|
|
51
|
+
private notify;
|
|
52
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DrawMode, DrawValue } from "@trackunit/react-map-adapter-shared";
|
|
2
|
+
/**
|
|
3
|
+
* The provider-bound half of the drawing capability. One engine instance is bound to
|
|
4
|
+
* one native map instance (or one Mapbox style); the `DrawController` creates a new
|
|
5
|
+
* engine through the loader on every reconnect and destroys the previous one.
|
|
6
|
+
*/
|
|
7
|
+
export type DrawEngine = Readonly<{
|
|
8
|
+
/** Apply a mode. Called after `setValue` on a fresh engine. */
|
|
9
|
+
setMode: (mode: DrawMode) => void;
|
|
10
|
+
/** Replace all rendered polygons with the given committed value. */
|
|
11
|
+
setValue: (value: DrawValue) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Called when the user finishes, edits or deletes a polygon. The engine must not
|
|
14
|
+
* echo values it received through `setValue`.
|
|
15
|
+
*/
|
|
16
|
+
onChange: (listener: (value: DrawValue) => void) => () => void;
|
|
17
|
+
/** Release the engine's native resources. Safe to call when the native map is gone. */
|
|
18
|
+
destroy: () => void;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an engine bound to the adapter's current native map. Adapters build one
|
|
22
|
+
* loader per native map instance and hand it to `DrawController.connect`; the
|
|
23
|
+
* controller invokes it lazily, the first time the drawing actually needs an engine.
|
|
24
|
+
*/
|
|
25
|
+
export type DrawEngineLoader = () => Promise<DrawEngine>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decimal places kept in the Terra Draw store and demanded by its provider
|
|
3
|
+
* adapters. One constant for the engine and every bridge: Terra Draw rejects a
|
|
4
|
+
* feature whose coordinates carry more decimals than the adapter's precision.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DRAW_COORDINATE_PRECISION = 9;
|
|
7
|
+
/**
|
|
8
|
+
* Visual style of drawn polygons and their handles. Hex colours only, because
|
|
9
|
+
* Terra Draw styles every provider from the same hex values.
|
|
10
|
+
*
|
|
11
|
+
* Defaults follow the Trackunit `PRIMARY` 600 token (#2563eb). Styling parity with
|
|
12
|
+
* `useShapes` polygons is an open item for milestone 1 (ADR 0030).
|
|
13
|
+
*/
|
|
14
|
+
export type DrawStyle = Readonly<{
|
|
15
|
+
fillColor: `#${string}`;
|
|
16
|
+
fillOpacity: number;
|
|
17
|
+
outlineColor: `#${string}`;
|
|
18
|
+
outlineWidth: number;
|
|
19
|
+
vertexColor: `#${string}`;
|
|
20
|
+
vertexOutlineColor: `#${string}`;
|
|
21
|
+
vertexWidth: number;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const DEFAULT_DRAW_STYLE: DrawStyle;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type GeoJsonFeature } from "@trackunit/geo-json-utils";
|
|
2
|
+
import { type DrawValue } from "@trackunit/react-map-adapter-shared";
|
|
3
|
+
/**
|
|
4
|
+
* A feature the drawing engine can hold: a valid, closed `Polygon` with exactly one
|
|
5
|
+
* ring. Sites have no holes (SAGA-196 decision), so inner rings are rejected rather
|
|
6
|
+
* than silently dropped.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isDrawablePolygonFeature: (feature: GeoJsonFeature) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Keeps only drawable polygon features. Returns the input reference when nothing
|
|
11
|
+
* was dropped so controlled-input round trips keep identity, and the shared
|
|
12
|
+
* `EMPTY_DRAW_VALUE` when nothing remains.
|
|
13
|
+
*/
|
|
14
|
+
export declare const normalizeDrawValue: (value: DrawValue) => DrawValue;
|
|
15
|
+
/** Full feature equality (ids, properties and geometry). Used for controlled-input updates. */
|
|
16
|
+
export declare const drawValuesIdentical: (a: DrawValue, b: DrawValue) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Geometry-only equality. Ids and properties are ignored because the engine assigns
|
|
19
|
+
* its own ids and bookkeeping properties; two drawings are "the same" when their
|
|
20
|
+
* polygons have the same rings in the same order.
|
|
21
|
+
*/
|
|
22
|
+
export declare const drawValuesEqual: (a: DrawValue, b: DrawValue) => boolean;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DrawController, type DrawControllerOptions } from "./DrawController";
|
|
2
|
+
export type { DrawEngine, DrawEngineLoader } from "./drawEngine";
|
|
3
|
+
export { DEFAULT_DRAW_STYLE, DRAW_COORDINATE_PRECISION, type DrawStyle } from "./drawStyle";
|
|
4
|
+
export { drawValuesEqual, isDrawablePolygonFeature, normalizeDrawValue } from "./drawValue";
|
|
5
|
+
export { loadTerraDrawEngine, type TerraDrawEngineOptions, type TerraDrawProviderAdapter } from "./loadTerraDrawEngine";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TerraDrawExtend } from "terra-draw";
|
|
2
|
+
import type { DrawEngine } from "./drawEngine";
|
|
3
|
+
import type { DrawStyle } from "./drawStyle";
|
|
4
|
+
/** A Terra Draw provider adapter (for example `TerraDrawGoogleMapsAdapter`). Type-only import, erased at runtime. */
|
|
5
|
+
export type TerraDrawProviderAdapter = TerraDrawExtend.TerraDrawBaseAdapter;
|
|
6
|
+
export type TerraDrawEngineOptions = Readonly<{
|
|
7
|
+
/** Provider adapter built by the map adapter from its native map object. */
|
|
8
|
+
adapter: TerraDrawProviderAdapter;
|
|
9
|
+
/** Visual overrides for the drawn polygons and their handles. */
|
|
10
|
+
style?: Partial<DrawStyle>;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Dynamic-imports Terra Draw and creates a `DrawEngine` on the given provider
|
|
14
|
+
* adapter. This is the only runtime entry into Terra Draw; everything reachable
|
|
15
|
+
* from the package index is type-only, so consumers that never draw never download
|
|
16
|
+
* the engine (same route as deck.gl in the Google adapter, ADR 0030).
|
|
17
|
+
*/
|
|
18
|
+
export declare const loadTerraDrawEngine: (options: TerraDrawEngineOptions) => Promise<DrawEngine>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DrawEngine } from "./drawEngine";
|
|
2
|
+
import type { TerraDrawEngineOptions } from "./loadTerraDrawEngine";
|
|
3
|
+
/**
|
|
4
|
+
* Creates the Terra Draw backed `DrawEngine`. One instance per native map: the
|
|
5
|
+
* `DrawController` destroys it and creates a new one on every reconnect.
|
|
6
|
+
*
|
|
7
|
+
* Mode and value may be applied before the provider adapter reports `ready`
|
|
8
|
+
* (Google Maps reports it asynchronously, once its overlay is attached); they are
|
|
9
|
+
* queued and applied in order when it fires.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createTerraDrawEngine: ({ adapter, style }: TerraDrawEngineOptions) => DrawEngine;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TerraDrawExtend, type TerraDrawChanges } from "terra-draw";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal Terra Draw provider adapter for unit tests.
|
|
4
|
+
*
|
|
5
|
+
* Projection is the identity (lng = x, lat = y), `register` reports ready at once,
|
|
6
|
+
* and `render` records every change set so specs can assert what Terra Draw asked
|
|
7
|
+
* the provider to draw. `click`/`move` drive the active mode through the same
|
|
8
|
+
* callbacks a real adapter uses for pointer events, without DOM events; `rightClick`
|
|
9
|
+
* and `dragStart`/`drag`/`dragEnd` do the same for vertex deletion and dragging.
|
|
10
|
+
*/
|
|
11
|
+
export declare class FakeTerraDrawAdapter extends TerraDrawExtend.TerraDrawBaseAdapter {
|
|
12
|
+
readonly element: HTMLDivElement;
|
|
13
|
+
readonly renders: Array<TerraDrawChanges>;
|
|
14
|
+
readonly cursors: Array<string>;
|
|
15
|
+
registered: boolean;
|
|
16
|
+
cleared: number;
|
|
17
|
+
constructor();
|
|
18
|
+
register(callbacks: TerraDrawExtend.TerraDrawCallbacks): void;
|
|
19
|
+
unregister(): void;
|
|
20
|
+
click(lng: number, lat: number): void;
|
|
21
|
+
move(lng: number, lat: number): void;
|
|
22
|
+
rightClick(lng: number, lat: number): void;
|
|
23
|
+
/** Drag a vertex: `dragStart` at the vertex, `drag` per frame, `dragEnd` where it is released. */
|
|
24
|
+
dragStart(lng: number, lat: number): void;
|
|
25
|
+
drag(lng: number, lat: number): void;
|
|
26
|
+
dragEnd(lng: number, lat: number): void;
|
|
27
|
+
keyUp(key: string): void;
|
|
28
|
+
getMapEventElement(): HTMLElement;
|
|
29
|
+
project(lng: number, lat: number): {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
};
|
|
33
|
+
unproject(x: number, y: number): {
|
|
34
|
+
lng: number;
|
|
35
|
+
lat: number;
|
|
36
|
+
};
|
|
37
|
+
setCursor(cursor: string): void;
|
|
38
|
+
getLngLatFromEvent(): {
|
|
39
|
+
lng: number;
|
|
40
|
+
lat: number;
|
|
41
|
+
} | null;
|
|
42
|
+
setDraggability(): void;
|
|
43
|
+
setDoubleClickToZoom(): void;
|
|
44
|
+
render(changes: TerraDrawChanges): void;
|
|
45
|
+
clear(): void;
|
|
46
|
+
private pointer;
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DrawPort, type DrawValue } from "@trackunit/react-map-adapter-shared";
|
|
2
|
+
export declare const SQUARE: DrawValue;
|
|
3
|
+
export declare const TRIANGLE: DrawValue;
|
|
4
|
+
/** A polygon with a hole; `DrawPort.setValue` must drop it (sites have no holes). */
|
|
5
|
+
export declare const HOLED: DrawValue;
|
|
6
|
+
/**
|
|
7
|
+
* Behavioural contract every `DrawPort` implementation must satisfy, independent of
|
|
8
|
+
* the engine behind it. Adapter specs run it against their bridge; the controller
|
|
9
|
+
* spec runs it against `DrawController` with a fake engine.
|
|
10
|
+
*/
|
|
11
|
+
export declare const describeDrawPortContract: (name: string, createPort: () => DrawPort) => void;
|