@orbat-mapper/tactical-draw 0.2.0-alpha.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Orbat Mapper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @orbat-mapper/tactical-draw
2
+
3
+ The engine-agnostic draw/edit core for the `@orbat-mapper` tactical graphics
4
+ toolkit. It hosts the rubber-band draw/edit controllers, sessions, and
5
+ draw-rule plumbing, the
6
+ `MapAdapter` contract and base adapter, pixel-space hit-testing and the
7
+ `EditPointerDriver` pointer contract, handle rendering, interaction styles, and
8
+ pick helpers.
9
+
10
+ It depends only on `@orbat-mapper/control-measures` and `geojson` — never on a
11
+ concrete map engine. This is the **bring-your-own-engine** entry point: pair it
12
+ with one of the engine adapter packages, or implement `MapAdapter` yourself.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ # npm
18
+ npm install @orbat-mapper/tactical-draw @orbat-mapper/control-measures
19
+
20
+ # pnpm
21
+ pnpm add @orbat-mapper/tactical-draw @orbat-mapper/control-measures
22
+ ```
23
+
24
+ Then add an engine adapter (or implement `MapAdapter` against your own engine):
25
+
26
+ ```bash
27
+ # pick one — npm
28
+ npm install @orbat-mapper/tactical-draw-adapter-openlayers ol
29
+ npm install @orbat-mapper/tactical-draw-adapter-maplibre maplibre-gl
30
+ npm install @orbat-mapper/tactical-draw-adapter-leaflet leaflet
31
+
32
+ # pick one — pnpm
33
+ pnpm add @orbat-mapper/tactical-draw-adapter-openlayers ol
34
+ pnpm add @orbat-mapper/tactical-draw-adapter-maplibre maplibre-gl
35
+ pnpm add @orbat-mapper/tactical-draw-adapter-leaflet leaflet
36
+ ```
37
+
38
+ ## What's inside
39
+
40
+ - **`TacticalDraw`** — the draw/edit controller hosting draw and edit sessions
41
+ driven by per-measure draw rules.
42
+ - **`MapAdapter`** — the type-only ABI every engine adapter implements, plus
43
+ **`BaseMapAdapter`** with the shared implementation to extend.
44
+ - **Hit-testing & pointer driver** — pixel-space `hitTestFeature`, hit
45
+ tolerances, and the `EditPointerDriver` contract adapters implement for the
46
+ edit controller.
47
+ - **Interaction styles** — `coerceHandleStyle` and the `InteractionStyle` /
48
+ `GuideStyle` / `HandleStyle` shapes. (Handle _rendering_ itself is not part of
49
+ the public API.)
50
+ - **Pick helpers** — hit tolerance and control-measure identification utilities.
51
+
52
+ ## Pick to edit
53
+
54
+ Use `onMeasurePick` to subscribe to committed control measures without accessing
55
+ internal layer ids:
56
+
57
+ ```ts
58
+ const unsubscribe = td.onMeasurePick((event) => {
59
+ const measure = measures.find((candidate) => candidate.id === event.id);
60
+ if (measure) void td.edit(measure);
61
+ });
62
+ ```
63
+
64
+ The handler receives the full `PickEvent`, with `event.id` set to the control
65
+ measure id. The returned unsubscribe function is idempotent, and
66
+ `onMeasurePick(handler, { signal })` also supports abort-driven teardown.
67
+
68
+ ## Cancel and inspect the active interaction
69
+
70
+ Use `cancel()` for a host Cancel button. It aborts draws and edits, including
71
+ fixed-length draws that do not expose a session:
72
+
73
+ ```ts
74
+ cancelButton.onclick = () => td.cancel();
75
+ ```
76
+
77
+ `activeSession` exposes the live `DrawSession` or `EditSession` when one exists,
78
+ and returns `null` while idle or during a fixed-length draw:
79
+
80
+ ```ts
81
+ const session = td.activeSession;
82
+ if (session && "canCommit" in session) {
83
+ doneButton.disabled = !session.canCommit;
84
+ }
85
+ ```
86
+
87
+ ## Bring your own engine
88
+
89
+ Implement `MapAdapter` (or extend `BaseMapAdapter`) against your map engine and
90
+ hand it to `TacticalDraw`. Everything above the adapter — controllers, sessions,
91
+ gestures, handle rendering — works unchanged.
92
+
93
+ ## License
94
+
95
+ MIT