@florasync/leaflet-geokit 0.8.3 → 0.9.1
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/ARCHITECTURE.md +195 -0
- package/CHANGELOG.md +8 -0
- package/README.md +146 -11
- package/custom-toolbar.html +165 -0
- package/dist/django/index.js +8993 -5090
- package/dist/django/index.js.map +1 -1
- package/dist/leaflet-geokit.es.js +21536 -5994
- package/dist/leaflet-geokit.es.js.map +1 -1
- package/dist/leaflet-geokit.external.es.js +18006 -2461
- package/dist/leaflet-geokit.external.es.js.map +1 -1
- package/dist/leaflet-geokit.umd.js +263 -60
- package/dist/leaflet-geokit.umd.js.map +1 -1
- package/dist/preact/index-DCKj0r6a.js +8545 -0
- package/dist/preact/index-DCKj0r6a.js.map +1 -0
- package/dist/preact/index.js +1 -1
- package/dist/preact-bundled/index.js +9002 -5089
- package/dist/preact-bundled/index.js.map +1 -1
- package/dist/react/index-DCKj0r6a.js +8545 -0
- package/dist/react/index-DCKj0r6a.js.map +1 -0
- package/dist/react/index.js +1 -1
- package/dist/react-bundled/index.js +9040 -5127
- package/dist/react-bundled/index.js.map +1 -1
- package/dist/types/components/LeafletDrawMapElement.d.ts +42 -3
- package/dist/types/django/index.d.ts +2 -2
- package/dist/types/external.d.ts +9 -3
- package/dist/types/index.d.ts +9 -3
- package/dist/types/lib/FeatureStore.d.ts +2 -2
- package/dist/types/lib/LayerRegistry.d.ts +19 -0
- package/dist/types/lib/MapController.d.ts +95 -5
- package/dist/types/lib/draw/L.Draw.Move.d.ts +1 -0
- package/dist/types/lib/draw/move-pointer.d.ts +12 -0
- package/dist/types/lib/layer-cake/LayerCakeManager.d.ts +10 -2
- package/dist/types/lib/layer-style-panel.d.ts +3 -0
- package/dist/types/lib/marker-icons.d.ts +1 -1
- package/dist/types/lib/providers.d.ts +64 -0
- package/dist/types/lib/snapping.d.ts +30 -0
- package/dist/types/lib/tool-buttons.d.ts +3 -1
- package/dist/types/lib/tool-capabilities.d.ts +27 -0
- package/dist/types/lib/toolbar-accessibility.d.ts +3 -0
- package/dist/types/lib/toolbar-layout.d.ts +14 -0
- package/dist/types/lib/toolbar-styles.d.ts +2 -0
- package/dist/types/preact/core.d.ts +2 -2
- package/dist/types/preact/index.d.ts +2 -2
- package/dist/types/preact-bundled/index.d.ts +3 -3
- package/dist/types/react/core.d.ts +2 -2
- package/dist/types/react/index.d.ts +2 -2
- package/dist/types/react-bundled/index.d.ts +3 -3
- package/dist/types/types/events.d.ts +15 -1
- package/dist/types/types/layers.d.ts +65 -0
- package/dist/types/types/public.d.ts +160 -5
- package/dist/types/utils/geojson-pipeline.d.ts +51 -0
- package/dist/types/utils/geojson.d.ts +15 -2
- package/dist/types/utils/grower-geometry.d.ts +107 -0
- package/docs/accessibility.md +142 -0
- package/docs/api-reference.md +249 -0
- package/docs/custom-toolbar.md +168 -0
- package/docs/diagnostics.md +216 -0
- package/docs/geojson-pipelines.md +145 -0
- package/docs/google-maps-adapter-spike.md +77 -0
- package/docs/grower-geometry.md +237 -0
- package/docs/grower-measurement.md +23 -0
- package/docs/integration-recipes.md +301 -0
- package/docs/layers.md +136 -0
- package/docs/providers.md +191 -0
- package/docs/release-verification.md +75 -0
- package/docs/shims/django.md +102 -0
- package/docs/shims/preact.md +98 -0
- package/docs/shims/react.md +98 -0
- package/docs/snapping-and-measurements.md +42 -0
- package/docs/tool-capabilities.md +131 -0
- package/docs/tool-lifecycle.md +124 -0
- package/docs/toolbar-layout.md +158 -0
- package/docs/toolbar-styling.md +118 -0
- package/package.json +35 -3
- package/dist/preact/index-BMfJn-mD.js +0 -4632
- package/dist/preact/index-BMfJn-mD.js.map +0 -1
- package/dist/react/index-BMfJn-mD.js +0 -4632
- package/dist/react/index-BMfJn-mD.js.map +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Keyboard and accessibility contract
|
|
2
|
+
|
|
3
|
+
GeoKit 0.8.3 keeps the existing framework-agnostic tool command API. Keyboard
|
|
4
|
+
activation uses the same toolbar command path as a pointer click, including the
|
|
5
|
+
existing capability gates and public lifecycle events.
|
|
6
|
+
|
|
7
|
+
## Command map
|
|
8
|
+
|
|
9
|
+
| Key | Context | Action |
|
|
10
|
+
| ---------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| Tab / Shift+Tab | Map controls | Visit enabled controls using the browser's normal tab order; no toolbar focus trap. |
|
|
12
|
+
| Left / Right | Horizontal toolbar | Previous / next enabled tool, wrapping at the ends. |
|
|
13
|
+
| Up / Down | Vertical toolbar | Previous / next enabled tool, wrapping at the ends. |
|
|
14
|
+
| Home / End | Toolbar | First / last enabled tool. |
|
|
15
|
+
| Enter / Space | Tool button | Activate the tool. Also works on native Leaflet anchor buttons and the ruler control. |
|
|
16
|
+
| Escape | Active map mode | Deactivate/cancel using the existing select command; no export. |
|
|
17
|
+
| Escape | Focused tool popover or settings dialog | Close it and return focus to its trigger. A subsequent Escape can cancel an active map mode. |
|
|
18
|
+
| Ctrl+Enter / Cmd+Enter | Map or toolbar | Commit active edit/delete changes; confirm a pending move; otherwise export completed geometry via the save command. |
|
|
19
|
+
| Tab / Shift+Tab | Measurement units dialog | Cycle through the selected unit radio and Close button. Radio arrow keys remain native. |
|
|
20
|
+
|
|
21
|
+
Text fields, selects, editable content and dialogs do not receive map-level
|
|
22
|
+
shortcuts. Single-letter shortcuts are deliberately avoided. Measurement mode is
|
|
23
|
+
reached with the toolbar's **Measure distance** button; Measurement settings opens
|
|
24
|
+
the named units dialog. Disabled tools are not keyboard-activatable. Their
|
|
25
|
+
requirements are available through the existing capability API.
|
|
26
|
+
|
|
27
|
+
These commands do not implement keyboard vertex placement or move a selected
|
|
28
|
+
geometry with arrow keys. Complete drawing with the tool's existing interaction;
|
|
29
|
+
Ctrl+Enter exports completed geometry rather than finishing an unfinished polygon
|
|
30
|
+
or layer-cake session. Layer-cake session Save/Cancel controls remain separate.
|
|
31
|
+
|
|
32
|
+
## Semantics and announcements
|
|
33
|
+
|
|
34
|
+
- Managed groups and native draw/edit groups expose named `toolbar` roles and
|
|
35
|
+
orientation; buttons have accessible names and native anchor controls expose
|
|
36
|
+
`button` roles.
|
|
37
|
+
- Persistent managed tools (including ruler) reflect `aria-pressed`.
|
|
38
|
+
- Configured popover triggers expose `aria-haspopup="dialog"` and explicit
|
|
39
|
+
`aria-expanded` state. Non-modal popovers receive focus without trapping Tab.
|
|
40
|
+
Their inside/outside click handling uses the composed event path across shadow
|
|
41
|
+
DOM. Escape is scoped to the originating control/popover, not every map.
|
|
42
|
+
- Measurement settings has an accessible dialog name, bounded Tab navigation,
|
|
43
|
+
and focus restoration. The existing layer-style dialog retains its own focus
|
|
44
|
+
restoration.
|
|
45
|
+
- Persistent `role="status"` / polite and `role="alert"` / assertive regions
|
|
46
|
+
announce tool outcomes and failure reasons. Messages use text, never HTML, and
|
|
47
|
+
survive toolbar configuration rerenders.
|
|
48
|
+
|
|
49
|
+
## Contrast, motion, and target sizing
|
|
50
|
+
|
|
51
|
+
`forced-colors: active` and `prefers-contrast: more` choose system-color defaults
|
|
52
|
+
through the existing `--geokit-toolbar-*`, `--geokit-tool-*`,
|
|
53
|
+
`--geokit-popover-*`, and `--geokit-panel-*` tokens. Focus and pressed states have
|
|
54
|
+
visible outlines as well as color changes. Host overrides should preserve these
|
|
55
|
+
states and contrast; tokens can also be overridden on the exposed parts.
|
|
56
|
+
|
|
57
|
+
`prefers-reduced-motion: reduce` removes animations/transitions in the map subtree
|
|
58
|
+
and disables smooth scrolling. `--geokit-reduced-motion-duration` defaults to `0s`
|
|
59
|
+
in this media mode. This does not change JavaScript Leaflet animation options.
|
|
60
|
+
|
|
61
|
+
Managed buttons retain 44px desktop defaults and 48px narrow responsive defaults.
|
|
62
|
+
Dense layouts reduce default group padding, not target size. Explicit host size
|
|
63
|
+
and padding overrides remain authoritative; hosts must not reduce usable targets.
|
|
64
|
+
The responsive layout reserves native zoom/attribution space and keeps enabled
|
|
65
|
+
controls reachable through overflow scrolling. See [Toolbar layout](toolbar-layout.md).
|
|
66
|
+
|
|
67
|
+
## Repeatable checks
|
|
68
|
+
|
|
69
|
+
From the repository root:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
npm run typecheck
|
|
73
|
+
npm run test:unit:focused -- tests/toolbar-accessibility.spec.ts tests/toolbar-contract.spec.ts tests/tool-lifecycle.spec.ts tests/map-controller.spec.ts tests/draw-event-runtime.spec.ts
|
|
74
|
+
npm run test:unit:focused -- tests/draw-move-pointer.spec.ts
|
|
75
|
+
npx playwright test -c playwright.accessibility.config.ts --output="$PAPERCLIP_RUN_SCRATCH_DIR/a11y-results"
|
|
76
|
+
PLAYWRIGHT_JSON_OUTPUT_NAME="$PAPERCLIP_RUN_SCRATCH_DIR/touch-report.json" npx playwright test -c playwright.touch.config.ts --reporter=list,json --output="$PAPERCLIP_RUN_SCRATCH_DIR/touch-results"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Outside Paperclip, choose a writable output directory instead. The finite
|
|
80
|
+
Playwright-owned Vite preview uses port 5187, disables HMR, and shuts down after
|
|
81
|
+
the suite. It does not reuse an existing server.
|
|
82
|
+
|
|
83
|
+
The Chromium suite exercises all 14 public tools using keyboard activation on
|
|
84
|
+
the existing irrigation harness, native anchor activation, edit/delete commit,
|
|
85
|
+
measurement cancellation, modal focus, popover shadow-DOM clicks, error/status
|
|
86
|
+
announcements, high-contrast/reduced-motion media, and measured mobile targets.
|
|
87
|
+
It also runs the existing CSS-contract and responsive-layout regressions,
|
|
88
|
+
including 320px and 390px maps. These are basic accessibility checks, not an axe
|
|
89
|
+
scan or screen-reader certification.
|
|
90
|
+
|
|
91
|
+
## Touch geometry contract and verified coverage
|
|
92
|
+
|
|
93
|
+
Bundled `DrawMove` and external `RuntimeDrawMove` share `move-pointer.ts`.
|
|
94
|
+
Move captures the primary pointer on the stable map container, including when a
|
|
95
|
+
feature is Canvas-rendered. It disables map dragging only for the active gesture
|
|
96
|
+
and restores its prior enabled state on release. Pointer cancellation, lost
|
|
97
|
+
capture, mode switch and destruction release capture and roll back uncommitted
|
|
98
|
+
geometry. Normal pointerup preserves a transaction for Save/Cancel; Save clears
|
|
99
|
+
rollback state before notifying synchronous completion listeners. There is no
|
|
100
|
+
parallel compatibility-mouse drag path.
|
|
101
|
+
|
|
102
|
+
Draw, edit and delete reuse Leaflet.draw and the irrigation harness rather than
|
|
103
|
+
adding a second gesture implementation. Coarse-pointer edit handles expose 44px
|
|
104
|
+
hit targets around 12px visible vertices. Move confirmation controls have 44px
|
|
105
|
+
minimum targets, suppress map touch propagation, and sit above bottom toolbars.
|
|
106
|
+
|
|
107
|
+
`e2e/touch-geometry.spec.ts` passes 20 Chromium tests: ten cases each with Canvas
|
|
108
|
+
and SVG on a 390 × 844 touch viewport. Real `page.touchscreen` taps and Chromium
|
|
109
|
+
CDP `Input.dispatchTouchEvent` drags exercise:
|
|
110
|
+
|
|
111
|
+
- Polygon creation by vertex taps and closure, plus unfinished-draw cancellation.
|
|
112
|
+
- Edit geometry change with cancellation rollback and Save persistence.
|
|
113
|
+
- Delete with cancellation restoration and Save removal.
|
|
114
|
+
- Captured move outside map bounds without map panning; Cancel rollback and Save
|
|
115
|
+
persistence, with no duplicate compatibility mousedown.
|
|
116
|
+
- Browser-generated pointercancel and lost-capture rollback; mouse pointer
|
|
117
|
+
release outside the map remains supported.
|
|
118
|
+
- Mode switch and controller destruction during an active touch, with capture,
|
|
119
|
+
transaction and touch-action cleanup.
|
|
120
|
+
- External Move registration, touch cancellation and confirmation.
|
|
121
|
+
- Measured edit hit targets, an off-center finger drag, and non-overlap with
|
|
122
|
+
toolbar/native controls in the tested layout.
|
|
123
|
+
- Correlated command IDs and exactly one completion for saved draw/edit/delete/
|
|
124
|
+
move operations; cancelled operations do not produce extra completions.
|
|
125
|
+
|
|
126
|
+
Focused unit tests additionally cover both Move implementations with map dragging
|
|
127
|
+
initially disabled, unrelated pointer IDs, pending-transaction protection,
|
|
128
|
+
re-enabling, teardown and synchronous completion listeners. The JSON report
|
|
129
|
+
preserves geometry/event evidence and the harness saves screenshots per case.
|
|
130
|
+
|
|
131
|
+
### Platform and scope constraints
|
|
132
|
+
|
|
133
|
+
This is Chromium touch emulation, not physical Android/iOS certification. CDP
|
|
134
|
+
touchCancel is a browser input event, not `handler.fire` or a constructed DOM
|
|
135
|
+
PointerEvent. Lost-capture testing explicitly calls `releasePointerCapture`
|
|
136
|
+
during a real drag; mode switch/destroy invoke the controller API during a real
|
|
137
|
+
drag. External coverage registers a fresh host namespace against the same
|
|
138
|
+
installed Leaflet version; it does not certify arbitrary host Leaflet versions.
|
|
139
|
+
The gesture fixture uses six managed tools and a polygon. It does not claim
|
|
140
|
+
every shape, dense overlapping vertex target, custom host toolbar layout,
|
|
141
|
+
multi-touch gesture, Firefox or WebKit has been tested. The separate keyboard
|
|
142
|
+
suite continues to cover all 14 public tools and 320px/390px responsive layouts.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Public API reference
|
|
2
|
+
|
|
3
|
+
This reference describes the framework-independent `<leaflet-geokit>` custom element.
|
|
4
|
+
`<leaflet-draw-map>` remains a compatibility alias. Import
|
|
5
|
+
`@florasync/leaflet-geokit` to register the bundled element; the `/external`
|
|
6
|
+
entrypoint is for hosts supplying Leaflet/Draw. Registration requires browser
|
|
7
|
+
DOM globals: defer imports to the client in SSR applications.
|
|
8
|
+
|
|
9
|
+
Contracts: [public types](../src/types/public.ts), [event types](../src/types/events.ts),
|
|
10
|
+
[element implementation](../src/components/LeafletDrawMapElement.ts), and
|
|
11
|
+
[package exports](../src/index.ts). Framework wrappers are optional; see
|
|
12
|
+
[React](shims/react.md), [Preact](shims/preact.md), and [Django](shims/django.md).
|
|
13
|
+
|
|
14
|
+
## Readiness and sizing
|
|
15
|
+
|
|
16
|
+
Give the element a nonzero width and height. Subscribe directly on the element
|
|
17
|
+
before connecting it when initial events matter. `customElements.whenDefined()`
|
|
18
|
+
means the class is registered, not that its map is initialized. Observe
|
|
19
|
+
`leaflet-geokit:status` and read `status` for durable readiness; the legacy
|
|
20
|
+
`leaflet-draw:ready` callback fires before the asynchronous status synchronization
|
|
21
|
+
finishes. In particular, wait for `status.ready` before `setBasemapAdapter()`.
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import "@florasync/leaflet-geokit";
|
|
25
|
+
|
|
26
|
+
const map = document.createElement("leaflet-geokit");
|
|
27
|
+
map.style.cssText = "width:100%;height:400px";
|
|
28
|
+
map.setAttribute("draw-polygon", "");
|
|
29
|
+
map.addEventListener("leaflet-geokit:status", (event) => {
|
|
30
|
+
console.log(event.detail.state, event.detail.featureCount);
|
|
31
|
+
});
|
|
32
|
+
map.addEventListener("leaflet-draw:created", (event) => {
|
|
33
|
+
console.log(event.detail.id, event.detail.geoJSON);
|
|
34
|
+
});
|
|
35
|
+
document.body.append(map);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Do not use pre-ready mutation calls as a queue: many methods return empty results
|
|
39
|
+
or do nothing without a controller. Tool activation returns `false` with failure
|
|
40
|
+
events; `setBasemapAdapter()` throws when not ready. Disconnect destroys the map;
|
|
41
|
+
reapply host data and an optional adapter after reconnecting.
|
|
42
|
+
|
|
43
|
+
## Attributes and reflected properties
|
|
44
|
+
|
|
45
|
+
Boolean attributes use **presence**, not string values: `read-only="false"`
|
|
46
|
+
still enables read-only. Remove the attribute or set its boolean property to
|
|
47
|
+
`false`. A dash below means there is no corresponding scalar property; use
|
|
48
|
+
`setAttribute`/`removeAttribute` or the listed object configuration instead.
|
|
49
|
+
|
|
50
|
+
| Attribute | Property | Value / default / behavior |
|
|
51
|
+
| ------------------------------------------------------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `latitude`, `longitude` | `latitude`, `longitude` | Numbers; both default to `0`. Runtime changes update the view. |
|
|
53
|
+
| `zoom` | `zoom` | Number; default `2`. |
|
|
54
|
+
| `min-zoom`, `max-zoom` | `minZoom`, `maxZoom` | Optional numbers; unset by default. |
|
|
55
|
+
| `tile-url` | `tileUrl` | Default `https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png`. Used when no named provider is configured. |
|
|
56
|
+
| `tile-attribution` | `tileAttribution` | Optional attribution string; trusted HTML passed to Leaflet. |
|
|
57
|
+
| `tile-provider` | `tileProvider` | Optional `osm` or `here`; trimmed/lowercased. Clear it to use `tile-url`. |
|
|
58
|
+
| `tile-style` | `tileStyle` | Optional provider style; HERE defaults to `lite.day`. |
|
|
59
|
+
| `api-key`, `here-api-key` | `apiKey` | Canonical key and legacy alias. Nonempty canonical value wins; setting `apiKey` removes the legacy attribute. Browser-visible, not secret storage. |
|
|
60
|
+
| `read-only` | `readOnly` | Boolean; default `false`. Restricts interactive mutating tools, not a server authorization boundary. |
|
|
61
|
+
| `log-level` | `logLevel` | `trace`, `debug`, `info`, `warn`, `error`, `silent`; default `debug`. |
|
|
62
|
+
| `dev-overlay` | `devOverlay` | Boolean; default `false`. Reserved compatibility flag, not an overlay UI. |
|
|
63
|
+
| `prefer-canvas` | `preferCanvas` | Boolean; initial default `true`. Presence is true even for `"false"`; set `map.preferCanvas = false` before connection to request SVG. This accessor exists on the concrete class, but is not declared in `LeafletDrawMapElementAPI`. |
|
|
64
|
+
| `use-external-leaflet` | `useExternalLeaflet` | Boolean; default `false`. Prefer supplied Leaflet/Draw runtime. |
|
|
65
|
+
| `skip-leaflet-styles` | `skipLeafletStyles` | Boolean; default `false`. Host takes responsibility for CSS/icon injection; global document CSS alone does not style shadow contents. |
|
|
66
|
+
| `theme-url` | — | Optional stylesheet URL inserted into the shadow root. |
|
|
67
|
+
| `marker-icon-url` | — | Custom marker URL; absent/invalid uses default marker. See `markerIconConfig`. |
|
|
68
|
+
| `marker-icon-retina-url` | — | Optional high-DPI URL; fallback is the regular icon URL. |
|
|
69
|
+
| `marker-shadow-url` | — | Optional shadow URL; absent/invalid omits shadow. |
|
|
70
|
+
| `marker-icon-size` | — | Comma-separated width,height in CSS pixels; default `25,41`. |
|
|
71
|
+
| `marker-icon-anchor` | — | Comma-separated x,y; default `12,41`. |
|
|
72
|
+
| `marker-popup-anchor` | — | Comma-separated x,y; default `1,-34`. |
|
|
73
|
+
| `tool-button-config` | `toolButtonConfig` (object override) | JSON object keyed by tool name; icons, accessible labels, popovers, disabled state, prerequisites. |
|
|
74
|
+
| `toolbar-groups` | `toolbarGroups` (object override) | JSON array of groups; default no custom groups. A group needs `id` and `tools`. |
|
|
75
|
+
| `draw-polygon`, `draw-polyline`, `draw-rectangle`, `draw-circle`, `draw-marker` | — | Boolean tool enables; absent by default. |
|
|
76
|
+
| `draw-layer-cake`, `draw-move`, `draw-ruler` | — | Boolean enables for `layerCake`, `move`, `ruler`; absent by default. |
|
|
77
|
+
| `edit-features`, `delete-features` | — | Boolean enables; absent by default. Delete also requires `edit-features`. |
|
|
78
|
+
| `polygon-allow-intersection` | — | Boolean; default `false`. Set before initialization; changing it alone does not trigger a controller rebuild. |
|
|
79
|
+
|
|
80
|
+
View changes are applied directly; structural changes (draw toggles, read-only,
|
|
81
|
+
zoom limits and runtime flags) serialize controller rebuilds. Tile configuration
|
|
82
|
+
updates the basemap. Prefer configuration before connection over repeated
|
|
83
|
+
structural changes. Do not infer new properties by camel-casing attributes.
|
|
84
|
+
|
|
85
|
+
## Object and property-only configuration
|
|
86
|
+
|
|
87
|
+
| Property | Type / semantics |
|
|
88
|
+
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
89
|
+
| `status` | Read-only detached `StatusEventDetail`; see [diagnostics](diagnostics.md). |
|
|
90
|
+
| `themeCss` | String; default empty. Injects inline CSS into the shadow root; does not reflect an attribute. |
|
|
91
|
+
| `markerIconConfig` | `MarkerIconConfig \| null \| undefined`; `undefined` uses attributes, `null` forces default markers. |
|
|
92
|
+
| `toolButtonConfig` | `ToolButtonConfig \| null \| undefined`; `undefined` uses JSON attribute, `null` clears customization. Functions/renderers require this property, not JSON. |
|
|
93
|
+
| `toolbarGroups` | `ToolToolbarGroupConfig[] \| null \| undefined`; `undefined` uses JSON attribute, `null` clears groups. |
|
|
94
|
+
| `snapping` | `SnappingOptions \| null \| undefined`; opt-in vertex/edge/grid/guide snapping. |
|
|
95
|
+
| `measurementOverlay` | `MeasurementOverlayOptions \| null \| undefined`; opt-in live measurements. |
|
|
96
|
+
| `leafletInstance` | Optional Leaflet namespace injection; set before connecting, with compatible Draw plugins attached. |
|
|
97
|
+
| `toolHooks` | `IntegratedToolHooks`; callbacks keyed by integrated event name. |
|
|
98
|
+
| `toolEventEmitter` | `IntegratedToolEventEmitter`; optional `emit(eventName, detail)` and/or `dispatchEvent(event)`. |
|
|
99
|
+
|
|
100
|
+
Configuration interfaces, including all callback signatures, are in
|
|
101
|
+
[public.ts](../src/types/public.ts). See [snapping and measurements](snapping-and-measurements.md)
|
|
102
|
+
for options/limits, [toolbar styling](toolbar-styling.md) for icons/popovers/slots,
|
|
103
|
+
and [responsive layout](toolbar-layout.md) for zones and map-width breakpoints.
|
|
104
|
+
Only trusted/sanitized host content belongs in `iconHtml`, popover `html`, CSS,
|
|
105
|
+
render callbacks, or attribution HTML.
|
|
106
|
+
|
|
107
|
+
## Methods
|
|
108
|
+
|
|
109
|
+
`FC` below means GeoJSON `FeatureCollection`; `Feature` and configuration types
|
|
110
|
+
are exported from the package. GeoJSON positions are `[longitude, latitude]`;
|
|
111
|
+
view/bounds methods use latitude first. Methods returning promises must be awaited
|
|
112
|
+
and may reject; see [diagnostics](diagnostics.md).
|
|
113
|
+
|
|
114
|
+
| Method | Return | Contract |
|
|
115
|
+
| ------------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `getGeoJSON()` | `Promise<FC>` | Current editing collection. |
|
|
117
|
+
| `importGeoJSON(fc, options?)` | `Promise<string[]>` | Import with `GeoJSONImportOptions`; default behavior `replace`, `fitToData: false`. Opt into `validate: true` for preflight validation. |
|
|
118
|
+
| `loadGeoJSON(fc)` | `Promise<void>` | Compatibility replacement import. |
|
|
119
|
+
| `addFeatures(fc)` | `Promise<string[]>` | Compatibility additive import; returns assigned IDs. |
|
|
120
|
+
| `loadGeoJSONFromUrl(url, options?)` | `Promise<void>` | Fetch JSON then import; default replace, `fitToData: true`. |
|
|
121
|
+
| `loadGeoJSONFromText(text, options?)` | `Promise<void>` | Parse then import; default replace, `fitToData: true`. |
|
|
122
|
+
| `exportGeoJSON(options?)` | `Promise<FC>` | `GeoJSONExportOptions`; default adapter `editing`; emits `leaflet-draw:export`. |
|
|
123
|
+
| `clearLayers()` | `Promise<void>` | Clear stored/rendered features. |
|
|
124
|
+
| `updateFeature(id, feature)` | `Promise<void>` | Update by stable string ID. |
|
|
125
|
+
| `removeFeature(id)` | `Promise<void>` | Remove by ID. |
|
|
126
|
+
| `fitBoundsToData(padding?)` | `Promise<void>` | Fit stored data; padding ratio defaults to `0.05`. |
|
|
127
|
+
| `fitBounds(bounds, padding?)` | `Promise<void>` | Bounds `[[south, west], [north, east]]`; padding ratio defaults to `0.05`. |
|
|
128
|
+
| `setView(lat, lng, zoom?)` | `Promise<void>` | Set view and reflect coordinate/zoom properties. |
|
|
129
|
+
| `mergePolygons(options?)` | `Promise<string \| null>` | Merge visible polygon layers, replacing originals; optional `properties` record; emits merged event on success. |
|
|
130
|
+
| `getLayers()` | `MapLayer[]` | Layer inventory. |
|
|
131
|
+
| `setLayerVisibility(id, visible)` | `Promise<void>` | Change layer visibility. |
|
|
132
|
+
| `setLayerStyle(id, style)` | `Promise<void>` | Apply `LayerStyle`. |
|
|
133
|
+
| `reorderLayers(ids)` | `Promise<void>` | Reorder using readonly string IDs. |
|
|
134
|
+
| `focusLayer(id)` | `Promise<void>` | Focus a layer. |
|
|
135
|
+
| `removeLayer(id)` | `Promise<void>` | Remove a named layer. |
|
|
136
|
+
| `getLayerCakeSession()` | `LayerCakeSession \| null` | Current session snapshot. |
|
|
137
|
+
| `updateLayerCakeSession(update)` | `Promise<void>` | Apply `LayerCakeSessionUpdate`. |
|
|
138
|
+
| `saveLayerCakeSession()` | `Promise<void>` | Commit the current session. |
|
|
139
|
+
| `cancelLayerCakeSession()` | `Promise<void>` | Cancel the current session. |
|
|
140
|
+
| `getToolCapabilities()` | `ToolCapabilities` | Detached synchronous snapshot, including before readiness. |
|
|
141
|
+
| `setToolSelection(featureIds)` | `void` | Supply readonly host-selected IDs; unknown/deleted IDs excluded. |
|
|
142
|
+
| `activateTool(tool, options?)` | `Promise<boolean>` | Command accepted/handled, not proof of completed geometry. Options: `source`, `groupId`, `commandId`. |
|
|
143
|
+
| `triggerTool(tool, options?)` | `Promise<boolean>` | Compatibility alias of `activateTool`. |
|
|
144
|
+
| `deactivateTool(options?)` | `Promise<boolean>` | Return to select mode. |
|
|
145
|
+
| `setMeasurementUnits(system)` | `Promise<void>` | `metric` or `imperial`. |
|
|
146
|
+
| `getSnappingOptions()` | `SnappingOptions \| null` | Current snap configuration. |
|
|
147
|
+
| `getMeasurementOverlayOptions()` | `MeasurementOverlayOptions \| null` | Current overlay configuration. |
|
|
148
|
+
| `setBasemapAdapter(adapter)` | `void` | After ready, set `BasemapAdapter`; `null` restores raster configuration. |
|
|
149
|
+
| `getProviderDiagnostics()` | `ProviderDiagnostics \| null` | Configuration report, not service-health probe. |
|
|
150
|
+
|
|
151
|
+
Detailed data semantics: [GeoJSON pipelines](geojson-pipelines.md),
|
|
152
|
+
[layers and cake sessions](layers.md), [providers](providers.md).
|
|
153
|
+
The URL/text convenience methods currently forward `behavior` and `fitToData`,
|
|
154
|
+
not `validate`; for validated uploads use the pipeline helpers followed by
|
|
155
|
+
`importGeoJSON(data, { validate: true })`. Legacy source export and the diagnostic
|
|
156
|
+
`exportGeoJSONData` helper have different provenance guarantees; consult the
|
|
157
|
+
pipeline guide before persisting source geometry.
|
|
158
|
+
|
|
159
|
+
## Events
|
|
160
|
+
|
|
161
|
+
These are DOM `CustomEvent`s: payloads live in `event.detail`, not on the event
|
|
162
|
+
itself. Listen on the element for compatibility across every family. Legacy draw,
|
|
163
|
+
status, and diagnostic events are not bubbling/composed; public lifecycle,
|
|
164
|
+
capability, and layer events are bubbling/composed. Provider events bubble but
|
|
165
|
+
are not composed. Do not assume all events can be delegated across shadow roots.
|
|
166
|
+
|
|
167
|
+
| Event | Detail / use |
|
|
168
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
169
|
+
| `leaflet-draw:ready` | `ReadyEventDetail`: optional bounds. |
|
|
170
|
+
| `leaflet-draw:created` | `CreatedEventDetail`: `id`, `layerType`, `geoJSON` Feature. |
|
|
171
|
+
| `leaflet-draw:edited`, `leaflet-draw:deleted` | `EditedEventDetail` / `DeletedEventDetail`: `ids`, current `geoJSON` FC. |
|
|
172
|
+
| `leaflet-draw:ingest` | `IngestEventDetail`: mutable `fc`, `mode: "load" \| "add"`; synchronous pre-import transform hook. |
|
|
173
|
+
| `leaflet-draw:export` | `ExportEventDetail`: `geoJSON`, `featureCount`, `adapter`. |
|
|
174
|
+
| `leaflet-draw:merged` | `id`, `mergedFeatureCount`, resulting `geoJSON`. |
|
|
175
|
+
| `leaflet-draw:error` | `ErrorEventDetail`: code/message/recoverability/timestamp and optional cause. |
|
|
176
|
+
| `leaflet-geokit:status` | `StatusEventDetail`; same shape as `status`. |
|
|
177
|
+
| `leaflet-geokit:diagnostic` | `DiagnosticEventDetail`; severity/state plus error summary. |
|
|
178
|
+
| `tile-provider-error`, `tile-provider-changed` | `TileProviderErrorDetail` / `TileProviderChangedDetail`; see diagnostics/provider guide. |
|
|
179
|
+
| `leaflet-geokit:tool-command` | Input `ToolCommandEventDetail`, normalized to correlated `ToolEventDetail`. |
|
|
180
|
+
| `leaflet-geokit:tool-commanded`, `leaflet-geokit:tool-started`, `leaflet-geokit:tool-completed`, `leaflet-geokit:tool-cancelled`, `leaflet-geokit:tool-failed`, `leaflet-geokit:tool-state-changed` | `ToolEventDetail`; canonical lifecycle, command IDs, geometry and failure/cancel reason. |
|
|
181
|
+
| `leaflet-geokit:tool-capabilities-changed` | `ToolCapabilities`; change-deduplicated snapshot. Read initial snapshot after subscribing. |
|
|
182
|
+
| `leaflet-geokit:tool-trigger-requested`, `leaflet-geokit:tool-triggered`, `leaflet-geokit:tool-trigger-failed` | Compatibility `ToolTriggerEventDetail`; includes `handled` and optional `error`. |
|
|
183
|
+
| `leaflet-geokit:layers-changed` | Layer inventory change; [layer payload contract](layers.md). |
|
|
184
|
+
| `leaflet-geokit:layer-style-request` | Cancelable host style request; `preventDefault()` claims it instead of the fallback panel. |
|
|
185
|
+
| `tool:layer-cake:session-started`, `tool:layer-cake:session-changed`, `tool:layer-cake:saved`, `tool:layer-cake:cancelled` | Layer-cake session events; [layers](layers.md). |
|
|
186
|
+
|
|
187
|
+
Compatibility command inputs `leaflet-geokit:activate-tool`,
|
|
188
|
+
`leaflet-geokit:trigger-tool`, and `leaflet-geokit:deactivate-tool` remain supported.
|
|
189
|
+
The full lifecycle ordering and per-tool completion matrix are in
|
|
190
|
+
[tool lifecycle](tool-lifecycle.md). Additional integrated hook/emitter names
|
|
191
|
+
(`tool:polygon:created`, `tool:polyline:created`, `tool:rectangle:created`,
|
|
192
|
+
`tool:circle:created`, `tool:marker:created`, `tool:move:pending`,
|
|
193
|
+
`tool:move:confirmed`, `tool:move:cancelled`, `tool:edit:applied`,
|
|
194
|
+
`tool:delete:applied`, `tool:ruler:units-changed`, `tool:save`) are declared by
|
|
195
|
+
`IntegratedToolEventName` in the public types; do not confuse these observer hooks
|
|
196
|
+
with the canonical element lifecycle bus.
|
|
197
|
+
|
|
198
|
+
## Tool capability states
|
|
199
|
+
|
|
200
|
+
Tool names are `polygon`, `polyline`, `rectangle`, `circle`, `marker`, `layerCake`,
|
|
201
|
+
`move`, `select`, `edit`, `delete`, `ruler`, `measurementSettings`, `layerStyle`,
|
|
202
|
+
and `save`.
|
|
203
|
+
|
|
204
|
+
| State | Meaning |
|
|
205
|
+
| ------------- | ----------------------------------------------------------------------------- |
|
|
206
|
+
| `enabled` | Prerequisites met; `reason` is null. |
|
|
207
|
+
| `disabled` | Read-only, missing attribute/layers/selection, or host button restriction. |
|
|
208
|
+
| `unavailable` | Not ready, missing plugin, runtime failure, or unavailable required provider. |
|
|
209
|
+
|
|
210
|
+
Use `state` for button presentation and inspect `commandEnabled` for imperative
|
|
211
|
+
retry/compatibility behavior: host `disabled` does not block imperative calls.
|
|
212
|
+
Local geometry tools do not require a paid basemap. There are no built-in letter
|
|
213
|
+
hotkeys (`hotkey` is null). The exhaustive reason table, precedence, selection
|
|
214
|
+
rules and external-button example live in [tool capabilities](tool-capabilities.md).
|
|
215
|
+
|
|
216
|
+
## CSS parts, tokens, and slots
|
|
217
|
+
|
|
218
|
+
| Surface | Authoritative inventory |
|
|
219
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
220
|
+
| Base parts `host`, `map`, `toolbar-group`, `toolbar-button`, `icon`, `popover`, `active`, `disabled`, `badge`, `tooltip` | [Styling parts table](toolbar-styling.md#parts-and-states). Capability reflection also applies `disabled` for unmet prerequisites, not only host-disabled configuration. |
|
|
221
|
+
| Tool, toolbar, icon, popover, badge, tooltip custom properties | [Token/default table](toolbar-styling.md#css-custom-properties). |
|
|
222
|
+
| Layout parts `toolbar-layout`, `toolbar-zone`, `zone-top-start`, `zone-top-end`, `zone-center-end`, `zone-bottom-start`, `zone-bottom-end`, and zone-mode `toolbar-group-ID` | [Responsive host CSS](toolbar-layout.md#host-css-including-shadow-dom). |
|
|
223
|
+
| Layout tokens `--geokit-toolbar-zone`, `--geokit-toolbar-order`, `--geokit-toolbar-wrap`, `--geokit-zone-gap`, and `--geokit-safe-area-top/right/bottom/left` (one token per side) | [Layout CSS](toolbar-layout.md#host-css-including-shadow-dom) and [safe-area contract](toolbar-layout.md#collision-insets-and-overflow-contract). |
|
|
224
|
+
| Named icon/badge/tooltip slots | [Slot naming and examples](toolbar-styling.md#named-slots). |
|
|
225
|
+
|
|
226
|
+
The built-in layer style panel additionally exposes `layer-style-panel`,
|
|
227
|
+
`--geokit-panel-background` (default `white`) and `--geokit-panel-color`
|
|
228
|
+
(default `#222`); see [layer style panel](layers.md#style-panel-built-in-or-host-owned).
|
|
229
|
+
|
|
230
|
+
Tokens inherit from the element; use `::part` for exposed surfaces and
|
|
231
|
+
`themeCss`/`theme-url` for internal per-tool/group selectors. `--_geokit-*` values
|
|
232
|
+
are private. Responsive zones supplement the older styling guide's corner-only
|
|
233
|
+
placement discussion. See [accessibility](accessibility.md) before replacing
|
|
234
|
+
focus, disabled, keyboard, or touch affordances.
|
|
235
|
+
|
|
236
|
+
## Standalone helpers
|
|
237
|
+
|
|
238
|
+
The root and external entrypoints also export pure operation helpers, although
|
|
239
|
+
the entrypoints themselves register browser elements:
|
|
240
|
+
|
|
241
|
+
- [GeoJSON validation, normalization, import/export, diff and patch](geojson-pipelines.md).
|
|
242
|
+
- [Grower geometry](grower-geometry.md): buffer, merge, split, simplify, centroid,
|
|
243
|
+
bounding box, row/bed guides, irrigation zones and presets.
|
|
244
|
+
- [Measurement](grower-measurement.md): `measureGeoJSON`, `formatMeasurements`.
|
|
245
|
+
- [Snapping](snapping-and-measurements.md): `findSnap` and associated types.
|
|
246
|
+
- [Provider factories, diagnostics and injected basemap contracts](providers.md#public-api).
|
|
247
|
+
|
|
248
|
+
No private controller, feature store, or Leaflet handler access is required for
|
|
249
|
+
these public contracts.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Branded toolbars and external buttons
|
|
2
|
+
|
|
3
|
+
Start with [the complete plain HTML example](../custom-toolbar.html): run
|
|
4
|
+
`npm run dev`, then open `/custom-toolbar.html`. It uses only public element
|
|
5
|
+
properties, events, CSS parts and tokens; no Leaflet toolbar DOM surgery. The
|
|
6
|
+
example imports `/src/index.ts` for Vite development. In a consumer bundler replace
|
|
7
|
+
that import with `@florasync/leaflet-geokit`; do not deploy a `/src` URL. For direct
|
|
8
|
+
browser modules use the version-pinned [Django entrypoint](shims/django.md).
|
|
9
|
+
|
|
10
|
+
## Choose the customization layer
|
|
11
|
+
|
|
12
|
+
| API | Use |
|
|
13
|
+
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
14
|
+
| `toolButtonConfig` | Labels, icons, classes, popovers and visual defaults keyed by tool name. |
|
|
15
|
+
| `toolbarGroups` | Explicit tool order, placement and semantic group labels. |
|
|
16
|
+
| `className` | App-owned classes on individual buttons. Target these inside `themeCss`, not document-level descendant selectors across Shadow DOM. |
|
|
17
|
+
| `iconUrl` | An app-owned SVG/PNG URL. Resolve bundled assets with `new URL("./icon.svg", import.meta.url).href`. |
|
|
18
|
+
| `iconHtml` | Developer-owned inline SVG/HTML, allowing `currentColor`. |
|
|
19
|
+
| `renderIcon` | JS property callback returning an HTMLElement, SVGElement, string, null or undefined. Functions cannot be represented in JSON attributes. |
|
|
20
|
+
| `popover` | Point-of-action guidance with `title`, text `body`, trusted `html` or a `render` callback. |
|
|
21
|
+
| CSS custom properties / `::part` | Host theme overrides without depending on private Leaflet structure. |
|
|
22
|
+
|
|
23
|
+
See [the API reference](api-reference.md), [styling tokens/parts/slots](toolbar-styling.md),
|
|
24
|
+
[responsive zones and overflow](toolbar-layout.md), and [keyboard accessibility](accessibility.md).
|
|
25
|
+
Property configuration overrides JSON attributes. `undefined` restores attribute
|
|
26
|
+
fallback; `null` clears programmatic configuration. Set configuration before
|
|
27
|
+
mount when possible, or assign through public setters after upgrade.
|
|
28
|
+
|
|
29
|
+
## Minimal toolbar configuration
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
map.toolButtonConfig = {
|
|
33
|
+
polygon: {
|
|
34
|
+
title: "Draw growing space",
|
|
35
|
+
ariaLabel: "Draw growing space",
|
|
36
|
+
className: "flora-primary",
|
|
37
|
+
iconUrl: "/assets/growing-space.svg",
|
|
38
|
+
popover: {
|
|
39
|
+
title: "Boundary",
|
|
40
|
+
body: "Click corners, then the first point to finish.",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
save: { title: "Save growing spaces", ariaLabel: "Save growing spaces" },
|
|
44
|
+
};
|
|
45
|
+
map.toolbarGroups = [
|
|
46
|
+
{
|
|
47
|
+
id: "grow",
|
|
48
|
+
tools: ["polygon", "select", "save"],
|
|
49
|
+
position: "bottomleft",
|
|
50
|
+
orientation: "horizontal",
|
|
51
|
+
offset: [12, 12],
|
|
52
|
+
hideDefaultToolbar: true,
|
|
53
|
+
ariaLabel: "Growing-space tools",
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Enable the matching tool attributes, e.g. `draw-polygon`. Placement supports
|
|
59
|
+
`topleft`, `topright`, `bottomleft`, `bottomright`. `offset` is `[x, y]` in pixels.
|
|
60
|
+
The native draw/ruler toolbar hides when **any** group has
|
|
61
|
+
`hideDefaultToolbar: true` (the default). Set it false on **every** group to keep
|
|
62
|
+
native controls. `select` cancels drawing; `save` emits `leaflet-draw:export`—it
|
|
63
|
+
is not a server write. Persist `event.detail.geoJSON` in your host application.
|
|
64
|
+
|
|
65
|
+
## Host-app CSS
|
|
66
|
+
|
|
67
|
+
```css
|
|
68
|
+
leaflet-geokit {
|
|
69
|
+
display: block;
|
|
70
|
+
width: 100%;
|
|
71
|
+
height: 65vh;
|
|
72
|
+
min-height: 320px;
|
|
73
|
+
--geokit-tool-size: 48px;
|
|
74
|
+
--geokit-tool-radius: 12px;
|
|
75
|
+
--geokit-tool-background: #edf6ee;
|
|
76
|
+
--geokit-tool-color: #183b27;
|
|
77
|
+
--geokit-tool-focus-ring: 3px solid #287d47;
|
|
78
|
+
--geokit-toolbar-background: #f4f8f2;
|
|
79
|
+
--geokit-toolbar-gap: 8px;
|
|
80
|
+
}
|
|
81
|
+
leaflet-geokit::part(toolbar-group) {
|
|
82
|
+
border: 1px solid #287d47;
|
|
83
|
+
}
|
|
84
|
+
[data-theme="dark"] leaflet-geokit {
|
|
85
|
+
--geokit-tool-background: #203d2a;
|
|
86
|
+
--geokit-tool-color: #e0f1de;
|
|
87
|
+
--geokit-toolbar-background: #15261b;
|
|
88
|
+
--geokit-tool-hover-background: #31563c;
|
|
89
|
+
--geokit-tool-focus-ring: 3px solid #9fdaaa;
|
|
90
|
+
}
|
|
91
|
+
@media (prefers-reduced-motion: reduce) {
|
|
92
|
+
leaflet-geokit::part(toolbar-button) {
|
|
93
|
+
transition: none;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
For per-tool styling, assign
|
|
99
|
+
`map.themeCss = '[data-geokit-tool="polygon"].flora-primary { --geokit-tool-radius: 50%; }'`.
|
|
100
|
+
Document-level `.flora-primary` rules cannot pierce Shadow DOM. Do not query private
|
|
101
|
+
Leaflet classes or replace internal buttons; setters may rerender groups.
|
|
102
|
+
|
|
103
|
+
## External layer-cake button
|
|
104
|
+
|
|
105
|
+
Use a native `<button type="button" disabled>Build layered zone</button>` outside
|
|
106
|
+
the map and enable `draw-layer-cake` on `<leaflet-geokit>`. Bind its disabled state to the capability snapshot rather than guessing
|
|
107
|
+
whether initialization has finished:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
function refresh() {
|
|
111
|
+
const capability = map.getToolCapabilities().tools.layerCake;
|
|
112
|
+
button.disabled = capability.state !== "enabled";
|
|
113
|
+
button.title = capability.reason?.message ?? "Build layered zone";
|
|
114
|
+
}
|
|
115
|
+
map.addEventListener("leaflet-geokit:tool-capabilities-changed", refresh);
|
|
116
|
+
refresh();
|
|
117
|
+
button.addEventListener("click", async () => {
|
|
118
|
+
await map.activateTool("layerCake", { source: "external-layer-button" });
|
|
119
|
+
});
|
|
120
|
+
cancelButton.addEventListener("click", async () => {
|
|
121
|
+
await map.deactivateTool({ source: "external-layer-button" });
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The event alternative dispatches **on the map element**, not an unrelated button:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
map.dispatchEvent(
|
|
129
|
+
new CustomEvent("leaflet-geokit:activate-tool", {
|
|
130
|
+
detail: { tool: "layerCake", source: "external-layer-button" },
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Listen to `leaflet-geokit:tool-failed` for actionable failures; do not equate a
|
|
136
|
+
resolved command promise with persisted geometry. See [tool lifecycle](tool-lifecycle.md)
|
|
137
|
+
and [layer-cake session methods](layers.md). Remove listeners when your framework
|
|
138
|
+
unmounts. UI-only `configured_disabled` does not prohibit imperative activation:
|
|
139
|
+
your external button should respect `state`, not only `commandEnabled`.
|
|
140
|
+
|
|
141
|
+
## Trust boundary: SVG, HTML and URLs
|
|
142
|
+
|
|
143
|
+
`iconHtml`, string renderer results, popover HTML and `themeCss` are trusted-code
|
|
144
|
+
surfaces, not sanitizers. Never interpolate uploaded GeoJSON properties, user
|
|
145
|
+
labels, remote markup or database text into these strings. Prefer `iconUrl` for
|
|
146
|
+
reviewed static assets and DOM nodes populated via `textContent` for untrusted
|
|
147
|
+
text. If rich untrusted markup is unavoidable, sanitize in the host using a vetted
|
|
148
|
+
policy before passing it; do not rely on Shadow DOM for isolation. Keep URLs
|
|
149
|
+
allowlisted and compatible with your CSP. Never put private provider credentials
|
|
150
|
+
in browser markup, diagnostic logs or screenshots.
|
|
151
|
+
|
|
152
|
+
## Integration and screenshot checklist
|
|
153
|
+
|
|
154
|
+
- Give the host and its containing layout real width/height; test hidden-tab reveal.
|
|
155
|
+
- Check toolbar/popover z-index against host dialogs and sticky navigation.
|
|
156
|
+
- Check light/dark hover, active, disabled, icon contrast and popover readability.
|
|
157
|
+
- Keep touch targets at least 44 × 44 CSS pixels; verify tool access at mobile,
|
|
158
|
+
tablet and desktop widths, including overflow scrolling.
|
|
159
|
+
- Keep visible focus rings, accessible names, arrow-key group navigation and Escape.
|
|
160
|
+
- Honor reduced motion; never convey state through animation or color alone.
|
|
161
|
+
- Capture light/dark screenshots at all three viewport classes. Inspect actual
|
|
162
|
+
layout, not only no-error/no-clipping assertions. A cramped map can pass both.
|
|
163
|
+
- Exercise polygon completion, Save export, external layer-cake activation and Cancel.
|
|
164
|
+
- Confirm import, teardown/remount and both bundled/external modes used by the app.
|
|
165
|
+
|
|
166
|
+
The existing [irrigation harness](../irrigation-draw-mode.html) retains the larger
|
|
167
|
+
secondary-toolbar and external-panel drawing scenarios; do not replace those
|
|
168
|
+
regression checks with screenshots of an idle toolbar.
|