@florasync/leaflet-geokit 0.7.0 → 0.8.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +384 -3
  3. package/dist/django/index.js +4758 -3546
  4. package/dist/django/index.js.map +1 -1
  5. package/dist/leaflet-geokit.es.js +4654 -3442
  6. package/dist/leaflet-geokit.es.js.map +1 -1
  7. package/dist/leaflet-geokit.external.es.js +2294 -1082
  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-DagV_wwR.js → index-x8CrGR_z.js} +2263 -1051
  12. package/dist/preact/index-x8CrGR_z.js.map +1 -0
  13. package/dist/preact/index.js +52 -48
  14. package/dist/preact/index.js.map +1 -1
  15. package/dist/preact-bundled/index.js +4808 -3592
  16. package/dist/preact-bundled/index.js.map +1 -1
  17. package/dist/react/{index-DagV_wwR.js → index-x8CrGR_z.js} +2263 -1051
  18. package/dist/react/index-x8CrGR_z.js.map +1 -0
  19. package/dist/react/index.js +40 -36
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react-bundled/index.js +4809 -3593
  22. package/dist/react-bundled/index.js.map +1 -1
  23. package/dist/types/{src/components → components}/LeafletDrawMapElement.d.ts +30 -2
  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 +50 -3
  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 +10 -1
  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 +10 -1
  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}/public.d.ts +125 -1
  39. package/package.json +6 -3
  40. package/dist/preact/index-DagV_wwR.js.map +0 -1
  41. package/dist/react/index-DagV_wwR.js.map +0 -1
  42. package/dist/types/e2e/component.spec.d.ts +0 -1
  43. package/dist/types/e2e/dummy.spec.d.ts +0 -1
  44. package/dist/types/src/external.d.ts +0 -4
  45. package/dist/types/src/index.d.ts +0 -4
  46. package/dist/types/tests/bbox-more.spec.d.ts +0 -1
  47. package/dist/types/tests/component-api-more.spec.d.ts +0 -1
  48. package/dist/types/tests/component-branch-coverage.spec.d.ts +0 -1
  49. package/dist/types/tests/component-delegation.spec.d.ts +0 -1
  50. package/dist/types/tests/component-events.spec.d.ts +0 -1
  51. package/dist/types/tests/component-io.spec.d.ts +0 -1
  52. package/dist/types/tests/component-tile-provider.spec.d.ts +0 -1
  53. package/dist/types/tests/django-shim.spec.d.ts +0 -1
  54. package/dist/types/tests/draw-cake.spec.d.ts +0 -1
  55. package/dist/types/tests/draw-move.spec.d.ts +0 -1
  56. package/dist/types/tests/eachcoord.spec.d.ts +0 -1
  57. package/dist/types/tests/element.spec.d.ts +0 -1
  58. package/dist/types/tests/ensure-element.spec.d.ts +0 -1
  59. package/dist/types/tests/external-entry.spec.d.ts +0 -1
  60. package/dist/types/tests/featureStore-more.spec.d.ts +0 -1
  61. package/dist/types/tests/featureStore.spec.d.ts +0 -1
  62. package/dist/types/tests/framework-runtime-externalization.spec.d.ts +0 -1
  63. package/dist/types/tests/geodesic.spec.d.ts +0 -1
  64. package/dist/types/tests/geojson-merge.spec.d.ts +0 -1
  65. package/dist/types/tests/geojson-more.spec.d.ts +0 -1
  66. package/dist/types/tests/geojson.spec.d.ts +0 -1
  67. package/dist/types/tests/layer-cake-baker.spec.d.ts +0 -1
  68. package/dist/types/tests/layer-cake-controls.spec.d.ts +0 -1
  69. package/dist/types/tests/layer-cake-editing.spec.d.ts +0 -1
  70. package/dist/types/tests/layer-cake-manager.spec.d.ts +0 -1
  71. package/dist/types/tests/leaflet-assets.spec.d.ts +0 -1
  72. package/dist/types/tests/leaflet-draw-circle-resize-patch.spec.d.ts +0 -1
  73. package/dist/types/tests/leaflet-guards.spec.d.ts +0 -1
  74. package/dist/types/tests/logger-more.spec.d.ts +0 -1
  75. package/dist/types/tests/logger.spec.d.ts +0 -1
  76. package/dist/types/tests/map-controller.spec.d.ts +0 -1
  77. package/dist/types/tests/mapcontroller-merge.spec.d.ts +0 -1
  78. package/dist/types/tests/preact-bundled-shim.spec.d.ts +0 -1
  79. package/dist/types/tests/preact-shim.spec.d.ts +0 -1
  80. package/dist/types/tests/react-bundled-shim.spec.d.ts +0 -1
  81. package/dist/types/tests/react-shim.spec.d.ts +0 -1
  82. package/dist/types/tests/ruler.spec.d.ts +0 -1
  83. package/dist/types/tests/tile-provider-factory.spec.d.ts +0 -1
  84. package/dist/types/vite.config.d.ts +0 -2
  85. package/dist/types/vite.config.external.d.ts +0 -2
  86. package/dist/types/vite.config.preact-bundled.d.ts +0 -2
  87. package/dist/types/vite.config.preact.d.ts +0 -2
  88. package/dist/types/vite.config.react-bundled.d.ts +0 -2
  89. package/dist/types/vite.config.react.d.ts +0 -2
  90. /package/dist/types/{src/lib → lib}/TileProviderFactory.d.ts +0 -0
  91. /package/dist/types/{src/lib → lib}/draw/L.Draw.Cake.d.ts +0 -0
  92. /package/dist/types/{src/lib → lib}/draw/L.Draw.Move.d.ts +0 -0
  93. /package/dist/types/{src/lib → lib}/draw/toolbar-patch.d.ts +0 -0
  94. /package/dist/types/{src/lib → lib}/layer-cake/CakeBaker.d.ts +0 -0
  95. /package/dist/types/{src/lib → lib}/layer-cake/bindCakeControls.d.ts +0 -0
  96. /package/dist/types/{src/lib → lib}/layer-cake/ensureCircleEditable.d.ts +0 -0
  97. /package/dist/types/{src/lib → lib}/leaflet-assets.d.ts +0 -0
  98. /package/dist/types/{src/shims → shims}/ensure-element.d.ts +0 -0
  99. /package/dist/types/{src/state → state}/types.d.ts +0 -0
  100. /package/dist/types/{src/types → types}/events.d.ts +0 -0
  101. /package/dist/types/{src/utils → utils}/geodesic.d.ts +0 -0
  102. /package/dist/types/{src/utils → utils}/geojson.d.ts +0 -0
  103. /package/dist/types/{src/utils → utils}/leaflet-guards.d.ts +0 -0
  104. /package/dist/types/{src/utils → utils}/logger.d.ts +0 -0
  105. /package/dist/types/{src/utils → utils}/ruler.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -2,9 +2,22 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.8.1 - 2026-07-15
