import { GeoJSON, type PathOptions } from 'leaflet'; import type { GeoJsonObject } from 'geojson'; import { json, positional } from '../core/props.ts'; import { pathProps } from '../core/shared-props.ts'; import { WithProps, type LeafletAddEventListener, type LeafletRemoveEventListener, } from '../core/with-props.ts'; import type { GroupEvents } from '../core/event-types.ts'; export default class LeafletGeoJSONElement extends WithProps({ data: positional( json(null, { set(obj: GeoJSON, value) { obj.clearLayers(); if (value) obj.addData(value); }, }), ), ...pathProps, }) { declare readonly leafletObject?: GeoJSON; declare addEventListener: LeafletAddEventListener; declare removeEventListener: LeafletRemoveEventListener; // Every prop but `data` is a style option, and GeoJSON takes those nested // under `style` so they apply to each feature it builds. createLeafletObject(options: PathOptions): GeoJSON { return new GeoJSON(this.data, { style: options }); } }