@florasync/leaflet-geokit 0.7.0 → 0.8.0

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/README.md CHANGED
@@ -364,6 +364,12 @@ map.tileAttribution = "..."; // string | undefined
364
364
  map.readOnly = true; // boolean
365
365
  map.preferCanvas = false; // boolean
366
366
  map.logLevel = "info"; // LogLevel
367
+ map.toolHooks = {
368
+ "tool:move:pending": (detail) => console.log("pending move", detail),
369
+ }; // optional integrated tool hooks
370
+ map.toolEventEmitter = {
371
+ emit: (eventName, detail) => console.log(eventName, detail),
372
+ }; // optional integrated tool event emitter
367
373
 
368
374
  // Theming
369
375
  map.themeCss = `
@@ -372,6 +378,122 @@ map.themeCss = `
372
378
  `;
373
379
  ```
374
380
 
381
+ ### Integrated Tool Hooks & Event Emitter
382
+
383
+ GeoKit exposes tool lifecycle events through two optional integration points:
384
+
385
+ - `map.toolHooks`: per-event callbacks keyed by event name
386
+ - `map.toolEventEmitter`: generic emitter object with either:
387
+ - `emit(eventName, detail)`
388
+ - or `dispatchEvent(new CustomEvent(eventName, { detail }))`
389
+
390
+ Both can be used together. If both are provided, both are called.
391
+
392
+ ```javascript
393
+ const map = document.querySelector("leaflet-geokit");
394
+
395
+ map.toolHooks = {
396
+ "tool:move:pending": (detail) => {
397
+ console.log("Move pending", detail.layerId);
398
+ },
399
+ "tool:ruler:units-changed": (detail) => {
400
+ console.log("Units changed", detail.previous, "->", detail.current);
401
+ },
402
+ };
403
+
404
+ map.toolEventEmitter = {
405
+ emit: (eventName, detail) => {
406
+ analytics.track(eventName, detail);
407
+ },
408
+ };
409
+ ```
410
+
411
+ Important behavior notes:
412
+
413
+ - Hooks/emitter can be assigned before or after map initialization.
414
+ - Re-assigning `toolHooks`/`toolEventEmitter` at runtime updates active observers immediately.
415
+ - Assign `undefined` to clear either integration point.
416
+
417
+ #### Supported integrated tool event names
418
+
419
+ - `tool:polygon:created`
420
+ - `tool:polyline:created`
421
+ - `tool:rectangle:created`
422
+ - `tool:circle:created`
423
+ - `tool:marker:created`
424
+ - `tool:layer-cake:session-started`
425
+ - `tool:layer-cake:saved`
426
+ - `tool:move:pending`
427
+ - `tool:move:confirmed`
428
+ - `tool:move:cancelled`
429
+ - `tool:edit:applied`
430
+ - `tool:delete:applied`
431
+ - `tool:ruler:units-changed`
432
+
433
+ #### Event detail payloads
434
+
435
+ `tool:*:created` (polygon/polyline/rectangle/circle/marker):
436
+
437
+ ```ts
438
+ {
439
+ id: string;
440
+ geoJSON: GeoJSON.Feature;
441
+ }
442
+ ```
443
+
444
+ `tool:layer-cake:session-started`:
445
+
446
+ ```ts
447
+ {
448
+ center: { lat: number; lng: number; ... };
449
+ radius: number;
450
+ }
451
+ ```
452
+
453
+ `tool:layer-cake:saved`:
454
+
455
+ ```ts
456
+ {
457
+ featureCollection: GeoJSON.FeatureCollection;
458
+ }
459
+ ```
460
+
461
+ `tool:move:pending` / `tool:move:confirmed`:
462
+
463
+ ```ts
464
+ {
465
+ layerId?: string;
466
+ originalGeoJSON?: GeoJSON.Feature;
467
+ newGeoJSON?: GeoJSON.Feature;
468
+ }
469
+ ```
470
+
471
+ `tool:move:cancelled`:
472
+
473
+ ```ts
474
+ {
475
+ layerId?: string;
476
+ }
477
+ ```
478
+
479
+ `tool:edit:applied` / `tool:delete:applied`:
480
+
481
+ ```ts
482
+ {
483
+ ids: string[];
484
+ geoJSON: GeoJSON.FeatureCollection;
485
+ }
486
+ ```
487
+
488
+ `tool:ruler:units-changed`:
489
+
490
+ ```ts
491
+ {
492
+ previous: "metric" | "imperial";
493
+ current: "metric" | "imperial";
494
+ }
495
+ ```
496
+
375
497
  ### Methods
376
498
 
377
499
  All methods return Promises and should be awaited. Invoke on the element instance: