Skip to main content

@mapcairn/map

The accessible React map interface of MapCairn: map controls, panels, search, measure and draw tools.

Checked against version 0.2.0. Install it with npm install @mapcairn/map; import from @mapcairn/map.

Components​

  • AccuracyCircle: The circle around a found location, sized from the ground resolution at its latitude so it matches the real accuracy at every zoom (on a globe, the resolution…
  • Attribution: The map credits for the bottom-end slot: a compact "Map credits" button (a 44 px target around a small info glyph) that expands into a labelled region of…
  • AttributionSkeleton: The credits button as a decorative stand-in for the server-rendered ChromeSkeleton: the same anchor and icon classes as Attribution, so it sits in the same…
  • BasemapAvailabilityProvider: Keeps which basemaps are not working, for the picker (which disables their tiles) and for the app (which marks a basemap whose tiles all failed).
  • BasemapPicker: Chooses the basemap: a three-across grid of previews as a radio group, one tile for each basemap the host offers (useBasemaps).
  • Button: A text button, 48 px tall at least.
  • CentreCrosshair: A small crosshair at the centre of the map, shown while measuring so "Add point at map centre" has a visible target.
  • Chip: A small pill.
  • ChromeLayoutProvider: Provides layout facts and the edge-publishing callbacks.
  • ChromeSkeleton: The server-rendered stand-in for MapChrome: the search pill, the map controls, the zoom group on a device with a fine pointer and the credits button, each in…
  • ControlGroup: Icon buttons stacked on one floating surface, separated by hairlines.
  • CursorCoordinates: The position under the pointer and the zoom level, as plain muted text with tabular figures.
  • DirectionsOverlay: The stops of a set of directions, drawn as lettered discs, and the crosshair that shows where the next stop goes when it is added at the map centre.
  • DirectionsPanel: The directions tool's panel, for the sheet or side panel: the stops (added by tapping the map, at the map centre, from a place search or from the dropped pin,…
  • DrawMapBindings: Connects the draw tool to the live map without drawing anything: it gives the adapter the handles of the selected shape, and passes the adapter's handle…
  • DrawOverlay: The draw tool's drawing: every shape with its fill and outline, the unfinished one dashed, the selected one drawn heavier, a dashed preview of the next edge,…
  • DrawToolbar: The draw toolbar: a switch for what to draw, the name and measures of the shape under way or selected, buttons to add a point at the map centre, undo, redo,…
  • EmptyState: What a list or panel shows when it has nothing to show: an icon, a real heading, an explanation and an optional action.
  • EndStack: The end-stack slot content, a landmark named "Map tools" holding, top to bottom: the compass (only while the map is rotated and the engine can rotate), the…
  • EndStackSkeleton: The end stack as a decorative stand-in for the server-rendered ChromeSkeleton: the same column, groups and buttons as EndStack, with the Map options, Measure,…
  • ExportSection: Saves the map as it looks now, with its layers and credits, as a PNG file.
  • FeatureCard: The card for one feature, drawn from its definition's card template (a feed's own, or the identify card of a tile layer): the title, for a feed layer the…
  • FocusRegistryProvider: Remembers the elements that open surfaces, so closing a surface can put focus back on the control that opened it, or on the map when that control is gone.
  • HelpSection: Help: what the search box accepts, the keyboard shortcuts, a statement of the accessibility target and, when the host supplies one, its About block.
  • Icon: Draws one icon at the system size and stroke width.
  • IconButton: A button that shows only an icon.
  • IdentifyStatus: The line a host shows in the bottom-centre slot while a tap's lookup is taking time ("Looking up what is here"): show it when…
  • Isolate: Keeps a run of text in its own bidirectional context.
  • LayerItem: One layer in the Layers section: its switch, and while it is on, its status, controls, legend, disclaimer and list.
  • LayerKey: A layer's key: one row for each colour, shape or class its style draws, with the same glyph the map uses and the words for it.
  • LayersSection: The Layers section of the sheet and side panel, drawn entirely from the layer definitions: a switch per layer with its data cost, and while a layer is on, its…
  • ListRow: A list item for lists of places, layers and options.
  • LiveRegionProvider: Mounts the one app-wide announcer: a visually hidden polite status region and a visually hidden assertive alert region.
  • MapChrome: The one owner of everything floating over the map.
  • MapDataLayers: Draws the layers that are on, and a shown affected area, through the map adapter, and turns a tap on a point into an open card.
  • MapDirections: Draws a route as a line with a white casing, or a travel-time area as an outlined, tinted shape, through the map adapter's shape layers, and fits the map to…
  • MapKey: The key to the layers that are on, for the map itself: a panel named "Map key" with one block for each layer that has a key, so a person can read what the…
  • MapOverlayLayer: The single layer every map overlay draws into: one SVG spanning the map host, above the engine and below the chrome.
  • MapReadout: The bottom-start readout: the scale bar with the cursor coordinates and zoom level under it.
  • MapView: The engine host: the map region and the single focus stop of the map.
  • MarkerGlyph: The marker a layer draws for a feature, as a small picture for the legend, the list and the card, so words and map look the same: the fill over a dark edge…
  • MeasureOverlay: The measuring tool's drawing: vertices, the line between them and, for an area, the closed polygon and its fill.
  • MeasureToolbar: The measure toolbar: a Distance or Area switch, the running total, buttons to add a point at the map centre, undo and clear, and Done.
  • PinCard: The content of the pin surface: a heading, the coordinates as selectable text, "Copy coordinates" and "Clear pin" buttons, and an address lookup that the user…
  • PinMarker: A dropped pin, drawn in the overlay layer and re-projected whenever the view changes.
  • PinSection: The pin: a button that drops a pin at the centre of the map, which is the button equivalent of a long press and of the P key, and a note while a pin is on the…
  • ScaleBar: A scale bar drawn straight on the map: a thin line with end ticks and a haloed label, re-computed whenever the view changes.
  • SearchPill: The floating search pill: a 48px pill holding an ARIA 1.2 combobox and a Search button, with the results in a listbox just below it.
  • SearchPillSkeleton: The search pill as a decorative stand-in for the server-rendered ChromeSkeleton: the same wrapper, pill and input classes as SearchPill, so it fills the same…
  • Section: A titled block of the sheet: a section named by a real heading.
  • SegmentedControl: A single-choice control that shows all options at once, built on the Radix ToggleGroup in single mode.
  • SelectionMarker: A ring around the point whose card is open, so the card and the map agree on which one it is.
  • SelectionProvider: Hands the selected set down to the components that show or change it, so none needs a prop for it.
  • ServicesProvider: Makes the app's services available to every component below it.
  • SettingsSection: The settings: theme, units, map shape (flat or globe), language (only when the host offers more than one; see LanguageField) and zoom buttons, a note when…
  • ShapesSection: The shapes the person has drawn: a list where each row selects a shape (so it can be edited with the keyboard from the draw tool), buttons to delete the…
  • Sheet: The map options surface: a bottom sheet with peek, half and full detents on narrow screens, and a floating side panel in the panel layout.
  • SheetContent: Everything inside the sheet, under its own h2 title, each part a section named by an h3.
  • SkipLink: The first focusable element on the page.
  • Slider: A single-thumb slider built on the Radix Slider primitive, with a visible label and a visible value readout.
  • StatusMessage: A toast or banner: an icon, text and a dismiss button, so the variant is never conveyed by colour alone.
  • StatusMessageFocusProvider: Says where focus goes when a StatusMessage below it goes away and focus cannot return to where it came from.
  • Subheading: A heading for a group inside a section, such as Privacy or Keyboard.
  • Surface: A translucent surface with backdrop blur, used by every floating control.
  • Switch: A labelled on/off switch built on the Radix Switch primitive.
  • Tooltip: A short hint attached to a focusable control, built on the Radix Tooltip.
  • TooltipProvider: Shares the open delay between every Tooltip below it.
  • TourCard: The first-visit tour's card: the welcome card, a step, or the ending.
  • VisuallyHidden: The one way to provide screen-reader-only text, such as a hidden heading or keyboard instructions.

