leaflet-realtime
leaflet-realtime copied to clipboard
Generate types
Hi,
Thanks for the plugin, it's a lifesaver :)
When working with Typescript, it would be nice if types were available out of the box or through DefinitelyTyped.
For me it's working with the declaration I created (see below), but for the sake of consistency.
// leaflet-realtime.d.ts
declare module 'leaflet-realtime' {
import { Feature, GeoJsonObject } from 'geojson'
import {
FeatureGroup,
GeoJSON,
GeoJSONOptions,
Layer,
LayerGroup,
} from 'leaflet'
type RealtimeFunctionSource = (
responseHandler: (data: GeoJSON) => void,
errorHandler: (err: Error, msg: string) => void
) => void
type RealtimeUrlSource = RequestInit & { url: string } & {
[key: string]: unknown
}
type RealtimeSource = RealtimeFunctionSource | RealtimeUrlSource | string
interface RealtimeOptions<P> extends GeoJSONOptions<P> {
cache?: boolean
container?: LayerGroup
getFeatureId?: (f: Feature) => unknown
interval?: number
logErrors?: boolean
onlyRunWhenAdded?: boolean
removeMissing?: boolean
start?: boolean
updateFeature?: (feature: Feature, oldLayer: Layer) => Layer
}
export default class Realtime<P> extends FeatureGroup {
constructor(src: RealtimeSource, options?: RealtimeOptions<P>)
getLayer(featureId: number | string): Layer | undefined
start(): this
stop(): this
update(geojson?: GeoJsonObject | GeoJsonObject[]): this
}
}