import type { MapOverlayPosition } from './map.types'; /** * Absolute-position classes for each of the nine overlay anchors. * * Every surveyed application recreated this positioning by hand and settled its * `z-index` by guesswork. Centralizing it keeps the legend, the notice, the * scale bar and the attribution on one predictable stacking layer. */ const POSITION_CLASSES: Record = { 'top-left': 'top-3 left-3', 'top-center': 'top-3 left-1/2 -translate-x-1/2', 'top-right': 'top-3 right-3', 'middle-left': 'top-1/2 left-3 -translate-y-1/2', 'middle-center': 'top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2', 'middle-right': 'top-1/2 right-3 -translate-y-1/2', 'bottom-left': 'bottom-3 left-3', 'bottom-center': 'bottom-3 left-1/2 -translate-x-1/2', 'bottom-right': 'bottom-3 right-3', }; /** * Returns the Tailwind classes that pin an overlay to one of the nine anchors. * * The result is positioned against the nearest positioned ancestor, so the * overlay must sit inside an element with `relative` — ``'s own container * already is one. */ export function mapOverlayPositionClasses(position: MapOverlayPosition): string { return `absolute z-10 ${POSITION_CLASSES[position]}`; } export const MAP_OVERLAY_POSITIONS = Object.keys(POSITION_CLASSES) as MapOverlayPosition[];