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-scale.ts

37 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: '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<string, PropDef>;
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);