You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
leaflet-components/src/components/leaflet-control-zoom.ts

36 lines
1.3 KiB
TypeScript

import { Control, ControlPosition } from 'leaflet';
import { registerWithParent } from '../core/utils.js';
import { withProps } from '../core/with-props.js';
import type { PropDef } from '../types/props.js';
const PROPS = {
position: { kind: 'str', attr: 'position', default: 'topleft' },
zoomInText: { kind: 'str', attr: 'zoom-in-text', default: '+' },
zoomInTitle: { kind: 'str', attr: 'zoom-in-title', default: 'Zoom in' },
zoomOutText: { kind: 'str', attr: 'zoom-out-text', default: '-' },
zoomOutTitle: { kind: 'str', attr: 'zoom-out-title', default: 'Zoom out' },
} satisfies Record<string, PropDef>;
export class LeafletControlZoom extends withProps(HTMLElement, PROPS) {
#obj?: Control.Zoom;
connectedCallback() {
this.#obj = new Control.Zoom({
position: this.getAttribute('position') as ControlPosition | undefined,
zoomInText: this.getAttribute('zoom-in-text') ?? '+',
zoomInTitle: this.getAttribute('zoom-in-title') ?? 'Zoom in',
zoomOutText: this.getAttribute('zoom-out-text') ?? '-',
zoomOutTitle: this.getAttribute('zoom-out-title') ?? 'Zoom out',
});
registerWithParent(this, this.#obj);
}
disconnectedCallback() {
this.#obj?.remove();
this.#obj = undefined;
}
}
customElements.define('leaflet-control-zoom', LeafletControlZoom);