/** * The renderer boundary (ADR-011, Decision 10). Bidirectional: the engine pushes scenes and patches in; * the renderer reports camera moves, picks, clicks, hover and errors back — always as stable objectIds. * A renderer holds no business logic and never queries data. */ import type { BasemapConfig, MapConfig, MapViewport, Position, RendererCapabilities, ScenePatch, SceneState, Size, TerrainConfig, TilesetConfig, Unsubscribe } from '../core/types.js'; export type { RendererCapabilities }; export interface RendererOptions { basemap: BasemapConfig; viewport: MapViewport; projection?: MapConfig['projection']; terrain?: TerrainConfig; tilesets?: TilesetConfig[]; /** The offline profile (doc 28 G14): a renderer refuses anything it fetches that would leave these origins. */ offline?: { allowedOrigins: string[]; }; } export interface PickEvent { objectId: string; layerId: string; /** Where the pointer was. Renderers provide it for clicks; hover may omit it. */ position?: Position; } export interface MapClickEvent { position: Position; } /** * Lifecycle (doc §65): initialize → render/update → destroy. destroy() releases everything (GPU context, DOM, * listeners) and cancels an initialize still in flight; initialize() may then be called again — the runtime * unmounts and remounts with the same renderer. */ export interface Renderer { initialize(container: HTMLElement, options: RendererOptions): Promise; /** * Swaps the basemap and keeps the map (camera, GPU context). Engine layers are gone afterwards: the runtime * calls render() with the full scene once this resolves. Optional; without it the runtime remounts. */ setBasemap?(basemap: BasemapConfig): Promise; readonly capabilities?: RendererCapabilities; /** Flat map or globe. Optional; a renderer without it cannot draw a globe (see capabilities). */ setProjection?(projection: NonNullable): void; /** Turns terrain relief on (a config) or off (null). */ setTerrain?(terrain: TerrainConfig | null): void; /** Replaces the 3D Tiles scenery (needs `tiles3d`). */ setTilesets?(tilesets: TilesetConfig[]): void; /** Ground heights (metres above sea level) under positions, from the renderer's terrain; null where unknown. */ sampleElevation?(positions: Position[]): Promise>; setViewport(viewport: MapViewport, options?: { animate?: boolean; }): void; /** Full scene (first draw, or after a reset). */ render(scene: SceneState): void; /** Incremental change; must not rebuild the whole scene (ADR-014). */ update(patch: ScenePatch): void; resize(): void; /** Drawing surface size in CSS pixels; the engine uses it to compute viewport bounds. */ getSize(): Size; destroy(): void; /** Camera settled (user or programmatic). Includes the renderer's real visible bounds. */ onViewportChange(listener: (viewport: MapViewport) => void): Unsubscribe; onPick(listener: (event: PickEvent) => void): Unsubscribe; /** Click on the map that did not hit an object. */ onMapClick(listener: (event: MapClickEvent) => void): Unsubscribe; onHover(listener: (event: PickEvent | null) => void): Unsubscribe; onError(listener: (error: Error) => void): Unsubscribe; /** Screen pixel of a position inside the map container (for overlays such as popups). Optional. */ project?(position: Position): { x: number; y: number; } | null; /** Every camera frame while it moves (pan, zoom, animation), for overlays that follow the map. Optional. */ onCameraMove?(listener: () => void): Unsubscribe; }