import { Evented, ControlPosition, CustomLayerInterface, FilterSpecification, IControl, Map as MaplibreMap, MapLibreEvent } from 'maplibre-gl'; /** Root metadata key under which a Maptoolkit style carries its 3D scene. */ export declare const SCENE3D_METADATA_KEY = "maptoolkit:scene3d"; /** * Where a layer of the scene goes: under the style's labels (`"below-labels"`, the default: right below its first * symbol layer), on top of everything (`"top"`), or right below the style layer with that id. The position only * decides what draws over the 3D among symbol layers (labels, icons); fills and lines always end up under it. A * layer id the style lacks falls back to `"below-labels"`. */ export type Scene3dPosition = "below-labels" | "top" | (string & {}); type Expression = unknown; /** One glTF vegetation layer: maplibre-3d-layers `GltfLayer` options, `models` as ids of the scene's model library. */ export interface Scene3dGltfLayer { id: string; position?: Scene3dPosition; /** Model ids from {@link Scene3dManifest.models}; all of them when missing. */ models?: string[]; source: string; "source-layer"?: string; filter?: FilterSpecification; minzoom?: number; maxzoom?: number; layout?: Record; paint?: Record; lighting?: { ambient?: number; directional?: number; environment?: number; }; maxInstances?: number; doubleSided?: boolean; } /** The 3D scene of a style, `metadata["maptoolkit:scene3d"]` (version 1). Values are plain MapLibre / maplibre-3d-layers options. */ export interface Scene3dManifest { version: 1; /** TileJSON URL of the buildings source, without api_key. */ source: string; /** `fill-extrusion` on the source layer `buildings2d`. */ lod1?: { position?: Scene3dPosition; minzoom?: number; maxzoom?: number; filter?: FilterSpecification; paint?: Record; layout?: Record; }; /** * `Fill3DLayer` on the source layer `buildings3d`. With `extrusion` it also extrudes the 2D footprints of a source * layer of the same tiles (maplibre-3d-layers ≥ 0.6.0, experimental), so that they get its shading and fake ambient * occlusion; leave the same footprints out of `lod1` where it does, by a filter on the tile zoom (not `maxzoom`). */ fill3d?: { position?: Scene3dPosition; filter?: FilterSpecification; paint?: Record; extrusion?: { "source-layer": string; filter?: FilterSpecification; height?: Expression; base?: Expression; }; }; /** * The landmarks in the source layer `buildings3d`, as a `Fill3DLayer` of their own: with their own paint and their * own place among the style's layers. `filter` picks them (default `["==", ["get", "source"], "landmark"]`), and * `fill3d` then leaves those features out. */ landmarks?: { position?: Scene3dPosition; filter?: FilterSpecification; paint?: Record; }; /** Model library of the vegetation: id → glTF/glb URL. */ models?: Record; gltf?: Scene3dGltfLayer[]; } /** What the control needs from `@maptoolkit/maplibre-3d-layers`. */ export interface Scene3dLibrary { Fill3DLayer: new (options: Record) => CustomLayerInterface; GltfLayer: new (options: Record) => CustomLayerInterface; } export interface Scene3dControlOptions { /** Maptoolkit API key, added to the buildings source URL as `api_key`. */ apiKey?: string; /** * The scene to show. Left out: the one the current style names in `metadata["maptoolkit:scene3d"]`, * re-read on every style change. A manifest or its URL replaces it; `null` shows none. */ scene?: Scene3dManifest | string | null; /** Show the scene right away (default `true`). */ enabled?: boolean; /** Add a 3D button that switches the scene on and off (default `false`: the control has no UI). */ button?: boolean; /** The 3D library is loaded once the map reaches this zoom; the buildings source has no tiles below 12 (default `12`). */ minzoom?: number; /** * Style layers hidden while the scene's buildings are shown, e.g. a style's own 3D buildings (default the v2 ids * `building_3d`, `building_3d_multicolored`). Hidden only once the buildings source has loaded, so without a working * API key the style keeps them. */ hideLayers?: string[]; /** Base for relative model URLs (default the document's base URL). */ modelBase?: string; /** Loads `@maptoolkit/maplibre-3d-layers` (default a dynamic import of the package). Pass another loader for its standalone build or a CDN. */ library?: () => Promise; /** Prefix of the source and layer ids the control adds (default `"scene3d-"`). */ idPrefix?: string; } /** Fired via `control.on("scene.change", ...)` whenever the shown scene is (re)built or removed. */ export type Scene3dControlEventType = { "scene.change": MapLibreEvent<"scene.change"> & { scene: Scene3dManifest | null; }; }; type ResolvedOptions = Required> & Pick; /** * A MapLibre GL JS control plugin that adds the 3D scene of a Maptoolkit style: 3D buildings * (a `fill-extrusion` plus maplibre-3d-layers' `Fill3DLayer`), the landmarks among them (a `Fill3DLayer` * of their own) and glTF vegetation (`GltfLayer`). * * The scene comes from the style itself (`metadata["maptoolkit:scene3d"]`, written by style-family-js), * so a style switch brings its own scene. The control keeps the tilt in the global state `pitch` * that the scene's opacity fades read, puts the layers under the style's labels, rebuilds them after * a style change and loads the 3D library only when the map gets close enough. A terrain that is * switched on, off or changed leaves the 3D layers as they are: they move onto it themselves. */ export declare class Scene3dControl extends Evented implements IControl { readonly options: ResolvedOptions; private map?; private container?; private button?; private enabled; /** undefined: the style's own scene. */ private override; private scene; private lib?; private libPromise?; private custom; private native; private hidden; private loadedStyle; private pitch; private building; private generation; private warned; /** Stops waiting for the buildings source (see hideOnceBuildingsLoad). */ private stopWaiting?; /** The scene last read from the style or override (also an unsupported one), and as JSON; null for none. */ private sceneRef; private sceneKey; /** Whether the buildings source of the current scene has loaded (its TileJSON answered). */ private sourceOk; /** The position each custom layer was added with (`"below-labels"` when the scene names none). */ private customPosition; constructor(options?: Scene3dControlOptions); getDefaultPosition(): ControlPosition; onAdd(map: MaplibreMap): HTMLElement; onRemove(): void; /** * Replace the style's scene: a manifest, the URL of one, `null` for none, or `undefined` to go back * to the style's own scene. The same scene again keeps the layers. * * MapLibre ignores a diffed `setStyle` that changes nothing but the metadata, so a scene that changes * on its own never reaches the control that way; pass it here (or use `setStyle` with `diff: false`). */ setScene(scene: Scene3dManifest | string | null | undefined): Promise; /** The scene shown now, or null. */ getScene(): Scene3dManifest | null; setEnabled(enabled: boolean): void; isEnabled(): boolean; /** The maplibre-3d-layers layers on the map (`Fill3DLayer`, `GltfLayer`s), e.g. to drive them frame by frame. */ getLayers(): CustomLayerInterface[]; /** The 3D library, once loaded. */ getLibrary(): Scene3dLibrary | undefined; /** Load the 3D library now instead of waiting for `minzoom`. */ loadLibrary(): Promise; private onStyleLoad; private onStyleData; private syncWithStyle; private onZoom; /** `["global-state", "pitch"]` for the scene's opacity fades. Whole degrees: each change is a style update. */ private syncPitch; private styleReady; private currentScene; private refresh; private sourceId; /** The id of the style's first symbol layer: the scene goes right below it. */ private labelsAnchor; /** The layer a scene layer goes below for `position`: none for "top", the style layer it names, else `anchor`. */ private beforeFor; /** * The buildings source and the native layers, each below the layer its position names. `place` can pick another * layer for a position (restoreNative: the 3D layers with the same position). */ private addNative; /** After a diffed setStyle with the same scene: put back the source and native layers, keep the 3D layers. */ private restoreNative; private loadCustom; private addCustom; private removeCustom; /** Remove everything the control added; `restore` puts hidden style layers back. */ private teardown; /** * Hide the style's own 3D buildings (`hideLayers`) only once the scene's buildings source has * loaded. Without a working API key it answers 403, and the style keeps its buildings. */ private hideOnceBuildingsLoad; private hideStyleLayers; private withKey; private modelUrl; private showState; private warnOnce; } export {};