@ -42,13 +42,13 @@ function relinkCss(_map: LMap, _value: string, el: HTMLElement): void {
}
}
interface FitHost extends HTMLElement {
interface FitHost extends HTMLElement {
sync Fit( ) : void ;
apply Fit( ) : void ;
}
}
// The fit-* attributes aren't Leaflet options either: they ask the element to
// The fit-* attributes aren't Leaflet options either: they ask the element to
// frame every point/bounds layer itself. Any change just re-runs that.
// frame every point/bounds layer itself. Any change just re-runs that.
function applyFit( _map : LMap , _value : unknown , el : HTMLElement ) : void {
function re applyFit( _map : LMap , _value : unknown , el : HTMLElement ) : void {
( el as FitHost ) . sync Fit( ) ;
( el as FitHost ) . apply Fit( ) ;
}
}
// Anything with a position we can fold into a bounding box -- markers,
// Anything with a position we can fold into a bounding box -- markers,
@ -197,16 +197,16 @@ const PROPS: {
cssIntegrity : positional ( str ( DEFAULT_CSS_INTEGRITY , { set : relinkCss } ) ) ,
cssIntegrity : positional ( str ( DEFAULT_CSS_INTEGRITY , { set : relinkCss } ) ) ,
cssCrossorigin : positional ( str ( '' , { set : relinkCss } ) ) ,
cssCrossorigin : positional ( str ( '' , { set : relinkCss } ) ) ,
// Not Leaflet options -- see sync Fit() below. With `fit-to-markers` present
// Not Leaflet options -- see apply Fit() below. With `fit-to-markers` present
// the map ignores lat/lng/zoom and frames every point/bounds layer that has
// the map ignores lat/lng/zoom and frames every point/bounds layer that has
// registered. It reframes only when a new component registers (initial load
// registered. It reframes only when a new component registers (initial load
// and later additions) -- panning, zooming, opening a popup and removing a
// and later additions) -- panning, zooming, opening a popup and removing a
// marker all leave the view untouched. `fit-padding` is the pixel gutter
// marker all leave the view untouched. `fit-padding` is the pixel gutter
// kept around the bounds; `fit-max-zoom` caps how far it zooms in (useful
// kept around the bounds; `fit-max-zoom` caps how far it zooms in (useful
// when a single marker would otherwise snap to max zoom).
// when a single marker would otherwise snap to max zoom).
fitToMarkers : positional ( bool < LMap > ( false , { set : applyFit } ) ) ,
fitToMarkers : positional ( bool < LMap > ( false , { set : re applyFit } ) ) ,
fitPadding : positional ( num < LMap > ( 20 , { set : applyFit } ) ) ,
fitPadding : positional ( num < LMap > ( 20 , { set : re applyFit } ) ) ,
fitMaxZoom : positional ( num < LMap > ( Infinity , { set : applyFit } ) ) ,
fitMaxZoom : positional ( num < LMap > ( Infinity , { set : re applyFit } ) ) ,
} ;
} ;
const Base : LeafletElementConstructor < LMap , typeof PROPS > = WithProps ( PROPS , { attach : 'none' } ) ;
const Base : LeafletElementConstructor < LMap , typeof PROPS > = WithProps ( PROPS , { attach : 'none' } ) ;
@ -217,7 +217,7 @@ const Base: LeafletElementConstructor<LMap, typeof PROPS> = WithProps(PROPS, { a
* CSS ` <link> ` ) , runs a ` ResizeObserver ` → ` invalidateSize() ` , and treats its
* CSS ` <link> ` ) , runs a ` ResizeObserver ` → ` invalidateSize() ` , and treats its
* ` css-* ` attributes as describing the shadow stylesheet . With ` fit-to-markers `
* ` css-* ` attributes as describing the shadow stylesheet . With ` fit-to-markers `
* set it frames every registered point / bounds layer instead of honouring
* set it frames every registered point / bounds layer instead of honouring
* ` lat ` / ` lng ` / ` zoom ` — see ` sync Fit()` .
* ` lat ` / ` lng ` / ` zoom ` — see ` apply Fit()` .
* /
* /
export default class LeafletMapElement extends Base {
export default class LeafletMapElement extends Base {
declare readonly leafletObject? : LMap ;
declare readonly leafletObject? : LMap ;
@ -251,7 +251,7 @@ export default class LeafletMapElement extends Base {
this . addEventListener ( 'leaflet-add-layer' , this . # onAddLayer ) ;
this . addEventListener ( 'leaflet-add-layer' , this . # onAddLayer ) ;
this . addEventListener ( 'leaflet-remove-layer' , this . # onRemoveLayer ) ;
this . addEventListener ( 'leaflet-remove-layer' , this . # onRemoveLayer ) ;
this . sync Fit( ) ;
this . apply Fit( ) ;
}
}
disconnectedCallback ( ) : void {
disconnectedCallback ( ) : void {
@ -303,11 +303,12 @@ export default class LeafletMapElement extends Base {
Icon . Default . imagePath = url ? . replace ( / \ / [ ^ / ] + $ / u , ' / i m a g e s / ' ) ;
Icon . Default . imagePath = url ? . replace ( / \ / [ ^ / ] + $ / u , ' / i m a g e s / ' ) ;
}
}
// Called on connect and whenever a fit-* attribute changes. Records whether
// Called on connect and whenever a fit-* attribute changes -- the sibling of
// framing is on (read by #onRegister) and requests an immediate (re)frame
// applyCss() above. Records whether framing is on (read by #onRegister) and
// when it is. No Leaflet event subscriptions: the only reframe trigger is a
// requests an immediate (re)frame when it is. No Leaflet event
// new component registering -- see #onRegister.
// subscriptions: the only reframe trigger is a new component registering --
syncFit ( ) : void {
// see #onRegister.
applyFit ( ) : void {
if ( ! this . leafletObject ) return ;
if ( ! this . leafletObject ) return ;
this . # fitActive = this . fitToMarkers ;
this . # fitActive = this . fitToMarkers ;
if ( this . # fitActive ) this . # scheduleFit ( ) ;
if ( this . # fitActive ) this . # scheduleFit ( ) ;