import { Icon, type IconOptions, type PointExpression } from 'leaflet'; import { json, str, type PropDef } from '../core/props.ts'; import { emitIconChanged } from '../core/register.ts'; import { WithProps, type LeafletElementConstructor } from '../core/with-props.ts'; const PROPS: { iconUrl: PropDef; iconRetinaUrl: PropDef; iconSize: PropDef; iconAnchor: PropDef; popupAnchor: PropDef; tooltipAnchor: PropDef; shadowUrl: PropDef; shadowRetinaUrl: PropDef; shadowSize: PropDef; shadowAnchor: PropDef; className: PropDef; } = { iconUrl: str(), iconRetinaUrl: str(), iconSize: json([0, 0]), iconAnchor: json([0, 0]), popupAnchor: json([0, 0]), tooltipAnchor: json([0, 0]), shadowUrl: str(), shadowRetinaUrl: str(), shadowSize: json([0, 0]), shadowAnchor: json([0, 0]), className: str(), }; // An Icon has no setters, so every attribute change builds a new one and the // parent marker is told to swap it in. const Base: LeafletElementConstructor = WithProps(PROPS, { attach: 'none', recreate: true, }); /** `` — a Leaflet `Icon` (an image marker icon). Child of ``; rebuilt on every attribute change and swapped in via `setIcon()`. */ export default class LeafletIconElement extends Base { declare readonly leafletObject?: Icon; createLeafletObject(options: Partial): Icon | undefined { return options.iconUrl ? new Icon(options as IconOptions) : undefined; } leafletObjectCreated(): void { emitIconChanged(this, this.leafletObject); } disconnectedCallback(): void { super.disconnectedCallback(); emitIconChanged(this, null); } }