refactor(leaflet-map): rename syncFit -> applyFit
Mirrors the sibling applyCss(): both run on connect and on every relevant attribute change. The prop set-handler that calls it becomes reapplyFit, the same relinkCss -> applyCss shape.
This commit is contained in:
parent
cd2c8d0fc5
commit
36e1f5fe49
@ -42,13 +42,13 @@ function relinkCss(_map: LMap, _value: string, el: HTMLElement): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface FitHost extends HTMLElement {
|
interface FitHost extends HTMLElement {
|
||||||
syncFit(): void;
|
applyFit(): 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 reapplyFit(_map: LMap, _value: unknown, el: HTMLElement): void {
|
||||||
(el as FitHost).syncFit();
|
(el as FitHost).applyFit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 syncFit() below. With `fit-to-markers` present
|
// Not Leaflet options -- see applyFit() 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: reapplyFit })),
|
||||||
fitPadding: positional(num<LMap>(20, { set: applyFit })),
|
fitPadding: positional(num<LMap>(20, { set: reapplyFit })),
|
||||||
fitMaxZoom: positional(num<LMap>(Infinity, { set: applyFit })),
|
fitMaxZoom: positional(num<LMap>(Infinity, { set: reapplyFit })),
|
||||||
};
|
};
|
||||||
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 `syncFit()`.
|
* `lat`/`lng`/`zoom` — see `applyFit()`.
|
||||||
*/
|
*/
|
||||||
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.syncFit();
|
this.applyFit();
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectedCallback(): void {
|
disconnectedCallback(): void {
|
||||||
@ -303,11 +303,12 @@ export default class LeafletMapElement extends Base {
|
|||||||
Icon.Default.imagePath = url?.replace(/\/[^/]+$/u, '/images/');
|
Icon.Default.imagePath = url?.replace(/\/[^/]+$/u, '/images/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user