6
+
7
+ - Added `toolbarGroups` / `toolbar-groups` for multiple independent map toolbar groups with Leaflet-like corner placement.
8
+ - 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.
9
+ - 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.
10
+ - 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.
11
+ - 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.
12
+ - Added focused Playwright visual coverage for icon customization so missing assets, hidden icons, draw-marker regressions, and default-icon fallbacks fail in headless Chromium.
13
+ - Added `irrigation-draw-mode.html` and focused Playwright coverage for external panel activation and secondary toolbar polygon drawing.
14
+ - Rewrote emitted declaration imports during packaging so consumer entrypoints no longer leak internal `@src/*` aliases.
5
15
  - Added optional Spec Kitty bootstrap scaffolding via [`.kittify/README.md`](.kittify/README.md) for future spec-driven workflows.
6
16
  - 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
17
  - Updated [`.gitignore`](.gitignore) to exclude Spec Kitty/agent runtime state while keeping source artifacts commit-friendly.
18
+
19
+ ## 0.8.0 - 2026-04-11
20
+
8
21
  - 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
22
  - Improved Move tool drag stability by anchoring translation to the initial drag-start pointer location, reducing jitter while repositioning GeoJSON features.
10
23
  - 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,17 +327,100 @@ 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
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"]
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"`
@@ -364,14 +450,306 @@ map.tileAttribution = "..."; // string | undefined
364
450
  map.readOnly = true; // boolean
365
451
  map.preferCanvas = false; // boolean
366
452
  map.logLevel = "info"; // LogLevel
