import { LineString, Polygon, Position } from "geojson"; import { StoreChangeHandler, GeoJSONStore, GeoJSONStoreFeatures, FeatureId } from "./store/store"; export type HexColor = `#${string}`; export type HexColorStyling = HexColor | ((feature: GeoJSONStoreFeatures) => HexColor | undefined); export type NumericStyling = number | ((feature: GeoJSONStoreFeatures) => number | undefined); export type UrlStyling = string | ((feature: GeoJSONStoreFeatures) => string); export interface TerraDrawAdapterStyling { pointColor: HexColor; pointWidth: number; pointOpacity?: number; pointOutlineColor: HexColor; pointOutlineOpacity?: number; pointOutlineWidth: number; polygonFillColor: HexColor; polygonFillOpacity: number; polygonOutlineColor: HexColor; polygonOutlineOpacity?: number; polygonOutlineWidth: number; lineStringWidth: number; lineStringColor: HexColor; lineStringOpacity?: number; /** lineStringDash - Tuple representing the dash pattern for the line string, where the first number is the length of the dash and the second number is the length of the gap in pixels */ lineStringDash?: [number, number]; zIndex: number; markerUrl?: string; markerHeight?: number; markerWidth?: number; } export type CartesianPoint = { x: number; y: number; }; export interface TerraDrawMouseEvent { lng: number; lat: number; containerX: number; containerY: number; button: "neither" | "left" | "middle" | "right"; heldKeys: string[]; isContextMenu: boolean; } export interface TerraDrawKeyboardEvent { key: string; heldKeys: string[]; preventDefault: () => void; } export type Cursor = Parameters[0]; export type SetCursor = (cursor: "unset" | "grab" | "grabbing" | "crosshair" | "pointer" | "wait" | "move") => void; export type Project = (lng: number, lat: number) => CartesianPoint; export type Unproject = (x: number, y: number) => { lat: number; lng: number; }; export type GetLngLatFromEvent = (event: PointerEvent | MouseEvent) => { lng: number; lat: number; } | null; export type Projection = "web-mercator" | "globe"; export declare const FinishActions: { readonly Draw: "draw"; readonly Edit: "edit"; readonly DeleteCoordinate: "deleteCoordinate"; readonly InsertMidpoint: "insertMidpoint"; readonly DragCoordinate: "dragCoordinate"; readonly DragFeature: "dragFeature"; readonly DragCoordinateResize: "dragCoordinateResize"; }; export type DrawInteractions = "click-move" | "click-drag" | "click-move-or-drag"; export type DrawType = "click" | "drag"; export type Actions = (typeof FinishActions)[keyof typeof FinishActions]; export type OnFinishContext = { mode: string; action: Actions; }; export type TerraDrawOnChangeContext = { origin: "api"; target?: "geometry" | "properties"; } | { target?: "geometry" | "properties"; }; export type TerraDrawGeoJSONStore = GeoJSONStore; export interface TerraDrawModeRegisterConfig { mode: string; store: TerraDrawGeoJSONStore; setDoubleClickToZoom: (enabled: boolean) => void; setCursor: SetCursor; onChange: StoreChangeHandler; onSelect: (selectedId: string) => void; onDeselect: (deselectedId: string) => void; onFinish: (finishedId: string, context: OnFinishContext) => void; project: Project; unproject: Unproject; coordinatePrecision: number; undoRedoMaxStackSize?: number; } export declare enum UpdateTypes { Commit = "commit", Provisional = "provisional", Finish = "finish" } type ValidationContext = Pick & { updateType: UpdateTypes; }; export type Validation = (feature: GeoJSONStoreFeatures, context: ValidationContext) => { valid: boolean; reason?: string; }; export interface Snapping { toLine?: boolean; toCoordinate?: boolean; toCustom?: (event: TerraDrawMouseEvent, context: { currentId?: FeatureId; currentCoordinate?: number; getCurrentGeometrySnapshot: () => (Polygon | LineString) | null; project: Project; unproject: Unproject; }) => Position | undefined; } export type TerraDrawModeState = "unregistered" | "registered" | "started" | "drawing" | "selecting" | "stopped"; export interface TerraDrawCallbacks { getState: () => TerraDrawModeState; onKeyUp: (event: TerraDrawKeyboardEvent) => void; onKeyDown: (event: TerraDrawKeyboardEvent) => void; onClick: (event: TerraDrawMouseEvent) => void; onMouseMove: (event: TerraDrawMouseEvent) => void; onDragStart: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void; onDrag: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void; onDragEnd: (event: TerraDrawMouseEvent, setMapDraggability: (enabled: boolean) => void) => void; onClear: () => void; onReady?(): void; } export interface TerraDrawChanges { created: GeoJSONStoreFeatures[]; updated: GeoJSONStoreFeatures[]; unchanged: GeoJSONStoreFeatures[]; deletedIds: FeatureId[]; } export type TerraDrawStylingFunction = { [mode: string]: (feature: GeoJSONStoreFeatures) => TerraDrawAdapterStyling; }; export type TerraDrawHandledEvents = Extract; export interface TerraDrawAdapter { project: Project; unproject: Unproject; setCursor: SetCursor; getLngLatFromEvent: GetLngLatFromEvent; setDoubleClickToZoom: (enabled: boolean) => void; getMapEventElement: (eventType?: TerraDrawHandledEvents) => HTMLElement; register(callbacks: TerraDrawCallbacks): void; unregister(): void; render(changes: TerraDrawChanges, styling: TerraDrawStylingFunction): void; clear(): void; getCoordinatePrecision(): number; } export declare const MARKER_URL_DEFAULT = "https://raw.githubusercontent.com/JamesLMilner/terra-draw/refs/heads/main/assets/markers/marker-blue.png"; export declare const SELECT_PROPERTIES: { readonly SELECTED: "selected"; readonly MID_POINT: "midPoint"; readonly SELECTION_POINT_FEATURE_ID: "selectionPointFeatureId"; readonly SELECTION_POINT: "selectionPoint"; }; export declare const COMMON_PROPERTIES: { readonly MODE: "mode"; readonly CURRENTLY_DRAWING: "currentlyDrawing"; readonly EDITED: "edited"; readonly CLOSING_POINT: "closingPoint"; readonly SNAPPING_POINT: "snappingPoint"; readonly COORDINATE_POINT: "coordinatePoint"; readonly COORDINATE_POINT_FEATURE_ID: "coordinatePointFeatureId"; readonly COORDINATE_POINT_IDS: "coordinatePointIds"; readonly PROVISIONAL_COORDINATE_COUNT: "provisionalCoordinateCount"; readonly COMMITTED_COORDINATE_COUNT: "committedCoordinateCount"; readonly MARKER: "marker"; }; declare const GUIDANCE_POINT_PROPERTY_KEYS: ("midPoint" | "selectionPoint" | "edited" | "closingPoint" | "snappingPoint" | "coordinatePoint")[]; export type GuidancePointProperties = (typeof GUIDANCE_POINT_PROPERTY_KEYS)[number]; /** * Lower z-index represents layers that are lower in the stack * and higher z-index represents layers that are higher in the stack * i.e. a layer with z-index 10 will be rendered below a layer with z-index 20 */ export declare const Z_INDEX: { readonly LAYER_ONE: 10; readonly LAYER_TWO: 20; readonly LAYER_THREE: 30; readonly LAYER_FOUR: 40; readonly LAYER_FIVE: 50; }; export {};