@florasync/leaflet-geokit 0.9.0 → 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/README.md +7 -1
- package/custom-toolbar.html +165 -0
- package/dist/django/index.js.map +1 -1
- package/dist/leaflet-geokit.es.js.map +1 -1
- package/dist/leaflet-geokit.external.es.js.map +1 -1
- package/dist/leaflet-geokit.umd.js.map +1 -1
- package/dist/preact/index-DCKj0r6a.js.map +1 -1
- package/dist/preact-bundled/index.js.map +1 -1
- package/dist/react/index-DCKj0r6a.js.map +1 -1
- package/dist/react-bundled/index.js.map +1 -1
- package/dist/types/components/LeafletDrawMapElement.d.ts +6 -6
- package/dist/types/django/index.d.ts +2 -2
- package/dist/types/external.d.ts +9 -9
- package/dist/types/index.d.ts +9 -9
- package/dist/types/lib/FeatureStore.d.ts +2 -2
- package/dist/types/lib/LayerRegistry.d.ts +1 -1
- package/dist/types/lib/MapController.d.ts +8 -8
- package/dist/types/lib/layer-cake/LayerCakeManager.d.ts +2 -2
- package/dist/types/lib/layer-style-panel.d.ts +1 -1
- package/dist/types/lib/marker-icons.d.ts +1 -1
- package/dist/types/lib/providers.d.ts +1 -1
- package/dist/types/lib/snapping.d.ts +1 -1
- package/dist/types/lib/tool-buttons.d.ts +1 -1
- package/dist/types/lib/tool-capabilities.d.ts +1 -1
- package/dist/types/lib/toolbar-layout.d.ts +1 -1
- 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 +1 -1
- package/dist/types/types/public.d.ts +6 -6
- package/dist/types/utils/geojson-pipeline.d.ts +1 -1
- package/dist/types/utils/geojson.d.ts +1 -1
- package/docs/api-reference.md +249 -0
- package/docs/custom-toolbar.md +168 -0
- package/docs/diagnostics.md +216 -0
- package/docs/grower-measurement.md +23 -0
- package/docs/integration-recipes.md +301 -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/toolbar-layout.md +158 -0
- package/docs/toolbar-styling.md +2 -2
- package/package.json +14 -3
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Architecture: Leaflet GeoKit
|
|
2
|
+
|
|
3
|
+
This is a map of the implemented library, not a future implementation plan.
|
|
4
|
+
GeoKit exposes a framework-agnostic custom element backed by Leaflet and
|
|
5
|
+
Leaflet.draw. The canonical tag is `<leaflet-geokit>`; `<leaflet-draw-map>` is a
|
|
6
|
+
registered compatibility alias. Host applications own persistence, authentication,
|
|
7
|
+
vendor credentials, and framework UI.
|
|
8
|
+
|
|
9
|
+
For task-oriented examples start with [integration recipes](docs/integration-recipes.md).
|
|
10
|
+
The [README](README.md) describes the public API; the source contracts are
|
|
11
|
+
[public.ts](src/types/public.ts), [events.ts](src/types/events.ts), and
|
|
12
|
+
[layers.ts](src/types/layers.ts).
|
|
13
|
+
|
|
14
|
+
## Runtime boundaries
|
|
15
|
+
|
|
16
|
+
```mermaid
|
|
17
|
+
flowchart TD
|
|
18
|
+
Host[Host app / React / Preact / Django shim] --> Element[LeafletDrawMapElement]
|
|
19
|
+
Element --> Controller[MapController]
|
|
20
|
+
Controller --> Leaflet[Leaflet map + Leaflet.draw + ruler]
|
|
21
|
+
Controller --> Store[FeatureStore: GeoJSON by string ID]
|
|
22
|
+
Controller --> Registry[LayerRegistry: named presentation groups]
|
|
23
|
+
Controller --> Cake[LayerCakeManager + CakeBaker]
|
|
24
|
+
Controller --> Toolbar[Toolbar styling / layout / accessibility / capabilities]
|
|
25
|
+
Controller --> Provider[Raster provider or injected basemap adapter]
|
|
26
|
+
Element --> Events[DOM status / diagnostic / draw / tool / layer events]
|
|
27
|
+
Events --> Host
|
|
28
|
+
Pipeline[GeoJSON pipeline / grower geometry helpers] --> Host
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Custom element and lifecycle
|
|
32
|
+
|
|
33
|
+
[LeafletDrawMapElement](src/components/LeafletDrawMapElement.ts) owns Shadow DOM,
|
|
34
|
+
configuration attributes/properties, style injection, status snapshots, and the
|
|
35
|
+
public method/event bridge. On connection it constructs and initializes a
|
|
36
|
+
controller; on disconnection it destroys the controller and removes its listeners.
|
|
37
|
+
Give the host an explicit height and attach readiness/error listeners before
|
|
38
|
+
connecting it. Custom-element registration alone is not map readiness.
|
|
39
|
+
|
|
40
|
+
Public status states are `uninitialized`, `initializing`, `ready`, `loading`, and
|
|
41
|
+
`error`. `leaflet-geokit:status` reports readiness, busy state and feature count;
|
|
42
|
+
`leaflet-geokit:diagnostic` and `leaflet-draw:error` expose failures. Recoverable
|
|
43
|
+
errors can leave the map usable. `dev-overlay` is a compatibility flag, not an
|
|
44
|
+
implemented debugging overlay. Logging defaults to `debug` and supports a custom
|
|
45
|
+
logger; do not assume diagnostic output is appropriate for sensitive data.
|
|
46
|
+
|
|
47
|
+
### Controller and map ownership
|
|
48
|
+
|
|
49
|
+
[MapController](src/lib/MapController.ts) owns the Leaflet map, drawn FeatureGroup,
|
|
50
|
+
feature-to-rendered-layer bindings, basemap, draw/ruler controls, active tool
|
|
51
|
+
commands, and editing sessions. It translates Leaflet changes into store updates
|
|
52
|
+
and public callbacks. It also manages structural reconfiguration, read-only tool
|
|
53
|
+
behavior, snapping, measurement overlays and cleanup. Integrations should use the
|
|
54
|
+
element API rather than reach into the Shadow DOM or private Leaflet handlers.
|
|
55
|
+
|
|
56
|
+
[FeatureStore](src/lib/FeatureStore.ts) is map-agnostic: it stores GeoJSON by string
|
|
57
|
+
ID, provides CRUD and computes coordinate bounds. It does **not** own Leaflet
|
|
58
|
+
layers or bidirectional Leaflet bindings. IDs come from `feature.id`, then
|
|
59
|
+
`properties.id`, then generated UUIDs. Legacy store operations use shallow copies;
|
|
60
|
+
clone a snapshot when retaining an independent editing baseline.
|
|
61
|
+
|
|
62
|
+
[LayerRegistry](src/lib/LayerRegistry.ts) stores detached presentation records:
|
|
63
|
+
name, kind, visibility, order, feature membership and portable style. Hiding a
|
|
64
|
+
group removes its rendered features from the editable group, not the data store.
|
|
65
|
+
The `base` record is reserved. Default GeoJSON export is feature data;
|
|
66
|
+
`preserveLayers: true` explicitly persists registry metadata. See
|
|
67
|
+
[named layers and layer-cake sessions](docs/layers.md) for invariants and restoration.
|
|
68
|
+
|
|
69
|
+
## Data and geometry
|
|
70
|
+
|
|
71
|
+
The element exposes `getGeoJSON`, `importGeoJSON`, `exportGeoJSON`, legacy
|
|
72
|
+
`loadGeoJSON`/`addFeatures`, per-feature CRUD and view-fitting helpers. Import
|
|
73
|
+
supports replace/add behavior, optional validation, named groups and optional
|
|
74
|
+
layer restoration. `loadGeoJSON` replaces without automatically fitting bounds.
|
|
75
|
+
|
|
76
|
+
[geojson-pipeline.ts](src/utils/geojson-pipeline.ts) implements validation,
|
|
77
|
+
normalization, text/URL ingestion, diagnostic export, diff and patch helpers.
|
|
78
|
+
Validation is opt-in on map imports (`validate: true`); its preflight runs after
|
|
79
|
+
the ingest hook and before destructive replacement. Multi/collection geometries
|
|
80
|
+
expand into editing features, with reserved provenance for diagnostic source
|
|
81
|
+
export. Validation is not a general GIS topology/reprojection service. Read the
|
|
82
|
+
[GeoJSON pipeline contract](docs/geojson-pipelines.md) for ID, provenance,
|
|
83
|
+
validation and legacy export differences.
|
|
84
|
+
|
|
85
|
+
[grower-geometry.ts](src/utils/grower-geometry.ts) supplies Turf-backed geometry
|
|
86
|
+
operations, measurements and guides, exported by the root and external entries.
|
|
87
|
+
See [grower geometry](docs/grower-geometry.md) and
|
|
88
|
+
[snapping and measurements](docs/snapping-and-measurements.md). These utilities
|
|
89
|
+
are distinct from the controller's interactive tools: calculating geometry does
|
|
90
|
+
not automatically import it or create a visible map layer.
|
|
91
|
+
|
|
92
|
+
[LayerCakeManager](src/lib/layer-cake/LayerCakeManager.ts) manages concentric-circle
|
|
93
|
+
draft sessions. [CakeBaker](src/lib/layer-cake/CakeBaker.ts) produces saved core/ring
|
|
94
|
+
polygons. The public session API allows external controls to update radii, style
|
|
95
|
+
and name, then save or cancel. A saved polygon group is not an editable draft
|
|
96
|
+
session; see [layers](docs/layers.md).
|
|
97
|
+
|
|
98
|
+
## Tools, events and host-owned UI
|
|
99
|
+
|
|
100
|
+
Tool activation is public: `activateTool`, `triggerTool`, `deactivateTool`, and
|
|
101
|
+
`leaflet-geokit:tool-command` share a correlated lifecycle. Command acknowledgement
|
|
102
|
+
is not necessarily interaction completion. Read
|
|
103
|
+
[tool lifecycle](docs/tool-lifecycle.md) for commanded/started/completed/cancelled/
|
|
104
|
+
failed events and [tool capabilities](docs/tool-capabilities.md) for readiness,
|
|
105
|
+
read-only, selection and provider prerequisites.
|
|
106
|
+
|
|
107
|
+
Existing `leaflet-draw:ready`, `created`, `edited`, `deleted`, `ingest`, `export`,
|
|
108
|
+
and `error` events coexist with the newer tool and layer event families.
|
|
109
|
+
`leaflet-geokit:layers-changed` drives a host sidebar;
|
|
110
|
+
`leaflet-geokit:layer-style-request` is synchronously cancelable so a host can
|
|
111
|
+
replace the built-in style panel. Listen on the element: not every legacy event
|
|
112
|
+
bubbles. Event constants and payload types are exported from root and external.
|
|
113
|
+
|
|
114
|
+
Managed `toolbarGroups` and `toolButtonConfig` are data-driven; visual customization
|
|
115
|
+
uses CSS custom properties, parts, named slots and optional trusted renderers.
|
|
116
|
+
Do not depend on generated Leaflet class order or private DOM layout. Dedicated
|
|
117
|
+
contracts are maintained in:
|
|
118
|
+
|
|
119
|
+
- [Toolbar styling](docs/toolbar-styling.md): tokens, parts, states, icons and slots.
|
|
120
|
+
- [Toolbar layout](docs/toolbar-layout.md): zones, responsive placement and overflow.
|
|
121
|
+
- [Accessibility](docs/accessibility.md): labels, focus, keyboard and touch behavior.
|
|
122
|
+
|
|
123
|
+
## Providers and security
|
|
124
|
+
|
|
125
|
+
[TileProviderFactory](src/lib/TileProviderFactory.ts) retains OSM/HERE and custom
|
|
126
|
+
raster URL behavior. [providers.ts](src/lib/providers.ts) exports raster factories,
|
|
127
|
+
a dependency-injected MapLibre basemap shim, and configuration diagnostics.
|
|
128
|
+
`setBasemapAdapter` swaps only the basemap after readiness; geometry and
|
|
129
|
+
Leaflet.draw remain owned by GeoKit. Reconnection restores raster configuration.
|
|
130
|
+
|
|
131
|
+
`DrawEngineAdapter` is a design port, not an implemented replacement drawing
|
|
132
|
+
engine. The MapLibre seam does not bundle a WebGL renderer, PMTiles transport,
|
|
133
|
+
offline cache, Google Maps support or vendor provisioning. The
|
|
134
|
+
[provider guide](docs/providers.md) describes the optional bridge, teardown,
|
|
135
|
+
attribution and production-verification obligations; the
|
|
136
|
+
[Google adapter spike](docs/google-maps-adapter-spike.md) records a separate study.
|
|
137
|
+
|
|
138
|
+
Treat icon/popover HTML, attribution, theme CSS and adapter code as trusted host
|
|
139
|
+
input. Sanitize untrusted content. Browser keys are visible even when assigned
|
|
140
|
+
through properties; never ship server credentials. Hosts own URL allowlists,
|
|
141
|
+
CORS, upload limits, persistence authorization and concurrency controls.
|
|
142
|
+
|
|
143
|
+
## Package entries and SSR
|
|
144
|
+
|
|
145
|
+
[package.json](package.json) is authoritative for supported subpaths.
|
|
146
|
+
|
|
147
|
+
| Entry | Responsibility | Server import boundary |
|
|
148
|
+
| ----------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
|
149
|
+
| `@florasync/leaflet-geokit` | Bundled browser component, types, pipeline/geometry/provider helpers | Browser-only runtime registration |
|
|
150
|
+
| `/external` | Browser component with Leaflet/Draw/ruler JS externalized | Browser-only; not an SSR entry |
|
|
151
|
+
| `/react`, `/preact` | Additive framework wrappers; host-owned Leaflet assets | Wrapper module import is SSR-safe; registration is deferred to effects |
|
|
152
|
+
| `/react-bundled`, `/preact-bundled` | Self-provisioned framework wrappers | Eager root import; browser-only |
|
|
153
|
+
| `/django` | Browser textarea/form bridge (`initDjangoGeokit`) | Eager root import; browser-only |
|
|
154
|
+
|
|
155
|
+
Both browser component entries directly access `customElements`; the element
|
|
156
|
+
extends `HTMLElement` and its runtime imports the mapping stack. Pure helper
|
|
157
|
+
implementations do **not** make a root named import SSR-safe. There is no exported
|
|
158
|
+
`/utils`, `/geojson`, `/providers` or `/ssr` runtime subpath. Type-only root imports
|
|
159
|
+
are erased by TypeScript. Use client-only dynamic imports for browser entries.
|
|
160
|
+
|
|
161
|
+
The additive wrappers use [ensure-element.ts](src/shims/ensure-element.ts) to load
|
|
162
|
+
the root lazily in the browser. Their SSR-safe module import does not mean a map
|
|
163
|
+
renders on the server. React/Preact runtimes remain consumer-provided optional
|
|
164
|
+
peers. See the [integration recipes](docs/integration-recipes.md) and existing
|
|
165
|
+
[React](docs/shims/react.md), [Preact](docs/shims/preact.md), and
|
|
166
|
+
[Django](docs/shims/django.md) guides.
|
|
167
|
+
|
|
168
|
+
## Build, assets and verification
|
|
169
|
+
|
|
170
|
+
The build emits declarations and uses separate Vite configurations for the root,
|
|
171
|
+
external, Django and framework entries. Root output includes ESM/UMD; the other
|
|
172
|
+
exported entries are ESM. Vite targets ES2019. Bundled mode injects Leaflet/Draw
|
|
173
|
+
styles inside Shadow DOM and configures marker assets. External hosts must supply
|
|
174
|
+
a compatible shared Leaflet stack; opting out of injected styles does not make
|
|
175
|
+
ordinary document CSS cross the Shadow DOM boundary.
|
|
176
|
+
|
|
177
|
+
Vitest unit/integration tests and Playwright browser suites are present, not
|
|
178
|
+
planned work. [tests](tests) cover stores, pipelines, providers, lifecycle,
|
|
179
|
+
wrappers and presentation contracts; [e2e](e2e) exercises real map interactions.
|
|
180
|
+
HTML harnesses include `irrigation-draw-mode.html`, `layer-manager.html`,
|
|
181
|
+
`external.html`, and the React/Preact variants.
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
npm run typecheck
|
|
185
|
+
npm run test:unit
|
|
186
|
+
npm run build
|
|
187
|
+
npm run test:e2e
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Use `npm run test:unit:focused -- tests/<suite>.spec.ts` for a targeted check
|
|
191
|
+
without global coverage thresholds. Specialized Playwright configs exist for
|
|
192
|
+
layers, providers, layout, touch, accessibility, capabilities, snapping and
|
|
193
|
+
release checks. Their fixture-based passes do not validate live vendor service
|
|
194
|
+
availability. [PUBLISHING.md](PUBLISHING.md) owns release instructions and
|
|
195
|
+
[CHANGELOG.md](CHANGELOG.md) records shipped changes.
|
package/README.md
CHANGED
|
@@ -14,6 +14,11 @@ Primary sources
|
|
|
14
14
|
|
|
15
15
|
Documentation quick-links
|
|
16
16
|
|
|
17
|
+
- Branded toolbar, external layer-cake button, trust boundaries and screenshot checklist: [docs/custom-toolbar.md](docs/custom-toolbar.md); runnable [plain HTML example](custom-toolbar.html).
|
|
18
|
+
- Public API tables: [docs/api-reference.md](docs/api-reference.md).
|
|
19
|
+
- Integration recipes (including SSR): [docs/integration-recipes.md](docs/integration-recipes.md).
|
|
20
|
+
- Diagnostic event catalog and troubleshooting: [docs/diagnostics.md](docs/diagnostics.md).
|
|
21
|
+
- Release and packed-consumer verification: [docs/release-verification.md](docs/release-verification.md).
|
|
17
22
|
- Provider v2 contracts, diagnostics, MapLibre/PMTiles shim and security: [docs/providers.md](docs/providers.md)
|
|
18
23
|
- Optional Google Maps adapter spike: [docs/google-maps-adapter-spike.md](docs/google-maps-adapter-spike.md)
|
|
19
24
|
- Validated GeoJSON adapters, metadata round trips, diff/patch: [docs/geojson-pipelines.md](docs/geojson-pipelines.md)
|
|
@@ -638,7 +643,8 @@ map.themeCss = `
|
|
|
638
643
|
The [complete styling contract](docs/toolbar-styling.md)
|
|
639
644
|
documents all tokens/defaults, slots, state semantics, native-control boundaries,
|
|
640
645
|
and placement/visibility behavior. Try the default/CSS/config/mixed selector in
|
|
641
|
-
`irrigation-draw-mode.html`.
|
|
646
|
+
`irrigation-draw-mode.html`. See [responsive zones and overflow](docs/toolbar-layout.md)
|
|
647
|
+
for the implemented layout builder.
|
|
642
648
|
|
|
643
649
|
#### External Tool Triggers
|
|
644
650
|
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>GeoKit branded toolbar recipe</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 1rem;
|
|
11
|
+
font-family: system-ui, sans-serif;
|
|
12
|
+
background: #f4f8f2;
|
|
13
|
+
color: #183b27;
|
|
14
|
+
}
|
|
15
|
+
nav,
|
|
16
|
+
.actions {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-wrap: wrap;
|
|
19
|
+
gap: 0.75rem;
|
|
20
|
+
margin-bottom: 1rem;
|
|
21
|
+
}
|
|
22
|
+
nav a {
|
|
23
|
+
color: inherit;
|
|
24
|
+
text-underline-offset: 0.2em;
|
|
25
|
+
}
|
|
26
|
+
button {
|
|
27
|
+
min-height: 44px;
|
|
28
|
+
padding: 0.5rem 1rem;
|
|
29
|
+
border: 1px solid currentColor;
|
|
30
|
+
border-radius: 0.75rem;
|
|
31
|
+
background: #edf6ee;
|
|
32
|
+
color: #183b27;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
}
|
|
35
|
+
button:focus-visible {
|
|
36
|
+
outline: 3px solid #287d47;
|
|
37
|
+
outline-offset: 3px;
|
|
38
|
+
}
|
|
39
|
+
button:disabled {
|
|
40
|
+
opacity: 0.5;
|
|
41
|
+
cursor: not-allowed;
|
|
42
|
+
}
|
|
43
|
+
leaflet-geokit {
|
|
44
|
+
display: block;
|
|
45
|
+
height: 65vh;
|
|
46
|
+
min-height: 320px;
|
|
47
|
+
width: 100%;
|
|
48
|
+
--geokit-tool-size: 48px;
|
|
49
|
+
--geokit-tool-radius: 12px;
|
|
50
|
+
--geokit-tool-background: #edf6ee;
|
|
51
|
+
--geokit-tool-color: #183b27;
|
|
52
|
+
--geokit-tool-focus-ring: 3px solid #287d47;
|
|
53
|
+
--geokit-toolbar-background: #f4f8f2;
|
|
54
|
+
--geokit-toolbar-gap: 8px;
|
|
55
|
+
}
|
|
56
|
+
leaflet-geokit::part(toolbar-group) {
|
|
57
|
+
border: 1px solid #287d47;
|
|
58
|
+
}
|
|
59
|
+
@media (prefers-color-scheme: dark) {
|
|
60
|
+
body {
|
|
61
|
+
background: #15261b;
|
|
62
|
+
color: #e0f1de;
|
|
63
|
+
}
|
|
64
|
+
button {
|
|
65
|
+
background: #203d2a;
|
|
66
|
+
color: #e0f1de;
|
|
67
|
+
}
|
|
68
|
+
leaflet-geokit {
|
|
69
|
+
--geokit-tool-background: #203d2a;
|
|
70
|
+
--geokit-tool-color: #e0f1de;
|
|
71
|
+
--geokit-toolbar-background: #15261b;
|
|
72
|
+
--geokit-tool-hover-background: #31563c;
|
|
73
|
+
--geokit-tool-focus-ring: 3px solid #9fdaaa;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
@media (prefers-reduced-motion: reduce) {
|
|
77
|
+
leaflet-geokit::part(toolbar-button) {
|
|
78
|
+
transition: none;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
</style>
|
|
82
|
+
</head>
|
|
83
|
+
<body>
|
|
84
|
+
<nav aria-label="Recipe navigation">
|
|
85
|
+
<a href="/">Dev harness</a
|
|
86
|
+
><a href="/docs/custom-toolbar.md">Toolbar recipe</a>
|
|
87
|
+
</nav>
|
|
88
|
+
<h1>Growing-space tools</h1>
|
|
89
|
+
<div class="actions">
|
|
90
|
+
<button id="cake" disabled>Build layered zone</button
|
|
91
|
+
><button id="cancel" disabled>Cancel tool</button>
|
|
92
|
+
</div>
|
|
93
|
+
<p id="status" role="status">Loading map…</p>
|
|
94
|
+
<p id="export-status" role="status"></p>
|
|
95
|
+
<leaflet-geokit
|
|
96
|
+
id="map"
|
|
97
|
+
draw-polygon
|
|
98
|
+
draw-rectangle
|
|
99
|
+
draw-marker
|
|
100
|
+
draw-layer-cake
|
|
101
|
+
></leaflet-geokit>
|
|
102
|
+
<script type="module">
|
|
103
|
+
// In a consumer bundler use: import "@florasync/leaflet-geokit";
|
|
104
|
+
import "/src/index.ts";
|
|
105
|
+
const map = document.querySelector("#map");
|
|
106
|
+
const cake = document.querySelector("#cake");
|
|
107
|
+
const cancel = document.querySelector("#cancel");
|
|
108
|
+
const status = document.querySelector("#status");
|
|
109
|
+
// Developer-owned constant, never interpolated user HTML.
|
|
110
|
+
const leaf =
|
|
111
|
+
'<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-width="2" d="M5 19C2 7 10 3 20 4c0 10-5 17-15 15Zm0 0L16 8"/></svg>';
|
|
112
|
+
map.toolButtonConfig = {
|
|
113
|
+
polygon: {
|
|
114
|
+
title: "Draw growing space",
|
|
115
|
+
ariaLabel: "Draw growing space",
|
|
116
|
+
className: "flora-primary",
|
|
117
|
+
iconHtml: leaf,
|
|
118
|
+
popover: {
|
|
119
|
+
title: "Boundary",
|
|
120
|
+
body: "Click corners, then the first point to finish.",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
save: {
|
|
124
|
+
title: "Save growing spaces",
|
|
125
|
+
ariaLabel: "Save growing spaces",
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
map.toolbarGroups = [
|
|
129
|
+
{
|
|
130
|
+
id: "grow",
|
|
131
|
+
tools: ["polygon", "select", "save"],
|
|
132
|
+
position: "bottomleft",
|
|
133
|
+
orientation: "horizontal",
|
|
134
|
+
offset: [12, 12],
|
|
135
|
+
hideDefaultToolbar: true,
|
|
136
|
+
ariaLabel: "Growing-space tools",
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
map.themeCss =
|
|
140
|
+
'[data-geokit-tool="polygon"].flora-primary { --geokit-tool-radius: 50%; }';
|
|
141
|
+
function refresh() {
|
|
142
|
+
const state = map.getToolCapabilities().tools.layerCake;
|
|
143
|
+
cake.disabled = state.state !== "enabled";
|
|
144
|
+
cake.title = state.reason?.message ?? "Build layered zone";
|
|
145
|
+
cancel.disabled = !map.status.ready;
|
|
146
|
+
status.textContent = map.status.ready
|
|
147
|
+
? "Ready to draw"
|
|
148
|
+
: "Loading map…";
|
|
149
|
+
}
|
|
150
|
+
map.addEventListener("leaflet-geokit:tool-capabilities-changed", refresh);
|
|
151
|
+
map.addEventListener("leaflet-geokit:status", refresh);
|
|
152
|
+
cake.addEventListener("click", async () => {
|
|
153
|
+
await map.activateTool("layerCake", { source: "external-recipe" });
|
|
154
|
+
});
|
|
155
|
+
cancel.addEventListener("click", async () => {
|
|
156
|
+
await map.deactivateTool({ source: "external-recipe" });
|
|
157
|
+
});
|
|
158
|
+
map.addEventListener("leaflet-draw:export", (event) => {
|
|
159
|
+
document.querySelector("#export-status").textContent =
|
|
160
|
+
`Exported ${event.detail.geoJSON.features.length} growing spaces; host owns persistence.`;
|
|
161
|
+
});
|
|
162
|
+
refresh();
|
|
163
|
+
</script>
|
|
164
|
+
</body>
|
|
165
|
+
</html>
|