From c283632262cb739356b736805a0bd37417dfb11f Mon Sep 17 00:00:00 2001 From: Buddy Date: Tue, 9 Jun 2026 22:46:14 -0700 Subject: [PATCH] feat: add leafletObject escape hatch + move event wiring Every component now exposes a uniform get leafletObject() returning the underlying Leaflet instance (undefined before connected). Event wiring: - Marker: listen for 'dragend move' via onChange, syncing lat/lng back to attributes. Converted from arrow property to regular method using Leaflet's 3rd context arg pattern. - Circle, CircleMarker: listen for 'move' via onMove with syncing guard (same pattern). - Popup, Tooltip: listen for 'move' via onChange with syncing guard and null-check on getLatLng(). Also: - Update README with escape hatch section - Change map getter from get map() to get leafletObject() for consistency - index.html: add importmap for leaflet - All component exports changed from default to named - index.ts re-exports updated accordingly --- README.md | 18 +++++++- index.html | 7 ++++ src/components/leaflet-circle-marker.ts | 20 ++++++++- src/components/leaflet-circle.ts | 20 ++++++++- src/components/leaflet-control-attribution.ts | 6 ++- src/components/leaflet-control-scale.ts | 6 ++- src/components/leaflet-control-zoom.ts | 6 ++- src/components/leaflet-feature-group.ts | 6 ++- src/components/leaflet-geojson.ts | 6 ++- src/components/leaflet-image-overlay.ts | 6 ++- src/components/leaflet-layer-group.ts | 6 ++- src/components/leaflet-line.ts | 2 +- src/components/leaflet-map.ts | 4 +- src/components/leaflet-marker.ts | 14 ++++--- src/components/leaflet-polygon.ts | 8 +++- src/components/leaflet-polyline.ts | 8 +++- src/components/leaflet-popup.ts | 21 +++++++++- src/components/leaflet-rectangle.ts | 6 ++- src/components/leaflet-svg-overlay.ts | 6 ++- src/components/leaflet-tile-layer-wms.ts | 6 ++- src/components/leaflet-tile-layer.ts | 6 ++- src/components/leaflet-tooltip.ts | 21 +++++++++- src/components/leaflet-video-overlay.ts | 6 ++- src/index.ts | 42 +++++++++---------- 24 files changed, 202 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 392e906..a59d11d 100644 --- a/README.md +++ b/README.md @@ -161,13 +161,27 @@ Boolean options that default to `false` are enabled by adding the attribute: ```js const el = document.querySelector('leaflet-map'); -el.map; // L.Map instance (undefined before connected) -el.zoom; // current zoom (reads live from map, falls back to attribute) +el.leafletObject; // L.Map instance (undefined before connected) +el.zoom; // current zoom (reads live from map, falls back to attribute) el.scrollWheelZoom = false; // disable at runtime ``` All `leaflet-map` properties are two-way: reading returns the live map value; writing updates both the attribute and the map. +## Escape hatch + +Every component exposes a `leafletObject` getter that returns the underlying Leaflet instance. This is useful when you need to call Leaflet API methods directly: + +```js +const marker = document.querySelector('leaflet-marker'); +marker.leafletObject?.setLatLng([51.5, -0.09]); + +const map = document.querySelector('leaflet-map'); +map.leafletObject?.flyTo([48.86, 2.35], 13); +``` + +Returns `undefined` while the element isn't connected to the DOM. + ### CSS Leaflet's stylesheet is loaded from a CDN via a `` in the shadow DOM. Marker icon paths are derived from the CSS URL automatically. diff --git a/index.html b/index.html index 704cd7b..a5f82bd 100644 --- a/index.html +++ b/index.html @@ -320,6 +320,13 @@ +