@florasync/leaflet-geokit 0.8.0 → 0.8.2

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +362 -58
  3. package/dist/django/index.js +5335 -3723
  4. package/dist/django/index.js.map +1 -1
  5. package/dist/leaflet-geokit.es.js +5196 -3595
  6. package/dist/leaflet-geokit.es.js.map +1 -1
  7. package/dist/leaflet-geokit.external.es.js +2719 -1118
  8. package/dist/leaflet-geokit.external.es.js.map +1 -1
  9. package/dist/leaflet-geokit.umd.js +17 -17
  10. package/dist/leaflet-geokit.umd.js.map +1 -1
  11. package/dist/preact/{index-CudTfo4O.js → index-DCGBWrrm.js} +2671 -1057
  12. package/dist/preact/index-DCGBWrrm.js.map +1 -0
  13. package/dist/preact/index.js +34 -32
  14. package/dist/preact/index.js.map +1 -1
  15. package/dist/preact-bundled/index.js +5326 -3710
  16. package/dist/preact-bundled/index.js.map +1 -1
  17. package/dist/react/{index-CudTfo4O.js → index-DCGBWrrm.js} +2671 -1057
  18. package/dist/react/index-DCGBWrrm.js.map +1 -0
  19. package/dist/react/index.js +35 -33
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react-bundled/index.js +5326 -3710
  22. package/dist/react-bundled/index.js.map +1 -1
  23. package/dist/types/{src/components → components}/LeafletDrawMapElement.d.ts +40 -5
  24. package/dist/types/{src/django → django}/index.d.ts +2 -2
  25. package/dist/types/external.d.ts +4 -0
  26. package/dist/types/index.d.ts +4 -0
  27. package/dist/types/{src/lib → lib}/FeatureStore.d.ts +2 -2
  28. package/dist/types/{src/lib → lib}/MapController.d.ts +48 -6
  29. package/dist/types/{src/lib → lib}/layer-cake/LayerCakeManager.d.ts +1 -1
  30. package/dist/types/lib/marker-icons.d.ts +27 -0
  31. package/dist/types/lib/tool-buttons.d.ts +11 -0
  32. package/dist/types/{src/preact → preact}/core.d.ts +6 -2
  33. package/dist/types/{src/preact → preact}/index.d.ts +1 -1
  34. package/dist/types/{src/preact-bundled → preact-bundled}/index.d.ts +3 -3
  35. package/dist/types/{src/react → react}/core.d.ts +6 -2
  36. package/dist/types/{src/react → react}/index.d.ts +1 -1
  37. package/dist/types/{src/react-bundled → react-bundled}/index.d.ts +3 -3
  38. package/dist/types/{src/types → types}/events.d.ts +34 -6
  39. package/dist/types/{src/types → types}/public.d.ts +130 -5
  40. package/dist/types/{src/utils → utils}/geojson.d.ts +10 -0
  41. package/package.json +6 -3
  42. package/dist/preact/index-CudTfo4O.js.map +0 -1
  43. package/dist/react/index-CudTfo4O.js.map +0 -1
  44. package/dist/types/e2e/component.spec.d.ts +0 -1
  45. package/dist/types/e2e/dummy.spec.d.ts +0 -1
  46. package/dist/types/e2e/tool-events-harness.spec.d.ts +0 -1
  47. package/dist/types/e2e/tool-hooks.spec.d.ts +0 -1
  48. package/dist/types/src/external.d.ts +0 -4
  49. package/dist/types/src/index.d.ts +0 -4
  50. package/dist/types/tests/bbox-more.spec.d.ts +0 -1
  51. package/dist/types/tests/component-api-more.spec.d.ts +0 -1
  52. package/dist/types/tests/component-branch-coverage.spec.d.ts +0 -1
  53. package/dist/types/tests/component-delegation.spec.d.ts +0 -1
  54. package/dist/types/tests/component-events.spec.d.ts +0 -1
  55. package/dist/types/tests/component-io.spec.d.ts +0 -1
  56. package/dist/types/tests/component-tile-provider.spec.d.ts +0 -1
  57. package/dist/types/tests/django-shim.spec.d.ts +0 -1
  58. package/dist/types/tests/draw-cake.spec.d.ts +0 -1
  59. package/dist/types/tests/draw-move.spec.d.ts +0 -1
  60. package/dist/types/tests/eachcoord.spec.d.ts +0 -1
  61. package/dist/types/tests/element.spec.d.ts +0 -1
  62. package/dist/types/tests/ensure-element.spec.d.ts +0 -1
  63. package/dist/types/tests/external-entry.spec.d.ts +0 -1
  64. package/dist/types/tests/featureStore-more.spec.d.ts +0 -1
  65. package/dist/types/tests/featureStore.spec.d.ts +0 -1
  66. package/dist/types/tests/framework-runtime-externalization.spec.d.ts +0 -1
  67. package/dist/types/tests/geodesic.spec.d.ts +0 -1
  68. package/dist/types/tests/geojson-merge.spec.d.ts +0 -1
  69. package/dist/types/tests/geojson-more.spec.d.ts +0 -1
  70. package/dist/types/tests/geojson.spec.d.ts +0 -1
  71. package/dist/types/tests/layer-cake-baker.spec.d.ts +0 -1
  72. package/dist/types/tests/layer-cake-controls.spec.d.ts +0 -1
  73. package/dist/types/tests/layer-cake-editing.spec.d.ts +0 -1
  74. package/dist/types/tests/layer-cake-manager.spec.d.ts +0 -1
  75. package/dist/types/tests/leaflet-assets.spec.d.ts +0 -1
  76. package/dist/types/tests/leaflet-draw-circle-resize-patch.spec.d.ts +0 -1
  77. package/dist/types/tests/leaflet-guards.spec.d.ts +0 -1
  78. package/dist/types/tests/logger-more.spec.d.ts +0 -1
  79. package/dist/types/tests/logger.spec.d.ts +0 -1
  80. package/dist/types/tests/map-controller.spec.d.ts +0 -1
  81. package/dist/types/tests/mapcontroller-merge.spec.d.ts +0 -1
  82. package/dist/types/tests/preact-bundled-shim.spec.d.ts +0 -1
  83. package/dist/types/tests/preact-shim.spec.d.ts +0 -1
  84. package/dist/types/tests/react-bundled-shim.spec.d.ts +0 -1
  85. package/dist/types/tests/react-shim.spec.d.ts +0 -1
  86. package/dist/types/tests/ruler.spec.d.ts +0 -1
  87. package/dist/types/tests/tile-provider-factory.spec.d.ts +0 -1
  88. package/dist/types/vite.config.d.ts +0 -2
  89. package/dist/types/vite.config.external.d.ts +0 -2
  90. package/dist/types/vite.config.preact-bundled.d.ts +0 -2
  91. package/dist/types/vite.config.preact.d.ts +0 -2
  92. package/dist/types/vite.config.react-bundled.d.ts +0 -2
  93. package/dist/types/vite.config.react.d.ts +0 -2
  94. /package/dist/types/{src/lib → lib}/TileProviderFactory.d.ts +0 -0
  95. /package/dist/types/{src/lib → lib}/draw/L.Draw.Cake.d.ts +0 -0
  96. /package/dist/types/{src/lib → lib}/draw/L.Draw.Move.d.ts +0 -0
  97. /package/dist/types/{src/lib → lib}/draw/toolbar-patch.d.ts +0 -0
  98. /package/dist/types/{src/lib → lib}/layer-cake/CakeBaker.d.ts +0 -0
  99. /package/dist/types/{src/lib → lib}/layer-cake/bindCakeControls.d.ts +0 -0
  100. /package/dist/types/{src/lib → lib}/layer-cake/ensureCircleEditable.d.ts +0 -0
  101. /package/dist/types/{src/lib → lib}/leaflet-assets.d.ts +0 -0
  102. /package/dist/types/{src/shims → shims}/ensure-element.d.ts +0 -0
  103. /package/dist/types/{src/state → state}/types.d.ts +0 -0
  104. /package/dist/types/{src/utils → utils}/geodesic.d.ts +0 -0
  105. /package/dist/types/{src/utils → utils}/leaflet-guards.d.ts +0 -0
  106. /package/dist/types/{src/utils → utils}/logger.d.ts +0 -0
  107. /package/dist/types/{src/utils → utils}/ruler.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -2,9 +2,29 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.8.2 - 2026-08-24
6
+
7
+ - Added `save` as a first-class custom toolbar tool; activating it emits `leaflet-draw:export` with the current editable GeoJSON so host apps can persist map geometry from branded controls.
8
+ - Custom `toolbarGroups` now hide duplicate built-in Leaflet.draw/ruler toolbars by default, with per-group `hideDefaultToolbar: false` escape hatch.
9
+ - Replaced text fallback glyphs in custom toolbar groups with built-in SVG icons for every supported tool so incomplete host configs still render usable controls.
10
+ - Updated the irrigation draw harness and E2E coverage to prove custom draw/select/save controls work without duplicate default toolbars.
11
+
12
+ ## 0.8.1 - 2026-07-15
13
+
14
+ - Added `toolbarGroups` / `toolbar-groups` for multiple independent map toolbar groups with Leaflet-like corner placement.
15
+ - Expanded `toolButtonConfig` / `tool-button-config` with stable `data-geokit-tool` hooks plus custom icons, labels, theme classes, icon renderers, and popover guidance for draw/edit/select/layer-style workflows.
16
+ - Added `activateTool(...)` / `deactivateTool(...)` plus public tool trigger events so outside DOM controls can enter and leave draw mode without private Leaflet internals; `triggerTool(...)` remains as a back-compat activation alias.
17
+ - Documented the public marker icon customization API in `README.md`, including HTML attributes, `markerIconConfig` precedence, non-fatal fallback behavior, and icon asset guidance for package consumers.
18
+ - Added `icon-customization.html` to the multi-page harness with deterministic local tiles, a default marker reference map, and a custom SVG marker comparison map.
19
+ - Added focused Playwright visual coverage for icon customization so missing assets, hidden icons, draw-marker regressions, and default-icon fallbacks fail in headless Chromium.
20
+ - Added `irrigation-draw-mode.html` and focused Playwright coverage for external panel activation and secondary toolbar polygon drawing.
21
+ - Rewrote emitted declaration imports during packaging so consumer entrypoints no longer leak internal `@src/*` aliases.
5
22
  - Added optional Spec Kitty bootstrap scaffolding via [`.kittify/README.md`](.kittify/README.md) for future spec-driven workflows.
6
23
  - Added non-blocking Spec Kitty helper scripts in [`package.json`](package.json) (`spec-kitty:init`, `spec-kitty:doctor`) with no impact on existing CI/release steps.
