API-reference og typer
Genereret fra den aktuelle TypeScript-kilde. Se SDK-vejledningen for semantik, gyldige intervaller, events, callbacks og sikkerhedsgrænser. Koordinater er [longitude, latitude]. Await ready før kortkommandoer; asynkrone metoder returnerer promises.
Offentlige medlemmer
import { DEFAULTS, deepMerge } from './config.js';
import { AuthorizedSource, ResourcePolicy } from './network.js';
import type { ClusterInfo, ConfigurationLayer, Coordinates, EventHandler, MapConfiguration, MapConstructorOptions, MarkerInput, PopupContent, PopupProvider, ShapeData, ShapeOptions, Theme } from './types.js';
export type * from './types.js';
/** Concrete distribution version injected into both browser bundles at build time. */
export declare const version: string;
export { AuthorizedSource, DEFAULTS, deepMerge, ResourcePolicy };
/** Framework-independent map. Await ready before methods that move the camera. */
export declare class Map {
readonly ready: Promise<this>;
readonly container: HTMLElement;
config: MapConfiguration;
constructor(options: MapConstructorOptions);
/** Renew configuration/data lifetime. Cached state remains usable after a failed renewal. */
refreshSession(): Promise<this>;
/** Validated runtime settings. Data, filters, popup, camera and the renderer instance survive. */
updateConfiguration(patch: ConfigurationLayer): Promise<this>;
setOptions(patch: ConfigurationLayer): Promise<this>;
on(type: string, handler: EventHandler): this;
off(type: string, handler: EventHandler): this;
getDataVersion(): string | undefined;
getDataUrl(): string | undefined;
getAvailableThemes(): Theme[];
getCenter(): Coordinates;
getZoom(): number;
setCenter(center: Coordinates): this;
setZoom(zoom: number): this;
resize(): this;
flyTo(center: Coordinates, zoom?: number): this;
setTheme(theme: Theme): Promise<this>;
setMarkers(input: MarkerInput[]): this;
addMarker(marker: MarkerInput): this;
updateMarker(id: string, patch: Partial<Omit<MarkerInput, 'id'>>): this;
removeMarker(id: string): this;
getMarkers(): MarkerInput[];
getMarker(id: string): MarkerInput | undefined;
addMarkers(markers: MarkerInput[]): this;
clearMarkers(): this;
setMarkersVisible(visible: boolean): this;
setGroupVisible(group: string, visible: boolean): this;
setCategoryVisible(category: string, visible: boolean): this;
setFilter(predicate?: (marker: MarkerInput) => boolean): this;
getClusterLeaves(id: number, limit?: number, offset?: number, group?: string): Promise<MarkerInput[]>;
expandCluster(cluster: ClusterInfo): Promise<void>;
openPopup(id: string, override?: PopupContent | PopupProvider): Promise<void>;
closePopup(): this;
openClusterPopup(id: number, content?: PopupContent | PopupProvider, group?: string): Promise<void>;
addGeoJSON(id: string, data: ShapeData, options?: ShapeOptions): this;
addLine(id: string, positions: Coordinates[], options?: ShapeOptions): this;
addPolygon(id: string, rings: Coordinates[][], options?: ShapeOptions): this;
addCircle(id: string, center: Coordinates, radiusMeters: number, options?: ShapeOptions): this;
removeShape(id: string): this;
fitGeometry(data: ShapeData, padding?: number): this;
fitMarkers(padding?: number): this;
/** Invoke in a click/key event. Never requests a position on initialization. */
locate(event: Event): boolean;
destroy(): void;
}
Eksporterede parametre og datatyper
Valgfrie felter markeres med ?; deres standarder arves gennem konfigurationshierarkiet. Funktioner/DOM-fabrikker leveres kun i browserkode og kan ikke serialiseres i projektets JSON-konfiguration.
import type { ExpressionSpecification, StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
import type { Feature, FeatureCollection, Geometry } from 'geojson';
export type Coordinates = [longitude: number, latitude: number];
export type Theme = 'standard' | 'nature' | 'dark';
export type ScrollZoom = 'enabled' | 'disabled' | 'ctrl';
export type Token = string | { accessToken: string; expiresAt: string | number };
export type TokenProvider = (signal?: AbortSignal) => Token | Promise<Token>;
export interface ServerConfig {
dataVersion: string;
dataUrl: string;
styleUrls: Record<Theme, string>;
/** Project-authorized themes. Omitted retains compatibility with all three themes. */
availableThemes?: Theme[];
defaults?: ConfigurationLayer;
clientId?: string;
sessionExpiresAt?: string;
maximumSessionSeconds?: number;
}
export type PopupContent = string | { text: string } | { html: string } | { trustedDOM: HTMLElement };
export type PopupProvider = (marker: MarkerInput, signal: AbortSignal) => PopupContent | Promise<PopupContent>;
export interface PopupSettings {
closeButton: boolean;
closeOnClick: boolean;
className?: string;
minWidth: number;
maxWidth: number;
anchor?: 'top' | 'bottom' | 'left' | 'right' | 'center';
offset: number;
onOpen?: (marker: MarkerInput) => void;
onClose?: () => void;
}
export interface MarkerSettings {
icon?: string;
categoryIcon?: 'nature' | 'food' | 'parking' | 'home' | 'information';
width: number;
height: number;
color: string;
anchor: 'bottom' | 'center' | 'top';
rotation: number;
offset: [number, number];
opacity: number;
zIndex: number;
}
export interface MarkerInput {
id: string;
coordinates: Coordinates;
data?: unknown;
categories?: string[];
groups?: string[];
title?: string;
description?: string;
tooltip?: string;
icon?: string;
/** Inline SVG, sanitized and rasterized into a GPU icon. Takes precedence over icon URL. */
iconSvg?: string;
width?: number;
height?: number;
anchor?: 'bottom' | 'center' | 'top';
color?: string;
rotation?: number;
offset?: [number, number];
opacity?: number;
zIndex?: number;
/** Points with different clusterGroup values never share a cluster. */
clusterGroup?: string;
/** Built-in pin pictogram; custom icon URL takes precedence. */
categoryIcon?: 'nature' | 'food' | 'parking' | 'home' | 'information';
popupOptions?: Partial<PopupSettings>;
visible?: boolean;
/** Explicit trusted DOM factory; use textContent for untrusted data. */
html?: (marker: MarkerInput) => HTMLElement;
popup?: PopupContent | PopupProvider;
onClick?: (marker: MarkerInput, event: MapEvent) => boolean | void;
}
export interface ClusterOptions {
enabled: boolean;
radius: number;
minPoints: number;
maxZoom: number;
color: string;
textColor: string;
showCount: boolean;
categoryColors?: Record<string, string>;
/** MapLibre expression for radius, based on point_count. */
radiusExpression?: ExpressionSpecification;
/** Optional GPU cluster icon; falls back to default circles on failure. */
icon?: string;
html?: (count: number, clusterId: number, cluster?: ClusterInfo) => HTMLElement;
onClick?: (cluster: ClusterInfo, event: MapEvent) => boolean | void;
maxHTML: number;
spiderfy: boolean;
}
export interface MapConfiguration {
/** Wheel/trackpad zoom; ctrl requires Ctrl or Cmd. Defaults to enabled. */
scrollZoom: ScrollZoom;
maxBounds?: [Coordinates, Coordinates];
center: Coordinates;
zoom: number;
minZoom: number;
maxZoom: number;
theme: Theme;
language: 'da';
rotation: boolean;
compass: boolean;
fullscreen: boolean;
geolocation: boolean;
accessibleList: boolean;
maxHTMLMarkers: number;
markerDefaults: MarkerSettings;
popupDefaults: PopupSettings;
clustering: ClusterOptions;
branding: { visible: boolean; text: string; position: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' };
}
export interface MapConstructorOptions {
container: string | HTMLElement;
baseUrl: string;
tokenProvider?: TokenProvider;
/** Explicit isolated configuration, otherwise GET /api/v1/map-config. */
serverConfig?: ServerConfig;
/** Inline styles useful for isolated/offline fixtures. */
styles?: Partial<Record<Theme, StyleSpecification>>;
platform?: ConfigurationLayer;
project?: ConfigurationLayer;
map?: ConfigurationLayer;
component?: ConfigurationLayer;
/** Additional exact HTTP(S) origins permitted for browser resources. */
allowedOrigins?: string[];
markers?: MarkerInput[];
onMarkerClick?: (marker: MarkerInput, event: MapEvent) => boolean | void;
onClusterClick?: (cluster: ClusterInfo, event: MapEvent) => boolean | void;
/** Deliberately limited renderer tuning. Controls/data ownership remain with SDK. */
renderer?: {
canvasContextAttributes?: WebGLContextAttributes & { contextType?: 'webgl2' };
renderWorldCopies?: boolean;
fadeDuration?: number;
maxTileCacheSize?: number | null;
};
}
export type ConfigurationLayer = Omit<
Partial<MapConfiguration>,
'clustering' | 'markerDefaults' | 'popupDefaults' | 'branding' | 'maxBounds'
> & {
maxBounds?: [Coordinates, Coordinates] | null;
clustering?: Omit<Partial<ClusterOptions>, 'icon' | 'html' | 'categoryColors' | 'radiusExpression' | 'onClick'> & {
icon?: ClusterOptions['icon'] | null;
html?: ClusterOptions['html'] | null;
categoryColors?: ClusterOptions['categoryColors'] | null;
radiusExpression?: ClusterOptions['radiusExpression'] | null;
onClick?: ClusterOptions['onClick'] | null;
};
markerDefaults?: Omit<Partial<MarkerSettings>, 'icon' | 'categoryIcon'> & {
icon?: string | null;
categoryIcon?: MarkerSettings['categoryIcon'] | null;
};
popupDefaults?: Partial<PopupSettings>;
branding?: Partial<MapConfiguration['branding']>;
};
export interface ClusterInfo {
id: number;
count: number;
coordinates: Coordinates;
group?: string;
}
export interface MapEvent {
originalEvent?: Event;
type: string;
marker?: MarkerInput;
cluster?: ClusterInfo;
error?: unknown;
[key: string]: unknown;
}
export type EventHandler = (event: MapEvent) => void;
export interface ShapeOptions {
color?: string;
width?: number;
opacity?: number;
fillColor?: string;
fillOpacity?: number;
}
export type ShapeData = Geometry | Feature | FeatureCollection;
Alle platformens standardværdier
export const DEFAULTS: MapConfiguration = {
scrollZoom: 'enabled',
center: [10.4, 56.1],
zoom: 7,
minZoom: 0,
maxZoom: 19,
theme: 'standard',
language: 'da',
rotation: false,
compass: false,
fullscreen: true,
geolocation: false,
accessibleList: false,
maxHTMLMarkers: 100,
markerDefaults: {
width: 32,
height: 40,
color: '#1976d2',
anchor: 'bottom',
rotation: 0,
offset: [0, 0],
opacity: 1,
zIndex: 0,
},
popupDefaults: { minWidth: 120, maxWidth: 300, offset: 12, closeButton: true, closeOnClick: true },
clustering: {
enabled: true,
radius: 50,
minPoints: 2,
maxZoom: 16,
color: '#1976d2',
textColor: '#fff',
showCount: true,
maxHTML: 100,
spiderfy: true,
},
branding: { visible: true, text: 'CTWeb Maps', position: 'bottom-left' },
};
Type definitions distribueres under /sdk/v1/types/ og den konkrete versionsmappe. TypeScript-forbrugere skal have de deklarerede compile-time MapLibre/style-spec/GeoJSON-typer til rådighed; runtimebundlen kræver ingen npm-installation i integrationen.