@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,98 @@
|
|
|
1
|
+
# React shims
|
|
2
|
+
|
|
3
|
+
These shims provide React wrappers around the [`<leaflet-geokit>`](../../src/components/LeafletDrawMapElement.ts:17) custom element.
|
|
4
|
+
|
|
5
|
+
There are **two entrypoints**:
|
|
6
|
+
|
|
7
|
+
- External/additive wrapper (host already loads Leaflet/Draw): [`@florasync/leaflet-geokit/react`](../../package.json:9)
|
|
8
|
+
- Bundled/self-provisioned wrapper (package provides Leaflet/Draw): [`@florasync/leaflet-geokit/react-bundled`](../../package.json:9)
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @florasync/leaflet-geokit react react-dom
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`react` and `react-dom` are consumer-provided peer dependencies for these wrappers.
|
|
17
|
+
|
|
18
|
+
## Import
|
|
19
|
+
|
|
20
|
+
External/additive mode:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { ReactLeafletGeoKit } from "@florasync/leaflet-geokit/react";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Bundled/self-provisioned mode:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { ReactLeafletGeoKit } from "@florasync/leaflet-geokit/react-bundled";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { ReactLeafletGeoKit } from "@florasync/leaflet-geokit/react";
|
|
36
|
+
|
|
37
|
+
export function MapEditor() {
|
|
38
|
+
return (
|
|
39
|
+
<ReactLeafletGeoKit
|
|
40
|
+
style={{ width: "100%", height: "420px" }}
|
|
41
|
+
attributes={{
|
|
42
|
+
latitude: 39.7392,
|
|
43
|
+
longitude: -104.9903,
|
|
44
|
+
zoom: 11,
|
|
45
|
+
"draw-polygon": true,
|
|
46
|
+
"draw-rectangle": true,
|
|
47
|
+
"edit-features": true,
|
|
48
|
+
}}
|
|
49
|
+
onChangeText={(text) => {
|
|
50
|
+
console.log(text);
|
|
51
|
+
}}
|
|
52
|
+
onError={(error) => console.error(error)}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Choosing an entrypoint
|
|
59
|
+
|
|
60
|
+
- Use [`@florasync/leaflet-geokit/react`](../../package.json:9) when your app already owns Leaflet + Leaflet.draw runtime and CSS.
|
|
61
|
+
- Use [`@florasync/leaflet-geokit/react-bundled`](../../package.json:9) when you want this package to provide Leaflet + Leaflet.draw.
|
|
62
|
+
|
|
63
|
+
## External Leaflet behavior (`/react`)
|
|
64
|
+
|
|
65
|
+
By default, the wrapper mounts in external/additive mode:
|
|
66
|
+
|
|
67
|
+
- Sets `use-external-leaflet`
|
|
68
|
+
- Sets `skip-leaflet-styles`
|
|
69
|
+
|
|
70
|
+
So your app should load Leaflet + Leaflet.draw assets beforehand.
|
|
71
|
+
|
|
72
|
+
If needed, provide an explicit namespace via `leafletInstance`.
|
|
73
|
+
|
|
74
|
+
## Bundled behavior (`/react-bundled`)
|
|
75
|
+
|
|
76
|
+
By default, the bundled wrapper does **not** set external/additive flags.
|
|
77
|
+
|
|
78
|
+
- Does not set `use-external-leaflet`
|
|
79
|
+
- Does not set `skip-leaflet-styles`
|
|
80
|
+
|
|
81
|
+
This is the simplest path for apps that do not preload Leaflet.
|
|
82
|
+
|
|
83
|
+
## Props (both wrappers)
|
|
84
|
+
|
|
85
|
+
- `attributes`: map of attributes forwarded to `<leaflet-geokit>`
|
|
86
|
+
- `externalLeaflet`: optional override of default wrapper mode (`/react` defaults `true`, `/react-bundled` defaults `false`)
|
|
87
|
+
- `leafletInstance`: explicit Leaflet namespace (`window.L` equivalent)
|
|
88
|
+
- `initialGeoJSONText`: loaded once after `leaflet-draw:ready`
|
|
89
|
+
- `onChangeText`: receives serialized GeoJSON after create/edit/delete/merge
|
|
90
|
+
- `onChangeGeoJSON`: receives parsed FeatureCollection object
|
|
91
|
+
- `onReady`: receives the underlying custom element
|
|
92
|
+
- `onError`: receives normalized `Error` objects
|
|
93
|
+
|
|
94
|
+
## Notes
|
|
95
|
+
|
|
96
|
+
- Ensure the element has a fixed height.
|
|
97
|
+
- For strict ownership by host styles, keep `externalLeaflet` enabled and provide CSS from your app.
|
|
98
|
+
- React wrapper entrypoints do not bundle React runtime code; your app provides the React runtime.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Snapping and live measurements
|
|
2
|
+
|
|
3
|
+
Snapping is opt-in and does not change existing maps. Set the web component
|
|
4
|
+
property before or after connection:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
map.snapping = {
|
|
8
|
+
enabled: true,
|
|
9
|
+
modes: ["vertex", "edge", "grid", "guide"],
|
|
10
|
+
tolerancePx: 12,
|
|
11
|
+
gridSizeMeters: 1,
|
|
12
|
+
gridOrigin: [0, 0], // [longitude, latitude]
|
|
13
|
+
};
|
|
14
|
+
map.measurementOverlay = { enabled: true, autoScale: true };
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Candidates are compared in rendered screen pixels, which keeps the tolerance
|
|
18
|
+
consistent across zoom levels and desktop/touch input. `gridSizeMeters` is a
|
|
19
|
+
physical WGS84 spacing. Grid nodes are stable relative to the fixed
|
|
20
|
+
`gridOrigin` (`[longitude, latitude]`, default `[0, 0]`): latitude is
|
|
21
|
+
quantized by ellipsoidal meridian distance, while longitude uses the WGS84
|
|
22
|
+
parallel scale at the snapped latitude. This keeps adjacent nodes one meter
|
|
23
|
+
apart at realistic latitudes, including 45°, rather than treating longitude
|
|
24
|
+
degrees as latitude degrees.
|
|
25
|
+
|
|
26
|
+
Grid coordinates must remain in WGS84 longitude/latitude ranges, and grid
|
|
27
|
+
snapping is available inside ±89.9° latitude. The default origin is not moved
|
|
28
|
+
to the pointer, so repeated calls produce the same node. Antimeridian wrapping,
|
|
29
|
+
polar coordinates, CRS reprojection, and survey/machine-control accuracy are
|
|
30
|
+
outside this contract; use a local origin and a suitable cell size for
|
|
31
|
+
ordinary editing and planning.
|
|
32
|
+
|
|
33
|
+
Visible registered layers are the only guide sources. Hidden, measurement, and
|
|
34
|
+
currently edited features are excluded. A small marker and status label
|
|
35
|
+
identify the active snap. All listeners and feedback layers are removed on
|
|
36
|
+
cancellation, reconfiguration, and destroy.
|
|
37
|
+
|
|
38
|
+
The measurement overlay uses the same `measurementSystem` state as the ruler.
|
|
39
|
+
`setMeasurementUnits("metric" | "imperial")` refreshes an active overlay while
|
|
40
|
+
retaining the existing ruler behavior. Length, perimeter, and area are derived
|
|
41
|
+
with the exported grower measurement helpers and update while a shape is drawn
|
|
42
|
+
or a vertex is dragged.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Tool capabilities and external controls
|
|
2
|
+
|
|
3
|
+
`map.getToolCapabilities()` synchronously returns a detached `ToolCapabilities`
|
|
4
|
+
snapshot. It is safe before connection (tools report `unavailable/not_ready`).
|
|
5
|
+
Subscribe on the element or a composed ancestor to
|
|
6
|
+
`leaflet-geokit:tool-capabilities-changed`; its `detail` has exactly the same
|
|
7
|
+
shape. Notifications are change-deduplicated; controller changes within one
|
|
8
|
+
microtask are coalesced. Always read an initial snapshot after subscribing.
|
|
9
|
+
|
|
10
|
+
## Snapshot contract
|
|
11
|
+
|
|
12
|
+
`tools` is keyed by every existing `ToolButtonName`: polygon, polyline, rectangle,
|
|
13
|
+
circle, marker, layerCake, move, select, edit, delete, ruler,
|
|
14
|
+
measurementSettings, layerStyle, and save. Each entry contains:
|
|
15
|
+
|
|
16
|
+
- `state`: `enabled`, `disabled` (a prerequisite or host UI restriction), or
|
|
17
|
+
`unavailable` (runtime not ready, missing handler/plugin, or failed runtime).
|
|
18
|
+
- `reason`: null when enabled, otherwise `{ code, message, requirement? }`.
|
|
19
|
+
Codes are stable; messages are explanatory, not identifiers.
|
|
20
|
+
- `active`: whether this tool is the controller's persistent active mode.
|
|
21
|
+
- `groupIds`: deduplicated configured toolbar groups containing this tool.
|
|
22
|
+
Caller-provided command `groupId` values do not create toolbar groups.
|
|
23
|
+
- `hotkey`: actual built-in activation shortcut, currently null for all tools.
|
|
24
|
+
GeoKit does not register letter shortcuts. Leaflet's contextual Escape cancel
|
|
25
|
+
behavior is not a global select shortcut.
|
|
26
|
+
- `commands`: support for `activate` and `deactivate` commands. The existing
|
|
27
|
+
bus accepts both for every tool; `deactivate` always returns to select mode.
|
|
28
|
+
- `commandEnabled`: whether activation may run. The longstanding
|
|
29
|
+
`toolButtonConfig.disabled` option disables buttons, not the imperative API.
|
|
30
|
+
Runtime failures disable buttons but permit an explicit imperative retry.
|
|
31
|
+
- `behavior`: `draw`, `mode`, `action`, or `deactivate`. LayerCake is multi-stage
|
|
32
|
+
drawing; consult [the lifecycle contract](tool-lifecycle.md) for completion.
|
|
33
|
+
|
|
34
|
+
`provider` separately reports `requested`, `active`, `state`, and `reason`.
|
|
35
|
+
Missing HERE credentials, unknown providers, and tile runtime errors are visible
|
|
36
|
+
here even when fallback OSM tiles work. No key, tile URL, or raw provider error
|
|
37
|
+
payload is included. Local geometry tools do **not** require a paid tile
|
|
38
|
+
provider and remain enabled during fallback.
|
|
39
|
+
|
|
40
|
+
`selectedFeatureIds` contains the currently valid host-supplied selection.
|
|
41
|
+
Snapshots and events never expose mutable internal arrays or registry objects.
|
|
42
|
+
|
|
43
|
+
## Requirements and recovery
|
|
44
|
+
|
|
45
|
+
The registry reflects:
|
|
46
|
+
|
|
47
|
+
| Reason code | Meaning / recovery |
|
|
48
|
+
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
49
|
+
| `not_ready` | Wait for initialization or reconnect the element. |
|
|
50
|
+
| `read_only` | Drawing, move, edit and delete need read-only removed. Save/select/ruler remain usable. |
|
|
51
|
+
| `missing_attribute` | Enable the named draw/edit/delete/ruler attribute. Delete also needs `edit-features` because Leaflet.draw owns remove under its edit toolbar. |
|
|
52
|
+
| `unavailable_plugin` | The configured tool's actual handler/plugin is absent. Supply the runtime/plugin and rebuild. |
|
|
53
|
+
| `no_editable_layers` | Move/edit/delete need at least one actual editable layer, not merely a GeoJSON feature count. |
|
|
54
|
+
| `empty_selection` | An opt-in selection prerequisite has no valid selected feature ids. |
|
|
55
|
+
| `missing_provider` | Requested tile provider is not supported. |
|
|
56
|
+
| `missing_api_key` | Requested provider needs credentials; use a supported free provider or configure credentials privately. |
|
|
57
|
+
| `runtime_error` | A tool threw/failed or the requested provider failed. Tool activation may be retried explicitly; successful retry/rebuild clears its failure. Provider change/reconfiguration clears provider failure. |
|
|
58
|
+
| `configured_disabled` | Host disabled the managed button; imperative compatibility API remains available. |
|
|
59
|
+
|
|
60
|
+
Reasons have deterministic precedence: readiness, read-only, attributes, plugin,
|
|
61
|
+
editable layers, selection, provider, runtime error, host-disabled flag. Changes
|
|
62
|
+
after load/add/clear/update/remove, Leaflet create/delete, tool activation,
|
|
63
|
+
configuration, read-only rebuild, and provider reconfiguration are reflected.
|
|
64
|
+
Rapid structural attribute changes are serialized, retaining stored geometry.
|
|
65
|
+
|
|
66
|
+
GeoKit has no global feature-selection UI. Existing layerStyle remains a
|
|
67
|
+
host-owned action/popover, and save still exports an empty collection. To opt
|
|
68
|
+
host actions into stronger prerequisites without breaking those defaults:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
map.toolButtonConfig = {
|
|
72
|
+
layerStyle: { requirements: { selection: true } },
|
|
73
|
+
// Only opt in when YOUR action truly needs the requested provider.
|
|
74
|
+
save: { requirements: { provider: true } },
|
|
75
|
+
};
|
|
76
|
+
map.setToolSelection(["bed-17"]); // Supply ids from your host selection model.
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Unknown/deleted ids are excluded. Clear/load-replace resets selection. These
|
|
80
|
+
opt-in prerequisites also apply to imperative/event activation. No implicit
|
|
81
|
+
selection engine, provider provisioning, or host API wiring is introduced.
|
|
82
|
+
|
|
83
|
+
## Declarative external buttons
|
|
84
|
+
|
|
85
|
+
```html
|
|
86
|
+
<leaflet-geokit id="map" draw-polygon edit-features></leaflet-geokit>
|
|
87
|
+
<button data-tool="polygon" disabled>Draw boundary</button>
|
|
88
|
+
<button data-tool="edit" disabled>Edit boundaries</button>
|
|
89
|
+
<script type="module">
|
|
90
|
+
import "@florasync/leaflet-geokit";
|
|
91
|
+
const map = document.querySelector("#map");
|
|
92
|
+
const buttons = document.querySelectorAll("button[data-tool]");
|
|
93
|
+
const render = () => {
|
|
94
|
+
const { tools } = map.getToolCapabilities();
|
|
95
|
+
for (const button of buttons) {
|
|
96
|
+
const capability = tools[button.dataset.tool];
|
|
97
|
+
button.disabled = capability.state !== "enabled";
|
|
98
|
+
button.title = capability.reason?.message ?? "";
|
|
99
|
+
button.setAttribute("aria-pressed", String(capability.active));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
map.addEventListener("leaflet-geokit:tool-capabilities-changed", render);
|
|
103
|
+
render();
|
|
104
|
+
for (const button of buttons) {
|
|
105
|
+
button.addEventListener("click", () =>
|
|
106
|
+
map.activateTool(button.dataset.tool),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
</script>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The existing `irrigation-draw-mode.html` harness contains working external
|
|
113
|
+
buttons, an empty-layer edit state, and a read-only toggle. Managed toolbar
|
|
114
|
+
buttons consume the same snapshot, including duplicate placements. The
|
|
115
|
+
intentionally unguarded “Try unavailable polyline” button remains a failure-bus
|
|
116
|
+
example, not the recommended capability binding.
|
|
117
|
+
|
|
118
|
+
## Focused verification
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
npm run typecheck
|
|
122
|
+
npm run test:unit:focused -- tests/tool-capabilities.spec.ts tests/tool-lifecycle.spec.ts tests/map-controller.spec.ts tests/element.spec.ts
|
|
123
|
+
npx playwright test --config playwright.capabilities.config.ts --output "$PAPERCLIP_RUN_SCRATCH_DIR/browser-results"
|
|
124
|
+
npm run build
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Outside a Paperclip run, supply a writable output directory yourself. The
|
|
128
|
+
capability Playwright config starts an isolated Vite harness on port 5186 with
|
|
129
|
+
HMR off and shuts it down after the tests. Capability tests use fixture tile
|
|
130
|
+
responses while exercising real Leaflet pointer drawing and public APIs; they
|
|
131
|
+
do not contact paid providers or prove vendor availability.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Public tool command and lifecycle bus
|
|
2
|
+
|
|
3
|
+
GeoKit exposes one framework-agnostic command surface for host controls, managed
|
|
4
|
+
toolbars, and the native Leaflet toolbar. Consumers can use the imperative
|
|
5
|
+
methods or dispatch a typed command event; lifecycle results always leave the
|
|
6
|
+
actual `<leaflet-geokit>` element as bubbling, composed `CustomEvent`s.
|
|
7
|
+
|
|
8
|
+
## Command entry points
|
|
9
|
+
|
|
10
|
+
- `activateTool(tool, options)` starts a tool. `triggerTool` is its
|
|
11
|
+
compatibility alias.
|
|
12
|
+
- `deactivateTool(options)` stops the current persistent tool and returns to
|
|
13
|
+
select mode.
|
|
14
|
+
- Dispatch `leaflet-geokit:tool-command` with `ToolCommandEventDetail` to
|
|
15
|
+
use the event-only API. Its `action` defaults to `activate`; use
|
|
16
|
+
`{ tool: "select", action: "deactivate" }` to stop.
|
|
17
|
+
- `leaflet-geokit:activate-tool`, `leaflet-geokit:trigger-tool`, and
|
|
18
|
+
`leaflet-geokit:deactivate-tool` remain compatibility aliases.
|
|
19
|
+
- Managed toolbar buttons and observed native Leaflet toolbar buttons enter the
|
|
20
|
+
same controller bus. They do not synthesize a second activation.
|
|
21
|
+
|
|
22
|
+
`ToolTriggerOptions` accepts `source`, `groupId`, and an optional
|
|
23
|
+
`commandId`. GeoKit generates a command id when callers omit one. Reuse that
|
|
24
|
+
id only when the calls are intentionally the same logical command; repeated
|
|
25
|
+
commands normally need distinct ids.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import type {
|
|
29
|
+
LeafletDrawMapElementAPI,
|
|
30
|
+
ToolEventDetail,
|
|
31
|
+
} from "@florasync/leaflet-geokit";
|
|
32
|
+
|
|
33
|
+
const map = document.querySelector("leaflet-geokit") as HTMLElement &
|
|
34
|
+
LeafletDrawMapElementAPI;
|
|
35
|
+
|
|
36
|
+
map.addEventListener("leaflet-geokit:tool-failed", (event) => {
|
|
37
|
+
const detail = (event as CustomEvent<ToolEventDetail>).detail;
|
|
38
|
+
console.error(detail.commandId, detail.reason);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await map.activateTool("polygon", {
|
|
42
|
+
source: "field-panel",
|
|
43
|
+
groupId: "outside-controls",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
map.dispatchEvent(
|
|
47
|
+
new CustomEvent("leaflet-geokit:tool-command", {
|
|
48
|
+
bubbles: true,
|
|
49
|
+
composed: true,
|
|
50
|
+
detail: {
|
|
51
|
+
tool: "layerCake",
|
|
52
|
+
source: "field-panel",
|
|
53
|
+
groupId: "outside-controls",
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Lifecycle and ordering
|
|
60
|
+
|
|
61
|
+
Every lifecycle event uses exported `ToolEventDetail`:
|
|
62
|
+
|
|
63
|
+
- `tool`, `action`, `source`, `groupId`, and `commandId` identify the
|
|
64
|
+
command.
|
|
65
|
+
- `previousTool` and `activeTool` are null when there is no persistent mode.
|
|
66
|
+
- `featureIds` is always present. It is empty when no features apply.
|
|
67
|
+
- `geometry` is a GeoJSON `Feature` or `FeatureCollection` snapshot when a
|
|
68
|
+
committed operation has geometry.
|
|
69
|
+
- `reason` explains cancellations and failures.
|
|
70
|
+
- `timestamp` is milliseconds since the Unix epoch.
|
|
71
|
+
|
|
72
|
+
The canonical order is:
|
|
73
|
+
|
|
74
|
+
1. `leaflet-geokit:tool-command` — a normalized request entered the public bus.
|
|
75
|
+
For an event command, the caller's event is this phase; GeoKit enriches its
|
|
76
|
+
mutable detail rather than emitting a duplicate.
|
|
77
|
+
2. `leaflet-geokit:tool-commanded` — the controller accepted the request and
|
|
78
|
+
is attempting it.
|
|
79
|
+
3. Persistent tools emit `tool-started`, then `tool-state-changed` if the
|
|
80
|
+
active tool changed. Action tools emit `tool-completed` immediately.
|
|
81
|
+
4. Interactive commits emit `tool-completed` with ids/geometry. A one-shot
|
|
82
|
+
tool then emits `tool-state-changed` when Leaflet stops it.
|
|
83
|
+
5. Escape, select, and switches emit `tool-cancelled` for the command that was
|
|
84
|
+
active. A real active-state transition emits `tool-state-changed` once.
|
|
85
|
+
6. Unavailable handlers, thrown activation errors, and missing controllers emit
|
|
86
|
+
`tool-failed` with `reason`; they never leave the failed tool active.
|
|
87
|
+
|
|
88
|
+
On a switch, the new command/commanded phases occur first, the previous command
|
|
89
|
+
is cancelled using its original correlation id, and the new command starts.
|
|
90
|
+
Repeating the same persistent tool cancels the old command and starts the new
|
|
91
|
+
one without a false state-change event (the active tool name did not change).
|
|
92
|
+
|
|
93
|
+
The older `tool-trigger-requested`, `tool-triggered`, and
|
|
94
|
+
`tool-trigger-failed` events are still emitted for compatibility and include
|
|
95
|
+
`commandId`. Their presence does not change the canonical ordering above.
|
|
96
|
+
|
|
97
|
+
## Complete tool inventory
|
|
98
|
+
|
|
99
|
+
| Tool | Kind | Activation and terminal behavior |
|
|
100
|
+
| --------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
+
| `polygon` | Persistent, one-shot draw | Starts on Leaflet `drawstart`; created feature completes with one id/Feature; `drawstop` clears active state. Escape cancels. |
|
|
102
|
+
| `polyline` | Persistent, one-shot draw | Same contract as polygon. |
|
|
103
|
+
| `rectangle` | Persistent, one-shot draw | Same contract as polygon. |
|
|
104
|
+
| `circle` | Persistent, one-shot draw | Same contract as polygon. |
|
|
105
|
+
| `marker` | Persistent, one-shot draw | Same contract as polygon. |
|
|
106
|
+
| `layerCake` | Persistent, multi-stage draw | Starts with the base-circle command. Base-circle creation opens `LayerCakeManager` and is not completion. Manager Save completes with all ids and the FeatureCollection. Select/switch destroys the session and cancels the original command. Source/group/id are retained through save. |
|
|
107
|
+
| `move` | Persistent operation mode | Starts once. Each confirmed move completes with the moved id and new Feature. The mode remains active until select/switch/Escape; the existing `tool:move:*` events remain available for pending/confirmed/per-move-cancel observations. |
|
|
108
|
+
| `select` | Deactivation action | Cancels the current persistent command, clears state, then completes the select command. With nothing active it simply completes. |
|
|
109
|
+
| `edit` | Persistent batch mode | Leaflet edit save completes with edited ids and the current FeatureCollection; edit stop clears state. Closing without save cancels. |
|
|
110
|
+
| `delete` | Persistent batch mode | Leaflet delete save completes with deleted ids and the remaining FeatureCollection; delete stop clears state. Closing without save cancels. |
|
|
111
|
+
| `ruler` | Persistent plugin mode | Starts when the ruler toggle becomes active. Select/switch/Escape or the native toggle cancels and clears it. The third-party plugin does not expose a committed measurement geometry event, so GeoKit does not invent one. |
|
|
112
|
+
| `measurementSettings` | Action | Completes when the settings dialog opens. Choosing units continues to emit `tool:ruler:units-changed`; closing the dialog is not a new command. |
|
|
113
|
+
| `layerStyle` | Action | Completes when GeoKit delivers the style action/popover request. Host-owned styling after that point is outside this lifecycle. |
|
|
114
|
+
| `save` | Action | Completes with all current feature ids and a FeatureCollection snapshot, while also preserving `leaflet-draw:export` and `tool:save`. It does not stop the active persistent tool. |
|
|
115
|
+
|
|
116
|
+
## Integration rules
|
|
117
|
+
|
|
118
|
+
Listen on the element or any composed ancestor. Do not read `_controller`,
|
|
119
|
+
Leaflet handler internals, or Shadow DOM-private callbacks. Outside controls can
|
|
120
|
+
start/stop/save and observe failure using only the methods/events above.
|
|
121
|
+
|
|
122
|
+
A `tool-completed` event means an actual action or interactive commit. It is
|
|
123
|
+
never emitted merely because a draw handler was enabled. In particular,
|
|
124
|
+
LayerCake activation and base-circle creation are not reported as completion.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Responsive toolbar layout
|
|
2
|
+
|
|
3
|
+
The layout API is opt-in. Existing groups using `topleft`, `topright`,
|
|
4
|
+
`bottomleft`, `bottomright` (or no position) keep their absolute corner placement,
|
|
5
|
+
orientation, gap, and exact offsets. Existing styling tokens, parts, named icon /
|
|
6
|
+
badge / tooltip slots and tool events continue to work.
|
|
7
|
+
|
|
8
|
+
## Configuration
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
map.toolbarGroups = [
|
|
12
|
+
{
|
|
13
|
+
id: "draw",
|
|
14
|
+
tools: ["polygon", "rectangle", "marker", "select"],
|
|
15
|
+
preset: "responsive",
|
|
16
|
+
position: "topright",
|
|
17
|
+
orientation: "vertical",
|
|
18
|
+
order: 0,
|
|
19
|
+
overflow: "wrap",
|
|
20
|
+
offset: [10, 10],
|
|
21
|
+
responsive: {
|
|
22
|
+
breakpoint: 600,
|
|
23
|
+
position: "bottom-end",
|
|
24
|
+
orientation: "horizontal",
|
|
25
|
+
overflow: "scroll",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{ id: "save", tools: ["save"], preset: "responsive", order: 1 },
|
|
29
|
+
];
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `preset: "zones"` opts into collision-safe placement without automatic movement.
|
|
33
|
+
- `preset: "responsive"` uses the desktop position (default `topright`) at map
|
|
34
|
+
widths >= 600 CSS pixels; below that it becomes a horizontal bottom-end sheet.
|
|
35
|
+
- `responsive` also opts in and accepts `breakpoint`, `position`, `orientation`,
|
|
36
|
+
`order`, `overflow`, and `offset`. It overrides base configuration below the
|
|
37
|
+
breakpoint; omitted mobile position/orientation default to bottom-end/horizontal.
|
|
38
|
+
- Named positions opt in without a preset: `top-start`, `top-end`, `bottom-start`,
|
|
39
|
+
`bottom-end`, `center-end`. Legacy corner aliases work inside either preset.
|
|
40
|
+
- `order` defaults to 0 and sorts groups within their zone (ties keep config order).
|
|
41
|
+
It does not change the order of tools within a group.
|
|
42
|
+
- `overflow: "wrap"` (default) wraps along the configured flex direction;
|
|
43
|
+
`"scroll"` retains a single row/column with native scrollbars. Both are bounded.
|
|
44
|
+
- At map widths below 600, zones occupy separate rows in one column, groups span
|
|
45
|
+
that column, and touch targets default to 48px. `--geokit-tool-size` and direct
|
|
46
|
+
button parts still override that size. The one-column safety breakpoint is
|
|
47
|
+
fixed, independent of the configurable movement breakpoint.
|
|
48
|
+
|
|
49
|
+
## Host CSS, including shadow DOM
|
|
50
|
+
|
|
51
|
+
Group ids produce a named part `toolbar-group-ID` in addition to `toolbar-group`.
|
|
52
|
+
Characters other than letters, digits, underscore and hyphen become hyphens; use
|
|
53
|
+
simple unique ids to avoid part-name collisions. Existing legacy groups retain
|
|
54
|
+
exactly `part="toolbar-group"`; use `[part~="toolbar-group"]` in tests/themes that
|
|
55
|
+
must match both modes.
|
|
56
|
+
|
|
57
|
+
```css
|
|
58
|
+
/* Opt in via preset: "zones", then CSS controls placement. */
|
|
59
|
+
leaflet-geokit::part(toolbar-group-draw) {
|
|
60
|
+
--geokit-toolbar-zone: top-end;
|
|
61
|
+
--geokit-toolbar-order: 2;
|
|
62
|
+
--geokit-toolbar-direction: column;
|
|
63
|
+
--geokit-toolbar-wrap: wrap;
|
|
64
|
+
}
|
|
65
|
+
@media (max-width: 600px) {
|
|
66
|
+
leaflet-geokit::part(toolbar-group-draw) {
|
|
67
|
+
--geokit-toolbar-zone: bottom-end;
|
|
68
|
+
--geokit-toolbar-direction: row;
|
|
69
|
+
--geokit-toolbar-order: -1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
leaflet-geokit {
|
|
73
|
+
--geokit-zone-gap: 8px;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Configuration responds to **map width**; this CSS media-query example responds to
|
|
78
|
+
**viewport width**. CSS zone and order win over configuration. No shadowRoot access
|
|
79
|
+
is needed. `className` continues to support selectors in `themeCss`/`theme-url`, or
|
|
80
|
+
ordinary document selectors for externally managed Leaflet containers. Layout
|
|
81
|
+
styles are installed through the same runtime-independent toolbar style path.
|
|
82
|
+
Changes to host classes/styles, theme styles, viewport size and container size
|
|
83
|
+
schedule a coalesced layout pass. CSSOM `insertRule()` changes that do not mutate
|
|
84
|
+
style nodes should be followed by a host class change or resize.
|
|
85
|
+
|
|
86
|
+
Additional parts: `toolbar-layout`, `toolbar-zone`, `zone-top-start`, `zone-top-end`,
|
|
87
|
+
`zone-center-end`, `zone-bottom-start`, `zone-bottom-end`. Use parts for visual
|
|
88
|
+
styling; overriding their positioning/overflow can invalidate collision safety.
|
|
89
|
+
|
|
90
|
+
## Collision, insets and overflow contract
|
|
91
|
+
|
|
92
|
+
The layout measures visible native Leaflet controls and reserves full top/bottom
|
|
93
|
+
strips, including zoom and attribution. Separate CSS grid cells prevent opposing
|
|
94
|
+
zones colliding; flex stacks prevent same-zone groups colliding. Only occupied
|
|
95
|
+
rows consume space. This deliberately sacrifices some empty corner space to keep
|
|
96
|
+
placement deterministic. Multiple groups share their cell's bounded height and
|
|
97
|
+
scroll when needed. Narrow rows are weighted by their group counts. When the
|
|
98
|
+
available native-chrome-free height is below 100px per group, vertical margins
|
|
99
|
+
collapse and the default zone gap becomes 4px to preserve usable tool space.
|
|
100
|
+
Focused tools are scrolled fully into view, including tools
|
|
101
|
+
that the browser's default focus scrolling would leave partially clipped.
|
|
102
|
+
|
|
103
|
+
Safe areas use `env(safe-area-inset-top/right/bottom/left, 0px)` in addition to
|
|
104
|
+
native-control strips. Hosts can override `--geokit-safe-area-top`,
|
|
105
|
+
`--geokit-safe-area-right`, `--geokit-safe-area-bottom`, and
|
|
106
|
+
`--geokit-safe-area-left` for embedded layouts/testing. Use `viewport-fit=cover`
|
|
107
|
+
when appropriate for the host's mobile viewport policy.
|
|
108
|
+
|
|
109
|
+
In zone mode offsets are nonnegative spacing **inside the allocated zone**, not
|
|
110
|
+
absolute map coordinates. Each axis is capped at 10% of its available dimension
|
|
111
|
+
so oversized offsets cannot remove access. `--geokit-toolbar-offset-x/y` override
|
|
112
|
+
configuration. Legacy groups still use exact map-relative offsets, including
|
|
113
|
+
`bottomleft` / `[25, 35]` => `left: 25px; bottom: 35px`.
|
|
114
|
+
|
|
115
|
+
Use zone mode for **all groups** when requiring collision safety. Legacy absolute
|
|
116
|
+
groups intentionally remain outside this layout; mixing them with zones or
|
|
117
|
+
adding arbitrary absolute host overlays does not provide collision guarantees.
|
|
118
|
+
Native-control strips must leave usable map height, and the host must provide a
|
|
119
|
+
nonzero map size. Extremely crowded layouts can require scrolling both a zone
|
|
120
|
+
and an individual toolbar. Popovers/tooltips retain their existing behavior; they
|
|
121
|
+
are not new grid occupants, and bounded toolbar overflow can clip tooltips/badges
|
|
122
|
+
outside the group (accessible button labels and named slots remain available).
|
|
123
|
+
|
|
124
|
+
## Lifecycle and identity
|
|
125
|
+
|
|
126
|
+
Responsive rearrangement moves existing group/button nodes; it does not recreate
|
|
127
|
+
icons, slots or tool listeners. Keyboard focus is restored if moving a group
|
|
128
|
+
between zones detaches the focused node. Group ids and existing tool-instance ids
|
|
129
|
+
(`group:tool:index`) remain stable. Configuration rerender retains the existing
|
|
130
|
+
renderer semantics: DOM nodes may be recreated, but the same group/tool/index has
|
|
131
|
+
the same logical identity. Reordering the tools changes their index-based ids.
|
|
132
|
+
The layout owner's disconnected callback removes its resize/mutation observers,
|
|
133
|
+
window resize listener, focus listener and queued animation frame. No controller,
|
|
134
|
+
event bus or irrigation-tool lifecycle is replaced.
|
|
135
|
+
|
|
136
|
+
## Verification / real harness
|
|
137
|
+
|
|
138
|
+
Open `/irrigation-draw-mode.html` using the repository Vite server and set the
|
|
139
|
+
public `toolbarGroups` property as above. The automated harness uses that same
|
|
140
|
+
page, real synthetic map tiles, public configuration and actual button clicks.
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
npm run test:unit:focused -- tests/toolbar-layout.spec.ts tests/toolbar-contract.spec.ts
|
|
144
|
+
npm run typecheck
|
|
145
|
+
npm run test:e2e -- --config=playwright.layout.config.ts --output="$PAPERCLIP_RUN_SCRATCH_DIR/playwright-layout"
|
|
146
|
+
npm run build
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Outside Paperclip, replace the output path with a user-writable directory. The
|
|
150
|
+
dedicated Playwright config owns port 5183, refuses to reuse somebody else's
|
|
151
|
+
preview and disables HMR so concurrent edits cannot reset test state. Playwright
|
|
152
|
+
starts/stops this finite server; no background preview is left running. The
|
|
153
|
+
layout browser suite measures map/group/zoom/attribution rectangles, exercises
|
|
154
|
+
configuration and CSS movement in both resize directions, same-zone order,
|
|
155
|
+
all five zones, narrow-width wrapping/scrolling and access to every tool,
|
|
156
|
+
post-movement polygon/save interaction, teardown and rerender. Styling-contract
|
|
157
|
+
regressions retain exact legacy placement assertions. Real device notches are
|
|
158
|
+
not emulated; safe-area overrides test the same inset arithmetic in Chromium.
|