7
24
  - Updated [`.gitignore`](.gitignore) to exclude Spec Kitty/agent runtime state while keeping source artifacts commit-friendly.
25
+
26
+ ## 0.8.0 - 2026-04-11
27
+
8
28
  - Added `draw-move` support to all dev harness variants so the Move/Translate toolbar tool is visible in Bundled WC, External WC, React, React (Bundled), Preact, and Preact (Bundled) demos.
9
29
  - Improved Move tool drag stability by anchoring translation to the initial drag-start pointer location, reducing jitter while repositioning GeoJSON features.
10
30
  - Kept Move confirmation workflow (`Save`/`Cancel`) and ensured docs/examples now include `draw-move` in supported draw attributes.
package/README.md CHANGED
@@ -71,6 +71,7 @@ The dev harness is a multi-page environment that allows you to prototype and tes
71
71
  - **Bundled WC**: Standard web component with all dependencies included.
72
72
  - **External WC**: Web component using external Leaflet/Draw from a CDN.
73
73
  - **Preact / React**: First-class wrappers for Preact and React, testing both bundled and external dependency models.
74
+ - **Icon Customization**: Deterministic blank-tile comparison page for default versus custom marker assets, used by the focused Playwright visual gate.
74
75
 
75
76
  Use the navigation bar at the top of the harness to switch between these environments. This is the best way to verify changes across different framework integrations and dependency models.
76
77
 
@@ -182,11 +183,13 @@ Scripts (see [package.json](package.json))
182
183
  - npm run dev — Vite dev server
183
184
  - npm run build — type declarations + Vite build
184
185
  - npm run build:analyze — generate per-target bundle reports in dist/stats/\*.html
185
- - npm run test:unit — Vitest (happy-dom)
186
+ - npm run test:unit — full Vitest (happy-dom) suite with coverage thresholds
187
+ - npm run test:unit:focused -- tests/path.spec.ts — focused Vitest gate without global coverage thresholds; use this for narrow handoffs where the full suite is not the acceptance gate
186
188
  - npm run typecheck — TypeScript noEmit
187
189
  - npm run lint — ESLint (strict TS rules)
188
190
  - npm run format — Prettier write
189
- - npm run test:e2e — Playwright (currently a minimal smoke test under e2e/)
191
+ - npm run test:e2e — Playwright coverage for harness smoke, draw runtime, toolbar hooks, and component integration under e2e/
192
+ - npm run test:e2e:polling -- e2e/icon-customization.spec.ts — Playwright with `CHOKIDAR_USEPOLLING=true`; use this on dev hosts that hit Vite `ENOSPC` watcher exhaustion before the browser tests start
190
193
 
191
194
  Optional workflow tooling
192
195
 
@@ -324,21 +327,104 @@ Control editing and deletion of existing features:
324
327
  <leaflet-geokit prefer-canvas="false"></leaflet-geokit>
325
328
  ```
326
329
 
330
+ #### Marker Icon Customization
331
+
332
+ Customize the marker asset used for both loaded `Point`/`MultiPoint` features and
333
+ new markers created through `draw-marker`:
334
+
335
+ - **`marker-icon-url`** (string): Required to enable custom markers. Supports absolute URLs, relative URLs, `data:` URLs, and `blob:` URLs.
336
+ - **`marker-icon-retina-url`** (string, optional): High-DPI icon URL. Falls back to `marker-icon-url` when omitted or invalid.
337
+ - **`marker-shadow-url`** (string, optional): Optional marker shadow URL. Dropped when omitted or invalid.
338
+ - **`marker-icon-size`** (string tuple, optional): Icon size as `"width,height"`. Default: `"25,41"`.
339
+ - **`marker-icon-anchor`** (string tuple, optional): Anchor point as `"x,y"`. Default: `"12,41"`.
340
+ - **`marker-popup-anchor`** (string tuple, optional): Popup anchor as `"x,y"`. Default: `"1,-34"`.
341
+
342
+ ```html
343
+ <leaflet-geokit
344
+ draw-marker
345
+ marker-icon-url="/icons/field-pin.svg"
346
+ marker-icon-retina-url="/icons/field-pin@2x.svg"
347
+ marker-icon-size="32,40"
348
+ marker-icon-anchor="16,40"
349
+ marker-popup-anchor="0,-34"
350
+ ></leaflet-geokit>
351
+ ```
352
+
353
+ Behavior notes:
354
+
355
+ - `marker-icon-url` is the activation switch. If it is missing, empty, or invalid, GeoKit keeps the default Leaflet marker.
356
+ - Invalid `marker-icon-retina-url`, `marker-shadow-url`, or tuple attributes degrade individually to safe defaults instead of disabling the map.
357
+ - Relative URLs resolve against `document.baseURI`, so app-served static assets work without extra rewriting.
358
+ - Attribute normalization failures emit [`leaflet-draw:error`](src/types/events.ts:42) with a non-fatal message so hosts can log or surface the problem.
359
+
360
+ Asset guidance:
361
+
362
+ - Prefer app-bundled assets, same-origin static files, or vetted `data:`/`blob:` URLs.
363
+ - Avoid passing arbitrary user-supplied or third-party tracking URLs directly into the icon attributes. The browser will fetch those assets at render time, which can leak client network metadata and make the map nondeterministic offline or in tests.
364
+
327
365
  #### Theming & Styling
328
366
 
329
367
  Customize the visual appearance:
330
368
 
331
369
  - **`theme-url`** (string, optional): External CSS stylesheet URL to inject into Shadow DOM
332
370
  - **`themeCss`** (property only): Inline CSS strings for custom styling
371
+ - **`tool-button-config`** (JSON string, optional): Per-tool toolbar button config for custom icons, labels, and theme classes
372
+ - **`toolbar-groups`** (JSON array, optional): Additional map toolbar groups with independent tool sets and corner placement. Custom groups hide the built-in Leaflet.draw/ruler toolbars by default so duplicate controls do not sit underneath branded buttons; set `hideDefaultToolbar: false` on a group only when the native toolbar should remain visible.
333
373
 
334
374
  ```html