Hooks​

  • useAnnounce: Returns announce(message, { priority?, keep?
  • useBasemapAvailability: Which basemaps are not working right now, and how to mark one.
  • useBasemaps: The basemaps on offer: the host's catalogue, or the built-in basemaps when it supplies none.
  • useChromeLayout: Reads the chrome layout.
  • useClipboard: The clipboard port.
  • useDataLayers: The state of every data layer and the actions on it, driven entirely by the definitions in the catalogue: nothing here names a layer.
  • useDirections: The state of one set of directions: the stops, the travel mode and the route or travel-time area the service found for them, with the requests cancellable and…
  • useDraw: The state of the Draw tool: the shapes, what is selected, undo, and every way to change them, by pointer and by keyboard.
  • useFeatureQuery: The query for the features inside a shape, or undefined when the host supplies none.
  • useFeatureSelection: The selected set as the ui shows it: the host's FeatureSelection store, resolved against the layers, with the select-mode flag and one message to the live…
  • useFileOpener: The file opener, which asks the person for a file and reads it in the browser, or undefined when the host supplies none.
  • useFileSaver: The file saver, which offers a file the ui built as a download.
  • useFocusElement: Returns element(name), the registered control in the document, or null.
  • useFocusReturn: Returns restore(name), which focuses the registered control, or the map region when the name is null or the control is no longer in the document.
  • useFocusTarget: Returns a ref callback to put on the control that opens a surface, so focus can come back to it: <IconButton ref={useFocusTarget("map-options")} />.
  • useFormatMessage: Formats a core Message (a key and its parameters) with the active catalogue, for text a component shows or hands on as a string.
  • useFreeCentre: The target of "at the map centre" for a tool whose panel covers part of the map: the middle of what is left uncovered, so it is never under the sheet.
  • useIdentifyFeedback: Whether to show the "Looking up what is here" line: true once identifying (see DataLayers.identifying) has been true for IDENTIFY_FEEDBACK_MS, and false again…
  • useLanguageLoad: Whether the messages for the language the person chose have failed to load, and a way to try again, or undefined when the host offers no languages.
  • useLanguages: The languages the host offers, or undefined when it offers none to choose between.
  • useLayers: The data layer catalogue: a store of the host's layer definitions and whether they have loaded.
  • useLocate: Finds the user's location through the services' LocationProvider, one request at a time.
  • useLocationProvider: The location provider.
  • useLongPress: Long-press on the map, implemented once with pointer events so it behaves the same on every engine.
  • useMap: Returns the live map.
  • useMapAdapterFactory: The map adapter factory, used by the map host to pick an engine for a basemap.
  • useMeasure: The state of one measurement: the points the user has placed, the mode and the total, worked out with the core geodesic maths (WGS 84, not flat pixels).
  • useMessages: The active message catalogue, for t/plural/list calls that look up copy by key instead of writing it inline.
  • useOnline: Whether the browser says the device has a connection, updating live.
  • useOptionalMessages: As useMessages, but without a ServicesProvider above it the SDK's English catalogue, so a piece a consumer may render on its own (the skip link, a status…
  • useOptionalServices: Returns the services, or null outside a ServicesProvider.
  • usePlacement: The placement every overlay uses: the live adapter, the current view and the map shape, or null before the map has mounted.
  • usePreferences: Device and accessibility preferences (reduced motion, fine pointer, languages, online), updating live.
  • useResolveText: Reads a definition's text in the active language: a message key is looked up in the catalogue, a plain string is returned as written (see resolveText).
  • useReverseAddress: Looks up the address at a position with the search provider's reverse, but only when lookUp is called, because the position leaves the device.
  • useRoutingProvider: The routing provider, or undefined when the host supplies none.
  • useSearch: Cancellable place search over the services' SearchProvider, run only when the user submits.
  • useSearchProvider: The place search provider.
  • useSelection: The selected set, or undefined outside a SelectionProvider or when the host offers no selection.
  • useSelectionStore: The store of selected features, or undefined when the host supplies none.
  • useServices: Returns the services.
  • useSettings: Subscribes to the settings store.
  • useSuggestionProvider: The suggestion provider, or undefined when the host supplies none.
  • useSuggestions: Suggests places for text as it is typed, over the services' optional SuggestionProvider.
  • useTheme: Combines the stored theme choice with the system preference, follows system changes live without a reload, and reflects the result onto the document through…
  • useThemeSource: The theme source.
  • useTour: Runs the first-visit tour: the welcome card, the steps and the ending.
  • useUrlState: The shareable URL state port.

Functions​

  • chromeSkeletonCopy: The skeleton's words from catalogue, by the keys the live search pill, end stack and credits button use, so the skeleton and the controls that replace it say…
  • endStackMinHeightForZoom: The height the end stack needs to show the zoom group under the main group: four main controls (Map options, Measure, Locate me and Settings), two zoom…
  • mapKeyBlocks: The blocks of the map key: one for each layer that is on and has a key, in catalogue order.

Constants​

  • IDENTIFY_FEEDBACK_MS: How long a lookup may run before the interface says it is waiting.
  • IDENTIFY_TIMEOUT_MS: How long one layer has to answer a tap, in milliseconds.
  • LONG_PRESS_DELAY_MS: How long a still press must last to count as a long-press, in milliseconds.
  • MapContext: The map context.
  • MAX_IDENTIFY_LAYERS: The most layers one tap asks, in catalogue order.
  • MAX_OUTLINE_POINTS: The most vertices one ring or line contributes to an outline drawn over the map.
  • MIN_SUGGEST_LENGTH: The fewest characters (after trimming) that suggestions are asked for.
  • REVEAL_DETENT: The detent a bottom sheet rests at when a feature is shown, so its card and the map share the screen.
  • SCALE_BAR_IDLE_MS: How long the scale bar stays after the zoom last changed before it fades.
  • SUGGEST_COOLDOWN_MS: How long suggestions stay paused after repeated failures, in milliseconds.
  • SUGGEST_DEBOUNCE_MS: How long the text must stay unchanged before suggestions are asked for.
  • SUGGEST_FAILURE_LIMIT: How many requests in a row may fail before suggestions pause.
  • UNDO_TIMEOUT_MS: How long the Undo after turning layers off stays on offer, in milliseconds.
  • VIEW_SETTLE_MS: How long the map must stay still, in milliseconds, before layers that depend on its view are told it.

Types​