58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
// Type shim for the headless `esquisse` map package (ships JS only, no .d.ts).
|
|
// Only the surface we consume here is declared.
|
|
declare module "esquisse" {
|
|
import type {
|
|
Map as MaplibreMap,
|
|
LngLat,
|
|
MapGeoJSONFeature,
|
|
SourceSpecification,
|
|
} from "maplibre-gl"
|
|
|
|
export interface CreateMapOptions {
|
|
/** The MapLibre GL module namespace (its default export). */
|
|
maplibre: unknown
|
|
/** The pmtiles module namespace, to register the `pmtiles://` protocol. */
|
|
pmtiles?: unknown
|
|
container: string | HTMLElement
|
|
baseStyle: string
|
|
center?: [number, number]
|
|
zoom?: number
|
|
syncUrl?: boolean
|
|
globe?: boolean
|
|
}
|
|
|
|
/** A MapLibre `Map` subclass: the full MapLibre API plus esquisse helpers. */
|
|
export interface OsmMap extends MaplibreMap {
|
|
/** Runs `fn` now if the map is already loaded, otherwise on the next load. */
|
|
onLoadOrNow(fn: () => void): void
|
|
/** Swaps the base style, preserving custom (`custom-…`) sources/layers. */
|
|
changeBaseMap(url: string): Promise<void>
|
|
}
|
|
|
|
export interface AbstractLayerOptions {
|
|
map: OsmMap
|
|
visibleOnLoad?: boolean
|
|
baseStyle?: string | null
|
|
}
|
|
|
|
/** Base class for custom map layers; manages `custom-…` sources/layers. */
|
|
export class AbstractLayer {
|
|
constructor(options: AbstractLayerOptions)
|
|
map: OsmMap
|
|
layersIds: string[]
|
|
sourcesIds: string[]
|
|
beforeLayer: string | null
|
|
visibleOnLoad: boolean
|
|
baseStyle: string | null
|
|
|
|
addSource(id: string, source: SourceSpecification): void
|
|
addLayer(layer: LayerSpecification, before?: string | null): void
|
|
show(): Promise<void>
|
|
hide(): Promise<void>
|
|
onClick(
|
|
callback: (feature: MapGeoJSONFeature | null, lngLat: LngLat) => void,
|
|
): this
|
|
}
|
|
|
|
export function createMap(options: CreateMapOptions): OsmMap
|
|
}
|