335
375
  <leaflet-geokit theme-url="/css/custom-map-theme.css"></leaflet-geokit>
336
376
  ```
337
377
 
378
+ ```html
379
+ <leaflet-geokit
380
+ draw-polygon
381
+ draw-marker
382
+ tool-button-config='{
383
+ "polygon": {
384
+ "iconUrl": "/icons/bed-boundary.svg",
385
+ "title": "Draw bed boundary",
386
+ "ariaLabel": "Draw bed boundary tool",
387
+ "popover": {
388
+ "title": "Boundary",
389
+ "body": "Trace the active irrigation area and close on the first point."
390
+ },
391
+ "className": "fs-map-tool fs-map-tool--primary"
392
+ },
393
+ "marker": {
394
+ "iconUrl": "/icons/field-marker.svg",
395
+ "title": "Place marker"
396
+ }
397
+ }'
398
+ ></leaflet-geokit>
399
+ ```
400
+
401
+ ```html
402
+ <leaflet-geokit
403
+ draw-polygon
404
+ toolbar-groups='[
405
+ {
406
+ "id": "irrigation-draw",
407
+ "position": "bottomright",
408
+ "tools": ["polygon", "select", "save"]
409
+ },
410
+ {
411
+ "id": "irrigation-style",
412
+ "position": "topright",
413
+ "tools": ["layerStyle"]
414
+ }
415
+ ]'
416
+ ></leaflet-geokit>
417
+ ```
418
+
419
+ GeoKit also tags rendered Leaflet controls with stable `data-geokit-tool`
420
+ attributes, such as `data-geokit-tool="polygon"` and
421
+ `data-geokit-tool="layer-cake"`, so `theme-url` and `themeCss` can target
422
+ buttons without depending on Leaflet's sprite class names.
423
+
338
424
  #### Debugging & Development
339
425
 
340
426
  - **`log-level`** (string): Control console logging verbosity. Options: `trace`, `debug`, `info`, `warn`, `error`, `silent`. Default: `"debug"`
341
- - **`dev-overlay`** (boolean): Reserved for future development overlay features
427
+ - **`dev-overlay`** (boolean): Reserved compatibility flag. No overlay UI ships in `0.8.x`.
342
428
 
343
429
  ```html
344
430
  <leaflet-geokit log-level="info"></leaflet-geokit>