453
+ map.toolHooks = {
454
+ "tool:move:pending": (detail) => console.log("pending move", detail),
455
+ }; // optional integrated tool hooks
456
+ map.toolEventEmitter = {
457
+ emit: (eventName, detail) => console.log(eventName, detail),
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"],
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
367
491
 
368
492
  // Theming
369
493
  map.themeCss = `
370
494
  .leaflet-container { font-family: "Inter", sans-serif; }
371
- .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; }
372
497
  `;
373
498
  ```
374
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"],
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`, and `layerStyle`. `select` disables active draw/edit
555
+ handlers; `layerStyle` emits a public trigger event for host-owned style panels.
556
+
557
+ `map.toolButtonConfig` takes precedence over the `tool-button-config` attribute;
558
+ `map.toolbarGroups` takes precedence over the `toolbar-groups` attribute. Set a
559
+ property to `undefined` to return to the attribute, or `null` to clear the
560
+ programmatic config while keeping stable `data-geokit-tool` hooks.
561
+
562
+ #### External Tool Triggers
563
+
564
+ Outside DOM controls can activate any configured tool through the public custom
565
+ element API:
566
+
567
+ ```ts
568
+ const map = document.querySelector("leaflet-geokit");
569
+
570
+ await map!.activateTool("polygon", {
571
+ source: "external-irrigation-button",
572
+ groupId: "field-panel",
573
+ });
574
+
575
+ await map!.deactivateTool({
576
+ source: "external-irrigation-cancel",
577
+ groupId: "field-panel",
578
+ });
579
+
580
+ map!.dispatchEvent(
581
+ new CustomEvent("leaflet-geokit:activate-tool", {
582
+ detail: {
583
+ tool: "polygon",
584
+ source: "event",
585
+ groupId: "field-panel",
586
+ },
587
+ }),
588
+ );
589
+ ```
590
+
591
+ `triggerTool(tool, options)` remains available as a back-compat alias for
592
+ `activateTool(tool, options)`. `deactivateTool(options)` disables active
593
+ draw/edit handlers and returns the map to `select` mode without requiring host
594
+ code to reach into Leaflet.draw toolbar internals. The legacy
595
+ `leaflet-geokit:trigger-tool` event also remains supported; pass
596
+ `{ action: "deactivate" }` or `{ active: false }` in its detail to use it as a
597
+ deactivate request.
598
+
599
+ GeoKit emits `leaflet-geokit:tool-trigger-requested`, then either
600
+ `leaflet-geokit:tool-triggered` or
601
+ `leaflet-geokit:tool-trigger-failed`. Event detail includes `tool`, `source`,
602
+ `groupId`, `handled`, `timestamp`, and optional `error`.
603
+
604
+ See `irrigation-draw-mode.html` for a working integration demo with custom
605
+ icons, popovers, two toolbar groups, an external panel button, and real polygon
606
+ draw activation.
607
+
608
+ #### Programmatic Marker Icon Override
609
+
610
+ The bundled and external entrypoints both export `MarkerIconConfig`:
611
+
612
+ ```ts
613
+ import "@florasync/leaflet-geokit";
614
+ import type { MarkerIconConfig } from "@florasync/leaflet-geokit";
615
+
616
+ const map = document.querySelector("leaflet-geokit");
617
+
618
+ const fieldPin: MarkerIconConfig = {
619
+ iconUrl: new URL("./field-pin.svg", import.meta.url).toString(),
620
+ iconRetinaUrl: new URL("./field-pin@2x.svg", import.meta.url).toString(),
621
+ iconSize: [32, 40],
622
+ iconAnchor: [16, 40],
623
+ popupAnchor: [0, -34],
624
+ };
625
+
626
+ map!.markerIconConfig = fieldPin;
627
+ ```
628
+
629
+ Precedence and fallback rules:
630
+
631
+ - `map.markerIconConfig` takes precedence over all `marker-icon-*` HTML attributes.
632
+ - Set `map.markerIconConfig = undefined` to return to attribute-driven configuration.
633
+ - Set `map.markerIconConfig = null` to force default Leaflet markers even if `marker-icon-*` attributes remain on the element.
634
+ - 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.
635
+ - Existing point features and future `draw-marker` placements both reuse the same normalized icon contract, so loaded data and interactive drawing stay visually consistent.
636
+
637
+ ### Integrated Tool Hooks & Event Emitter
638
+
639
+ GeoKit exposes tool lifecycle events through two optional integration points:
640
+
641
+ - `map.toolHooks`: per-event callbacks keyed by event name
642
+ - `map.toolEventEmitter`: generic emitter object with either:
643
+ - `emit(eventName, detail)`
644
+ - or `dispatchEvent(new CustomEvent(eventName, { detail }))`
645
+
646
+ Both can be used together. If both are provided, both are called.
647
+
648
+ ```javascript
649
+ const map = document.querySelector("leaflet-geokit");
650
+
651
+ map.toolHooks = {
652
+ "tool:move:pending": (detail) => {
653
+ console.log("Move pending", detail.layerId);
654
+ },
655
+ "tool:ruler:units-changed": (detail) => {
656
+ console.log("Units changed", detail.previous, "->", detail.current);
657
+ },
658
+ };
659
+
660
+ map.toolEventEmitter = {
661
+ emit: (eventName, detail) => {
662
+ analytics.track(eventName, detail);
663
+ },
664
+ };
665
+ ```
666
+
667
+ Important behavior notes:
668
+
669
+ - Hooks/emitter can be assigned before or after map initialization.
670
+ - Re-assigning `toolHooks`/`toolEventEmitter` at runtime updates active observers immediately.
671
+ - Assign `undefined` to clear either integration point.
672
+
673
+ #### Supported integrated tool event names
674
+
675
+ - `tool:polygon:created`
676
+ - `tool:polyline:created`
677
+ - `tool:rectangle:created`
678
+ - `tool:circle:created`
679
+ - `tool:marker:created`
680
+ - `tool:layer-cake:session-started`
681
+ - `tool:layer-cake:saved`
682
+ - `tool:move:pending`
683
+ - `tool:move:confirmed`
684
+ - `tool:move:cancelled`
685
+ - `tool:edit:applied`
686
+ - `tool:delete:applied`
687
+ - `tool:ruler:units-changed`
688
+
689
+ #### Event detail payloads
690
+
691
+ `tool:*:created` (polygon/polyline/rectangle/circle/marker):
692
+
693
+ ```ts
694
+ {
695
+ id: string;
696
+ geoJSON: GeoJSON.Feature;
697
+ }
698
+ ```
699
+
700
+ `tool:layer-cake:session-started`:
701
+
702
+ ```ts
703
+ {
704
+ center: { lat: number; lng: number; ... };
705
+ radius: number;
706
+ }
707
+ ```
708
+
709
+ `tool:layer-cake:saved`:
710
+
711
+ ```ts
712
+ {
713
+ featureCollection: GeoJSON.FeatureCollection;
714
+ }
715
+ ```
716
+
717
+ `tool:move:pending` / `tool:move:confirmed`:
718
+
719
+ ```ts
720
+ {
721
+ layerId?: string;
722
+ originalGeoJSON?: GeoJSON.Feature;
723
+ newGeoJSON?: GeoJSON.Feature;
724
+ }
725
+ ```
726
+
727
+ `tool:move:cancelled`:
728
+
729
+ ```ts
730
+ {
731
+ layerId?: string;
732
+ }
733
+ ```
734
+
735
+ `tool:edit:applied` / `tool:delete:applied`:
736
+
737
+ ```ts
738
+ {
739
+ ids: string[];
740
+ geoJSON: GeoJSON.FeatureCollection;
741
+ }
742
+ ```
743
+
744
+ `tool:ruler:units-changed`:
745
+
746
+ ```ts
747
+ {
748
+ previous: "metric" | "imperial";
749
+ current: "metric" | "imperial";
750
+ }
751
+ ```
752
+
375
753
  ### Methods
376
754
 
377
755
  All methods return Promises and should be awaited. Invoke on the element instance:
@@ -407,6 +785,7 @@ await map.loadGeoJSON({
407
785
 
408
786
  - Adds features to existing map data (does not clear)
409
787
  - Returns array of assigned stable feature IDs
788
+ - Expands `Multi*` and `GeometryCollection` inputs into one single-geometry feature/id per child part
410
789
  - Triggers [`leaflet-draw:ingest`](src/types/events.ts:51) event before adding
411
790
 
412
791
  ```javascript
@@ -562,6 +941,7 @@ map.addEventListener("leaflet-draw:ready", (e) => {
562
941
  **[`leaflet-draw:error`](src/types/events.ts:42)**
563
942
 
564
943
  - Fired when errors occur (fetch failures, parse errors, etc.)
944
+ - Also used for non-fatal marker icon normalization warnings before GeoKit falls back to defaults
565
945
  - Detail: `{ message: string, cause?: unknown }`
566
946
 
567
947
  ```javascript
@@ -710,6 +1090,7 @@ The component guarantees stable, persistent feature IDs that survive editing ope
710
1090
  1. **Explicit IDs**: If a feature has `feature.id` property, it's preserved
711
1091
  2. **Property IDs**: If no `feature.id` but has `properties.id`, that's used
712
1092
  3. **Generated IDs**: Otherwise, a UUID is generated and stored in `properties.id`
1093
+ 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`
713
1094
 
714
1095
  ```javascript
715
1096
  // Features maintain their IDs through edit cycles