astro-leaflet
Version:
Leaflet astro component, to display maps: Google Maps, Openstreetmap, maps from Michelin, googlemaps, Open Street Map...
24 lines (21 loc) • 851 B
text/typescript
// Copyright (c) Pascal Brand
// MIT License
import { getMapFromElement } from '../../index'
import type { CustomElementLeafletGeneric } from './generic'
export class CustomElementFitBounds extends HTMLElement {
constructor() {
super()
const map = getMapFromElement(this)
if (map) {
// take the parent. cast to a CustomElementLeafletGeneric, even if not, just to check access to leafletElement
const parent = this.parentElement as CustomElementLeafletGeneric | undefined
if (parent && parent.leafletElement && parent.leafletElement.getBounds) {
map.fitBounds(parent.leafletElement.getBounds())
} else {
console.error('astro-leaflet <FitBounds/>: no getbounds in parent')
}
} else {
console.error('astro-leaflet <FitBounds/>: no map in parent')
}
}
}