/** * MapLibre GL v5 adapter — grafts onto a host-owned `maplibregl.Map`. * * Builds one source + renderer per {@link LayerSpec} entry, data-driven from the * feature render-props (see the contract in `index.ts`). Dashed lines use a * parallel filtered sub-layer (MapLibre can't data-drive `line-dasharray`); * scallops/barbs are real geometry, so they render identically to OpenLayers. * * The manifest (`layers`) and the hit-testable set (`hitOverlays`) are supplied * by the consumer; this adapter knows no domain type. */ import type { FeatureCollection } from "geojson"; import type { Map as MapLibreMap } from "maplibre-gl"; import type { AdapterOptions, HighlightStyle, KeyEvent, LatLng, LngLatBounds, MapAdapter, MarkerWidget, PointerEvent, ProjectionSpec, SnapshotOptions, SymbolSprites, ToolbarItem, ToolbarOptions, TooltipStyle, WidgetEdit } from "./index.js"; export type Projection = "mercator" | "globe"; /** Batteries-included host map (headless hosts pass their own `map` instead). */ export declare function createMapLibreMap(opts: { container: HTMLElement | string; center: [number, number]; zoom: number; projection?: Projection; }): MapLibreMap; export declare class MapLibreAdapter implements MapAdapter { /** MapLibre exposes the WebGL canvas → snapshot is supported. */ protected readonly snapshotSupported = true; private readonly map; private readonly opts; private readonly overlayIds; private readyPromise; /** rendered MapLibre layer id → overlay id (for hit-testing). */ private readonly renderedToOverlay; private readonly builtLayers; private pointerHandlers; private keyCleanup; private windowUp; private windowBlur; private blurListener; /** Press state captured at `down`, used to emit a `click` ourselves on release — MapLibre's * native `click` can be swallowed by the OS on the first click after re-focusing the window. */ private pressHit; private pressX; private pressY; private pressDown; private justSynthClick; private viewHandler; private toolbarEl; private tooltipEl; private tooltipStyle; private dragging; /** Map-lock state: `locked` freezes all nav and wins over the controller's transient * pan/dbl toggles (remembered in `panOn`/`dblOn`, re-applied on unlock). */ private locked; private panOn; private dblOn; /** Raw sprite SVGs (`currentColor`), re-tinted per feature into `symbol|colour` images. */ private spriteSvgs; /** EVERY image id we added to the host map (bare ids, `id|colour` tints, `data:` * icons), so `destroy()` removes them all — not just the bare sprite ids. */ private readonly addedImages; /** Image ids currently being rasterized (deduplicates `styleimagemissing`). */ private readonly pendingImages; private imgMissing; private widgets; private pointerCb; /** Coord formatter, mirrored from {@link setCoordFormat} so sprite rasterization formats `coord` * leaves the same way the live cards do. */ private coordFmt; /** Whether the `static`-widget sprite source/layer have been added (lazy; only if used). */ private spriteLayerBuilt; /** Image ids baked for sprite icons (`__dap-wsprite|`), removed on `destroy`. */ private readonly spriteImageIds; /** Last rasterized sprite per widget id — skip re-uploading the texture when unchanged (req: * re-raster only on content/dpr change, never per frame/pan/zoom). */ private readonly lastSpriteRef; /** Monotonic token so a superseded async sprite update never clobbers a newer `setWidgets`. */ private spriteToken; constructor(opts: { map: MapLibreMap; } & AdapterOptions); ready(): Promise; registerSymbols(sprites: SymbolSprites): Promise; /** * Lazily materialize any image id the renderer asks for and we don't have yet: * - `data:…` → rasterize the data-URI directly (per-feature handle icons), * - `sprite|colour` → re-tint the raw sprite to that hue (symbol features). */ private bindImageMissing; /** * `icon-image` expression for a `text` layer: a per-feature label-box id * `__box|||||` when the feature carries a `textBackground` * and/or `textBorder`, else `""` (no box). Materialized lazily by * {@link materializeCalloutBox} via `styleimagemissing`. */ private calloutImageExpr; /** * Draw a label box (rounded rect: `textBackground` fill, `textBorder` stroke, * `textBoxRadius` corners) onto a 2× canvas and register it as a **9-slice** image — * the padding (`textBoxSize`) + border + corners are baked into the fixed frame, so * `icon-text-fit` stretches only the centre to the text. This is what lets MapLibre vary * the box per feature (`icon-text-fit-padding` itself is layer-wide). Synchronous. */ private materializeCalloutBox; setOverlay(id: string, data: FeatureCollection): void; setOverlayVisible(id: string, visible: boolean): void; setTooltip(text: string | null, at: LatLng, style?: TooltipStyle): void; addToolbar(items: ToolbarItem[], options?: ToolbarOptions): HTMLElement; setActiveTool(id: string | null): void; /** Capture the map as PNG, then apply `opts.target` (download/clipboard/none). The * capture promise is handed to `deliverSnapshot` *pending* so a clipboard write fires * synchronously within the click (gesture-safe). */ snapshot(opts?: SnapshotOptions): Promise; /** * Capture the GL canvas inside a render frame (no `preserveDrawingBuffer` * needed): listen for the next `render`, then read the canvas. `scale` defaults * to the current device-pixel-ratio (the canvas is already at that density); * a different `scale` re-draws the composition onto a resized canvas — a downscale * (`low`) is clean, an upscale (`medium`/`high`) is a best-effort enlargement. */ private capture; /** Hide every built layer belonging to the given overlay ids; returns a function that * restores their previous `visibility`. Used to drop editing chrome from a snapshot. */ private hideOverlays; getCenter(): LatLng; getViewSpan(): number; getBounds(): LngLatBounds; getZoom(): number; getContainer(): HTMLElement; fitBounds(bbox: LngLatBounds, opts?: { padding?: number; }): void; setProjection(projection: ProjectionSpec): void; viewArea(extent: LngLatBounds, opts?: { padding?: number; duration?: number; }): void; highlightArea(extent: LngLatBounds | null, style?: HighlightStyle): void; project(p: LatLng): [number, number] | null; unproject(px: [number, number]): LatLng | null; onViewChange(cb: () => void): void; setPanEnabled(enabled: boolean): void; setDoubleClickZoom(enabled: boolean): void; setInteractive(enabled: boolean): void; setCursor(cursor: string): void; onPointer(cb: (ev: PointerEvent) => void): void; onKey(cb: (ev: KeyEvent) => void): void; onBlur(cb: () => void): void; private widgetLayer; setWidgets(widgets: MarkerWidget[]): void; onWidgetEdit(cb: (e: WidgetEdit) => void): void; onWidgetDelete(cb: (e: { id: string; }) => void): void; onWidgetAction(cb: (e: { id: string; event: string; }) => void): void; setCoordFormat(fn: (ll: LatLng) => string): void; /** Add the sprite source + symbol layer once (lazy: only when a `static` widget appears). The layer * is mapped to {@link WSPRITE_HIT_OVERLAY} so its features hit-test like canvas call-outs. */ private ensureSpriteLayer; /** * Rasterize each `static` widget to a native icon and push them as point features (props * `{ featureId, labelId }`) into the sprite layer. Async (glyph rasterization) and token-guarded so * a newer call wins; the image texture is only (re)uploaded when the sprite actually changed. */ private updateSprites; destroy(): void; private hitAt; private track; private iconImageExpr; private addOverlays; } //# sourceMappingURL=maplibre.d.ts.map