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: 'bottomleft' }, maxWidth: { kind: 'num', attr: 'max-width', default: 100 }, metric: { kind: 'bool-on', attr: 'metric' }, imperial: { kind: 'bool-on', attr: 'imperial' }, updateWhenIdle: { kind: 'bool-on', attr: 'update-when-idle' }, } satisfies Record; export class LeafletControlScale extends withProps(HTMLElement, PROPS) { #obj?: Control.Scale; connectedCallback() { this.#obj = new Control.Scale({ position: this.getAttribute('position') as ControlPosition | undefined, maxWidth: parseInt(this.getAttribute('max-width') ?? '100', 10), metric: !this.hasAttribute('metric') || this.getAttribute('metric') !== 'false', imperial: !this.hasAttribute('imperial') || this.getAttribute('imperial') !== 'false', updateWhenIdle: !this.hasAttribute('update-when-idle') || this.getAttribute('update-when-idle') !== 'false', }); registerWithParent(this, this.#obj); } disconnectedCallback() { this.#obj?.remove(); this.#obj = undefined; } } customElements.define('leaflet-control-scale', LeafletControlScale);