import type { GeoJsonFeature, GeoJsonGeometry } from "@trackunit/geo-json-utils"; /** * Intent returned by a `resolveLabel` callback on an `edge-auto` anchor. * * - `"auto"` — run placement normally; hide if no qualifying edge is found. * - `"force"` — place on the best available edge even if the label overflows * its measured width. Still hides if the feature is entirely off-screen. * - `"hide"` — suppress unconditionally. */ export type ShapeLabelResolution = "auto" | "force" | "hide"; /** * Per-feature, per-frame context passed to `resolveLabel`. Lets the consumer * decide whether a shape's edge label should render, taking into account * zoom, viewport density, geometry, and interaction state. * * Deliberate parallel to the `resolveMode(item, ctx)` callback used by the * adaptive marker render mode (see ADR-0008 / ADR-0016). */ export type ShapeLabelResolutionContext = Readonly<{ /** Current map zoom level. */ zoom: number; /** Number of features from the same layer that intersect the viewport. */ shapesInViewport: number; /** Number of other in-viewport features whose **geometry shares area** with this feature's polygon (bbox prefilter, then polygon intersection for Polygon/MultiPolygon geometries; bbox-only for Point/Line types). Fully contained inner polygons are not counted — their fill does not obscure the map below. */ overlappingShapesCount: number; /** GeoJSON geometry type of the feature. */ geometryType: GeoJsonGeometry["type"]; /** Width of the feature's bounding box in screen pixels at the current zoom. */ bboxPixelWidth: number; /** Height of the feature's bounding box in screen pixels at the current zoom. */ bboxPixelHeight: number; /** True when the viewport is fully contained inside the feature (no edges visible). */ isViewportInsideShape: boolean; /** Number of parts in multi-geometries (1 for single geometries). */ partCount: number; /** True when the feature is the currently selected entity. */ isSelected: boolean; /** True when the feature is the currently hovered entity. */ isHovered: boolean; }>; /** * Callback signature for `edge-auto` `resolveLabel`. Receives the feature and * a snapshot of the resolution context; returns the desired render intent. */ export type ResolveShapeLabel = (feature: GeoJsonFeature, ctx: ShapeLabelResolutionContext) => ShapeLabelResolution;