@@ -370,14 +456,186 @@ map.toolHooks = {
370
456
  map.toolEventEmitter = {
371
457
  emit: (eventName, detail) => console.log(eventName, detail),
372
458
  }; // optional integrated tool event emitter
459
+ map.toolButtonConfig = {
460
+ polygon: {
461
+ iconUrl: new URL("./bed-boundary.svg", import.meta.url).toString(),
462
+ iconHtml: '<svg viewBox="0 0 20 20"><path d="M10 2 3 18h14z" /></svg>',
463
+ title: "Draw bed boundary",
464
+ ariaLabel: "Draw bed boundary tool",
465
+ iconSize: [20, 20],
466
+ popover: {
467
+ title: "Boundary",
468
+ body: "Trace the active irrigation area and close on the first point.",
469
+ },
470
+ className: "fs-map-tool fs-map-tool--primary",
471
+ },
472
+ layerCake: {
473
+ iconUrl: new URL("./layer-cake.svg", import.meta.url).toString(),
474
+ title: "Build layered zone",
475
+ },
476
+ }; // optional draw/ruler toolbar button customization
477
+ map.toolbarGroups = [
478
+ {
479
+ id: "irrigation-draw",
480
+ position: "bottomright",
481
+ tools: ["polygon", "select", "save"],
482
+ ariaLabel: "Irrigation drawing tools",
483
+ },
484
+ {
485
+ id: "irrigation-style",
486
+ position: "topright",
487
+ tools: ["layerStyle"],
488
+ ariaLabel: "Irrigation layer style",
489
+ },
490
+ ]; // optional additional map toolbar groups
373
491
 
374
492
  // Theming
375
493
  map.themeCss = `
376
494
  .leaflet-container { font-family: "Inter", sans-serif; }
377
- .leaflet-draw-toolbar a { border-radius: 8px; }
495
+ [data-geokit-tool] { border-radius: 8px; }
496
+ [data-geokit-tool="polygon"].fs-map-tool--primary { background: #f7fff5; }
378
497
  `;
379
498
  ```
380
499
 
500
+ #### Programmatic Tool Buttons, Popovers, and Groups
501
+
502
+ The bundled and external entrypoints export `ToolButtonConfig` for host apps
503
+ that need branded, domain-specific map controls. Hosts can provide PNG/SVG URLs,
504
+ trusted inline SVG/HTML (`iconHtml`), or a `renderIcon` function when assigning
505
+ the config as a JavaScript property. `popover` adds point-of-action guidance to
506
+ default Leaflet buttons and configured toolbar-group buttons.
507
+
508
+ ```ts
509
+ import "@florasync/leaflet-geokit";
510
+ import type {
511
+ ToolButtonConfig,
512
+ ToolToolbarGroupConfig,
513
+ } from "@florasync/leaflet-geokit";
514
+
515
+ const toolButtons: ToolButtonConfig = {
516
+ polygon: {
517
+ iconUrl: new URL("./bed-boundary.svg", import.meta.url).toString(),
518
+ title: "Draw bed boundary",
519
+ ariaLabel: "Draw bed boundary tool",
520
+ iconSize: [20, 20],
521
+ popover: {
522
+ title: "Irrigation boundary",
523
+ body: "Draw the wetted area. Close on the first point before saving.",
524
+ },
525
+ className: "fs-map-tool fs-map-tool--primary",
526
+ },
527
+ marker: {
528
+ iconUrl: new URL("./field-marker.svg", import.meta.url).toString(),
529
+ title: "Place field marker",
530
+ },
531
+ };
532
+
533
+ const toolbarGroups: ToolToolbarGroupConfig[] = [
534
+ {
535
+ id: "irrigation-draw",
536
+ position: "bottomright",
537
+ tools: ["polygon", "select", "save"],
538
+ ariaLabel: "Irrigation drawing tools",
539
+ },
540
+ {
541
+ id: "irrigation-style",
542
+ position: "topright",
543
+ tools: ["layerStyle"],
544
+ ariaLabel: "Irrigation layer style",
545
+ },
546
+ ];
547
+
548
+ map!.toolButtonConfig = toolButtons;
549
+ map!.toolbarGroups = toolbarGroups;
550
+ ```
551
+
552
+ Supported tool keys are `polygon`, `polyline`, `rectangle`, `circle`, `marker`,
553
+ `layerCake`, `move`, `select`, `edit`, `delete`, `ruler`,
554
+ `measurementSettings`, `layerStyle`, and `save`. `select` disables active draw/edit
555
+ handlers; `layerStyle` emits a public trigger event for host-owned style panels;
556
+ `save` emits `leaflet-draw:export` with the current editable GeoJSON for host
557
+ persistence.
558
+
559
+ `map.toolButtonConfig` takes precedence over the `tool-button-config` attribute;
560
+ `map.toolbarGroups` takes precedence over the `toolbar-groups` attribute. Set a
561
+ property to `undefined` to return to the attribute, or `null` to clear the
562
+ programmatic config while keeping stable `data-geokit-tool` hooks.
563
+
564
+ #### External Tool Triggers
565
+
566
+ Outside DOM controls can activate any configured tool through the public custom
567
+ element API:
568
+
569
+ ```ts
570
+ const map = document.querySelector("leaflet-geokit");
571
+
572
+ await map!.activateTool("polygon", {
573
+ source: "external-irrigation-button",
574
+ groupId: "field-panel",
575
+ });
576
+
577
+ await map!.deactivateTool({
578
+ source: "external-irrigation-cancel",
579
+ groupId: "field-panel",
580
+ });
581
+
582
+ map!.dispatchEvent(
583
+ new CustomEvent("leaflet-geokit:activate-tool", {
584
+ detail: {
585
+ tool: "polygon",
586
+ source: "event",
587
+ groupId: "field-panel",
588
+ },
589
+ }),
590
+ );
591
+ ```
592
+
593
+ `triggerTool(tool, options)` remains available as a back-compat alias for
594
+ `activateTool(tool, options)`. `deactivateTool(options)` disables active
595
+ draw/edit handlers and returns the map to `select` mode without requiring host
596
+ code to reach into Leaflet.draw toolbar internals. The legacy
597
+ `leaflet-geokit:trigger-tool` event also remains supported; pass
598
+ `{ action: "deactivate" }` or `{ active: false }` in its detail to use it as a
599
+ deactivate request.
600
+
601
+ GeoKit emits `leaflet-geokit:tool-trigger-requested`, then either
602
+ `leaflet-geokit:tool-triggered` or
603
+ `leaflet-geokit:tool-trigger-failed`. Event detail includes `tool`, `source`,
604
+ `groupId`, `handled`, `timestamp`, and optional `error`.
605
+
606
+ See `irrigation-draw-mode.html` for a working integration demo with custom
607
+ icons, popovers, two toolbar groups, an external panel button, real polygon
608
+ draw activation, and a custom save button.
609
+
610
+ #### Programmatic Marker Icon Override
611
+
612
+ The bundled and external entrypoints both export `MarkerIconConfig`:
613
+
614
+ ```ts
615
+ import "@florasync/leaflet-geokit";
616
+ import type { MarkerIconConfig } from "@florasync/leaflet-geokit";
617
+
618
+ const map = document.querySelector("leaflet-geokit");
619
+
620
+ const fieldPin: MarkerIconConfig = {
621
+ iconUrl: new URL("./field-pin.svg", import.meta.url).toString(),
622
+ iconRetinaUrl: new URL("./field-pin@2x.svg", import.meta.url).toString(),
623
+ iconSize: [32, 40],
624
+ iconAnchor: [16, 40],
625
+ popupAnchor: [0, -34],
626
+ };
627
+
628
+ map!.markerIconConfig = fieldPin;
629
+ ```
630
+
631
+ Precedence and fallback rules:
632
+
633
+ - `map.markerIconConfig` takes precedence over all `marker-icon-*` HTML attributes.
634
+ - Set `map.markerIconConfig = undefined` to return to attribute-driven configuration.
635
+ - Set `map.markerIconConfig = null` to force default Leaflet markers even if `marker-icon-*` attributes remain on the element.
636
+ - Invalid `iconUrl` disables the override and falls back to default markers. Invalid secondary fields keep the override active but fall back field-by-field to the documented defaults.
637
+ - Existing point features and future `draw-marker` placements both reuse the same normalized icon contract, so loaded data and interactive drawing stay visually consistent.
638
+
381
639
  ### Integrated Tool Hooks & Event Emitter
382
640
 
383
641
  GeoKit exposes tool lifecycle events through two optional integration points:
@@ -510,8 +768,25 @@ const data = await map.getGeoJSON();
510
768
  console.log(`${data.features.length} features on map`);
511
769
  ```
512
770
 
771
+ **[`importGeoJSON(fc, options?)`](src/components/LeafletDrawMapElement.ts)**: Promise<string[]>
772
+
773
+ - Explicit import contract for host apps: `behavior: "replace" | "add"`
774
+ - `replace` clears existing data before ingest; `add` preserves existing map data
775
+ - `fitToData` is optional and defaults to `false` for direct programmatic imports
776
+ - Returns array of assigned stable feature IDs
777
+ - Triggers [`leaflet-draw:ingest`](src/types/events.ts:51) event before import (`mode: "load"` for replace, `mode: "add"` for additive imports)
778
+
779
+ ```javascript
780
+ const ids = await map.importGeoJSON(newFeatures, {
781
+ behavior: "add",
782
+ fitToData: true,
783
+ });
784
+ console.log("Imported features with IDs:", ids);
785
+ ```
786
+
513
787
  **[`loadGeoJSON(fc)`](src/components/LeafletDrawMapElement.ts:390)**: Promise<void>
514
788
 
789
+ - Back-compat alias for `importGeoJSON(fc, { behavior: "replace" })`
515
790
  - Clears existing data and loads new FeatureCollection
516
791
  - Does NOT auto-fit the view (use [`fitBoundsToData()`](src/components/LeafletDrawMapElement.ts:428) separately)
517
792
  - Triggers [`leaflet-draw:ingest`](src/types/events.ts:51) event before loading
@@ -519,16 +794,16 @@ console.log(`${data.features.length} features on map`);
519
794
  ```javascript
520
795
  await map.loadGeoJSON({
521
796
  type: "FeatureCollection",
522
- features: [
523
- /* ... */
524
- ],
797
+ features: [/* ... */],
525
798
  });
526
799
  ```
527
800
 
528
801
  **[`addFeatures(fc)`](src/components/LeafletDrawMapElement.ts:406)**: Promise<string[]>
529
802
 
803
+ - Back-compat alias for `importGeoJSON(fc, { behavior: "add" })`
530
804
  - Adds features to existing map data (does not clear)
531
805
  - Returns array of assigned stable feature IDs
806
+ - Expands `Multi*` and `GeometryCollection` inputs into one single-geometry feature/id per child part
532
807
  - Triggers [`leaflet-draw:ingest`](src/types/events.ts:51) event before adding
533
808
 
534
809
  ```javascript
@@ -555,9 +830,7 @@ await map.clearLayers();
555
830
  await map.updateFeature(featureId, {
556
831
  type: "Feature",
557
832
  properties: { name: "Updated" },
558
- geometry: {
559
- /* ... */
560
- },
833
+ geometry: {/* ... */},
561
834
  });
562
835
  ```
563
836
 
@@ -607,36 +880,43 @@ await map.fitBounds(
607
880
 
608
881
  #### Data Import Helpers
609
882
 
610
- **[`loadGeoJSONFromUrl(url)`](src/components/LeafletDrawMapElement.ts:510)**: Promise<void>
883
+ **[`loadGeoJSONFromUrl(url, options?)`](src/components/LeafletDrawMapElement.ts:510)**: Promise<void>
611
884
 
612
- - Fetches GeoJSON from URL and loads it
885
+ - Fetches GeoJSON from URL and imports it with explicit `behavior: "replace" | "add"`
613
886
  - Expects `application/json` content type
614
- - Automatically fits view to loaded data
615
- - Emits error events on fetch/parse failures
887
+ - Defaults to `behavior: "replace"` and `fitToData: true` for file/URL style imports
888
+ - Emits error events on fetch/parse/import failures
616
889
 
617
890
  ```javascript
618
- await map.loadGeoJSONFromUrl("/api/geodata.json");
891
+ await map.loadGeoJSONFromUrl("/api/geodata.json", {
892
+ behavior: "add",
893
+ });
619
894
  ```
620
895
 
621
- **[`loadGeoJSONFromText(text)`](src/components/LeafletDrawMapElement.ts:533)**: Promise<void>
896
+ **[`loadGeoJSONFromText(text, options?)`](src/components/LeafletDrawMapElement.ts:533)**: Promise<void>
622
897
 
623
- - Parses GeoJSON from text string and loads it
624
- - Automatically fits view to loaded data
625
- - Emits error events on parse failures
898
+ - Parses GeoJSON from text string and imports it with explicit `behavior: "replace" | "add"`
899
+ - Defaults to `behavior: "replace"` and `fitToData: true`
900
+ - Emits error events on parse/import failures
626
901
 
627
902
  ```javascript
628
903
  const text = await file.text();
629
- await map.loadGeoJSONFromText(text);
904
+ await map.loadGeoJSONFromText(text, {
905
+ behavior: "replace",
906
+ });
630
907
  ```
631
908
 
632
- **[`exportGeoJSON()`](src/components/LeafletDrawMapElement.ts:459)**: Promise<FeatureCollection>
909
+ **[`exportGeoJSON(options?)`](src/components/LeafletDrawMapElement.ts:459)**: Promise<FeatureCollection>
633
910
 
634
911
  - Exports current data and emits [`leaflet-draw:export`](src/types/events.ts:57) event
635
- - Returns the FeatureCollection for convenience
636
- - Useful for triggering export workflows
912
+ - Defaults to `adapter: "editing"`, which preserves the current editable single-geometry feature state
913
+ - `adapter: "source"` opt-in re-merges stable derived sibling IDs like `bed-1::0` / `bed-1::1` back into source-like `Multi*` or `GeometryCollection` output
914
+ - Source export is intentionally opt-in because sibling property divergence is resolved by reusing the first child properties
637
915
 
638
916
  ```javascript
639
- const exported = await map.exportGeoJSON();
917
+ const exported = await map.exportGeoJSON({
918
+ adapter: "source",
919
+ });
640
920
  // Listen for the event to trigger download/save workflows
641
921
  ```
642
922
 
@@ -670,9 +950,41 @@ The component emits typed CustomEvents that can be listened to for real-time upd
670
950
 
671
951
  #### Core Lifecycle Events
672
952
 
673
- **[`leaflet-draw:ready`](src/types/events.ts:7)**
953
+ **[`leaflet-geokit:status`](src/types/events.ts)**
954
+
955
+ - Fired whenever the public readiness/loading/error snapshot changes
956
+ - Also mirrored on the element as `map.status`
957
+ - Detail: `{ state, ready, busy, featureCount, lastEvent?, lastError?, timestamp }`
958
+
959
+ ```javascript
960
+ map.addEventListener("leaflet-geokit:status", (e) => {
961
+ const { state, featureCount, lastError } = e.detail;
962
+ console.log("GeoKit status:", state, featureCount, lastError?.code);
963
+ });
964
+
965
+ console.log(map.status.state); // 'uninitialized' | 'initializing' | 'ready' | 'loading' | 'error'
966
+ ```
967
+
968
+ **[`leaflet-geokit:diagnostic`](src/types/events.ts)**
969
+
970
+ - Fired for recoverable and fatal diagnostics
971
+ - Recoverable diagnostics keep `status.state` at `ready` when the map remains usable
972
+ - Detail: `{ code, message, recoverable, severity, state, cause?, timestamp }`
973
+
974
+ ```javascript
975
+ map.addEventListener("leaflet-geokit:diagnostic", (e) => {
976
+ if (e.detail.recoverable) {
977
+ console.warn("Recoverable GeoKit issue:", e.detail.code, e.detail.message);
978
+ return;
979
+ }
674
980
 
675
- - Fired when map is fully initialized and ready for interaction
981
+ console.error("Fatal GeoKit issue:", e.detail.code, e.detail.message);
982
+ });
983
+ ```
984
+
985
+ **[`leaflet-draw:ready`](src/types/events.ts)**
986
+
987
+ - Compatibility event fired when the map is fully initialized and ready for interaction
676
988
  - Detail: `{ bounds?: [[number, number], [number, number]] }`
677
989
 
678
990
  ```javascript
@@ -681,20 +993,26 @@ map.addEventListener("leaflet-draw:ready", (e) => {
681
993
  });
682
994
  ```
683
995
 
684
- **[`leaflet-draw:error`](src/types/events.ts:42)**
996
+ **[`leaflet-draw:error`](src/types/events.ts)**
685
997
 
686
- - Fired when errors occur (fetch failures, parse errors, etc.)
687
- - Detail: `{ message: string, cause?: unknown }`
998
+ - Fired when GeoKit hits a typed error condition (fetch failures, parse errors, init failures, config warnings)
999
+ - Recoverable warnings still emit here for backward compatibility
1000
+ - Detail: `{ code, message, recoverable, cause?, timestamp }`
688
1001
 
689
1002
  ```javascript
690
1003
  map.addEventListener("leaflet-draw:error", (e) => {
691
- console.error("Map error:", e.detail.message, e.detail.cause);
1004
+ console.error(
1005
+ "Map error:",
1006
+ e.detail.code,
1007
+ e.detail.message,
1008
+ e.detail.recoverable,
1009
+ );
692
1010
  });
693
1011
  ```
694
1012
 
695
1013
  #### Drawing & Editing Events
696
1014
 
697
- **[`leaflet-draw:created`](src/types/events.ts:15)**
1015
+ **[`leaflet-draw:created`](src/types/events.ts)**
698
1016
 
699
1017
  - Fired when user creates a new feature via drawing tools
700
1018
  - Detail: `{ id: string, layerType: string, geoJSON: Feature }`
@@ -710,7 +1028,7 @@ map.addEventListener('leaflet-draw:created', (e) => {
710
1028
  });
711
1029
  ```
712
1030
 
713
- **[`leaflet-draw:edited`](src/types/events.ts:25)**
1031
+ **[`leaflet-draw:edited`](src/types/events.ts)**
714
1032
 
715
1033
  - Fired when user modifies existing features via edit tools
716
1034
  - Detail: `{ ids: string[], geoJSON: FeatureCollection }`
@@ -729,7 +1047,7 @@ map.addEventListener('leaflet-draw:edited', (e) => {
729
1047
  });
730
1048
  ```
731
1049
 
732
- **[`leaflet-draw:deleted`](src/types/events.ts:34)**
1050
+ **[`leaflet-draw:deleted`](src/types/events.ts)**
733
1051
 
734
1052
  - Fired when user deletes features via delete tools
735
1053
  - Detail: `{ ids: string[], geoJSON: FeatureCollection }`
@@ -749,7 +1067,7 @@ map.addEventListener('leaflet-draw:deleted', (e) => {
749
1067
 
750
1068
  #### Data Flow Events
751
1069
 
752
- **[`leaflet-draw:ingest`](src/types/events.ts:51)**
1070
+ **[`leaflet-draw:ingest`](src/types/events.ts)**
753
1071
 
754
1072
  - Fired BEFORE data is loaded/added to the map
755
1073
  - Detail: `{ fc: FeatureCollection, mode: 'load' | 'add' }`
@@ -776,7 +1094,7 @@ map.addEventListener("leaflet-draw:ingest", (e) => {
776
1094
  });
777
1095
  ```
778
1096
 
779
- **[`leaflet-draw:export`](src/types/events.ts:57)**
1097
+ **[`leaflet-draw:export`](src/types/events.ts)**
780
1098
 
781
1099
  - Fired when [`exportGeoJSON()`](src/components/LeafletDrawMapElement.ts:459) method is called
782
1100
  - Detail: `{ geoJSON: FeatureCollection, featureCount: number }`
@@ -798,32 +1116,16 @@ map.addEventListener("leaflet-draw:export", (e) => {
798
1116
  });
799
1117
  ```
800
1118
 
801
- #### Extended Tool Events
802
-
803
- **`leaflet-draw:drawstart`** / **`leaflet-draw:drawstop`**
804
-
805
- - Fired when drawing mode starts/stops
806
- - Useful for UI state management
807
-
808
- **`leaflet-draw:editstart`** / **`leaflet-draw:editstop`**
809
-
810
- - Fired when edit mode starts/stops
1119
+ #### Merge and Tool Events
811
1120
 
812
1121
  **`leaflet-draw:merged`**
813
1122
 
814
1123
  - Fired after successful polygon merge operation
815
1124
  - Detail includes merge statistics and result
816
1125
 
817
- ```javascript
818
- // Show/hide UI elements based on draw state
819
- map.addEventListener("leaflet-draw:drawstart", () => {
820
- document.querySelector("#toolbar").classList.add("drawing-active");
821
- });
822
-
823
- map.addEventListener("leaflet-draw:drawstop", () => {
824
- document.querySelector("#toolbar").classList.remove("drawing-active");
825
- });
826
- ```
1126
+ GeoKit `0.8.x` does not emit public draw/edit start-stop lifecycle events.
1127
+ Use `leaflet-geokit:status` for readiness/loading coordination and the
1128
+ `leaflet-geokit:tool-*` events for host-triggered tool actions.
827
1129
 
828
1130
  ### Feature ID Management
829
1131
 
@@ -832,6 +1134,8 @@ The component guarantees stable, persistent feature IDs that survive editing ope
832
1134
  1. **Explicit IDs**: If a feature has `feature.id` property, it's preserved
833
1135
  2. **Property IDs**: If no `feature.id` but has `properties.id`, that's used
834
1136
  3. **Generated IDs**: Otherwise, a UUID is generated and stored in `properties.id`
1137
+ 4. **Multi-geometry normalization**: `MultiPoint`, `MultiLineString`, `MultiPolygon`, and `GeometryCollection` inputs are expanded into single-geometry features. If the source feature already had an ID, each child receives a stable derived ID such as `bed-1::0` and `bed-1::1`
1138
+ 5. **Opt-in source export**: `exportGeoJSON({ adapter: "source" })` best-effort re-merges those stable derived siblings into source-like `Multi*`/`GeometryCollection` output for hosts that want source-shaped files back
835
1139
 
836
1140
  ```javascript
837
1141
  // Features maintain their IDs through edit cycles
@@ -934,7 +1238,9 @@ C. Load from text (e.g., user paste or file input)
934
1238
 
935
1239
  ```js
936
1240
  const text = await file.text();
937
- await el.loadGeoJSONFromText(text);
1241
+ await el.loadGeoJSONFromText(text, {
1242
+ behavior: "add", // or "replace" to clear existing map data first
1243
+ });
938
1244
  ```
939
1245
 
940
1246
  D. Programmatic CRUD with ids
@@ -1172,11 +1478,9 @@ SSR
1172
1478
 
1173
1479
  Planned enhancements
1174
1480
 
1175
- - Dev overlay (opt-in) to visualize state, counts, and last event payloads
1176
1481
  - Geometry-level layer sync for updateFeature without re-add
1177
1482
  - Playwright e2e and CI workflows
1178
1483
  - Advanced import providers (files, streams) and output format adapters
1179
- - Theming hooks for overlay UI
1180
1484
 
1181
1485
  Versioning and releases
1182
1486