Skip to main content

MapCairnMapElement

The <mapcairn-map> element as defineMapCairnElement defines it. It draws nothing until services is set. Attributes set the starting view, basemap and theme, and the properties take what an attribute cannot hold. Give the element a height in CSS.

This is an interface exported by @mapcairn/map, checked against version 0.2.0.

Signature​

import type { MapCairnMapElement } from "@mapcairn/map";

interface MapCairnMapElement extends HTMLElement

Description​

latitude, longitude, zoom, bearing, basemap and theme change a map that is showing. label, language, tools, region-id and main-landmark, and each of services, messageStore, basemaps, layers, languages, regionId, mainLandmark, notes, privacyHref, about, creditsLink, engineNotice and tour, draw the map again when they change, which resets what the map alone holds, such as a measurement and the pin. A view or a basemap written in the same tick applies to the new map. For the rest it reads the link and the saved choices in services again, so a url that delays its writes can start it on the view and the basemap the link last held, even over an earlier change by the page. A new object with the same data is not a change, but keep objects the same from one render to the next where you can. Load the element before the page sets an object on it, because an element that is not defined yet takes an object as text.

Properties​

about​

about: MapCairnOptions["about"];

The About block in Help. Setting it draws the map again; the object is held, not copied. In releases after 0.2.0, not in 0.2.0 or any earlier release.

basemaps​

basemaps: readonly BasemapDefinition[] | undefined;

The basemaps offered, as plain definitions. They are given once: leave this unset when services has basemaps. Setting it draws the map again.

brand​

readonly brand: HTMLElement;

The container for the brand in the sheet: a node the element made when it was constructed, and keeps for its life. Put a mark and a name in it, with append or by rendering into it with a framework's portal, and the sheet draws them in a row above its title. It is decoration: the row is hidden from assistive technology and inert, so put nothing in it that a person should reach. The element never moves your nodes out of it, and draws no row while it holds nothing to see (no element and no text beyond white space). The container itself is laid out by the map (display: flex and a gap), so do not rely on its own display. In releases after 0.2.0, not in 0.2.0 or any earlier release.

creditsLink: MapCairnOptions["creditsLink"];

A link to the page's About page, listed after the map credits. Setting it draws the map again; the object is held, not copied. In releases after 0.2.0, not in 0.2.0 or any earlier release.

engineNotice​

engineNotice: MapCairnOptions["engineNotice"];

The notice for a map that could not start or stopped working, with the choice of a button, which sends mapcairn-notice-action and does nothing else, because what a reload would reload is the page's to decide, so a page that gives the button must listen for the event. The map has no words of its own for this notice. Setting it draws the map again; the object is held, not copied. In releases after 0.2.0, not in 0.2.0 or any earlier release.

languages​

languages: readonly MountLanguage[] | undefined;

Languages to offer besides English. They are given once: leave this unset when services has languages. Setting it draws the map again.

layers​

layers: MapCairnOptions["layers"];

The layers a person can turn on, as definitions or a function that loads them. They are given once: leave this unset unless services.layers is emptyLayerCatalogue itself, as any other catalogue counts as given, an empty one included. Setting it draws the map again.

layersState​

readonly layersState: MapStore<MapLayersState>;

The layers the map offers and whether each is on, as a store that belongs to the element: the same object for the element's life, whatever redraws of the map there are, so a page subscribes once. Its state is loading, with no layers, while the element has no map drawn, and its listeners are told when a map comes and goes. See MapHandle. In releases after 0.2.0, not in 0.2.0 or any earlier release.

mainLandmark​

mainLandmark: boolean;

Whether the map is wrapped in the page's main landmark, as the main-landmark attribute. False when absent, because a page has one main landmark. Only true sets it. Setting it draws the map again. In releases after 0.2.0, not in 0.2.0 or any earlier release.

map​

readonly map: MapHandle | undefined;

The map's handle, once it is drawn: undefined before and after.

messageStore​

messageStore: MessageStore | undefined;

The message store the page made with createMessageStore from the same services, which the page keeps for its own pages. The map reads the language from it in place of making one of its own, so the page and the map speak one language, and a Try again in the map is the page's retry. The page keeps the store given its services; the map never does. Setting a different store draws the map again. undefined and null mean the map makes its own. In releases after 0.2.0, not in 0.2.0 or any earlier release.

notes​

notes: MapCairnOptions["notes"];

Notes in the page's words, for what the map does not know. See MapCairnOptions. Setting it draws the map again. The element holds the object you set, not a copy, so keep it the same and do not change it afterwards. undefined and null mean none. In releases after 0.2.0, not in 0.2.0 or any earlier release.

privacyHref​

privacyHref: string | undefined;

Where the privacy policy is, for a link in Settings (a path or an http or https address). Setting it draws the map again. In releases after 0.2.0, not in 0.2.0 or any earlier release.

regionId​

regionId: string | undefined;

The id of the map region, as the region-id attribute. A skip link the page drew before the map existed can point at it. The ids inside the map are its own. An id is unique in a page, so two maps, or a map and the page, must not share one, and an empty region-id is an error. Setting undefined or null removes the attribute. Setting it draws the map again. In releases after 0.2.0, not in 0.2.0 or any earlier release.

services​

services: Services | undefined;

Everything the interface uses from outside itself, as a complete, plain object: each member is a property of the object itself, because the element copies it. The element draws once it is set. Setting it draws the map again.

tour​

tour: MapCairnOptions["tour"];

The first-visit tour: a welcome card, steps that each end when the person does what they ask, and an ending, in the page's words. None when unset, and then Help offers no tour. Setting it draws the map again; the object is held, not copied, so keep it the same. In releases after 0.2.0, not in 0.2.0 or any earlier release.

view​

view: ViewState | undefined;

The view the map shows, or the one it last showed. Setting it moves the map, and the latest of this and the latitude, longitude, zoom and bearing attributes wins. Nothing is written back to an attribute.

Methods​

addEventListener​

addEventListener<K extends keyof MapCairnMapEventMap>(type: K, listener: (this: MapCairnMapElement, event: MapCairnMapEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;

Listens for one of the element's events, typed by its name.

  • type (K)
  • listener ((this: MapCairnMapElement, event: MapCairnMapEventMap[K]) => void)
  • options? (boolean | AddEventListenerOptions)

addEventListener​

addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;

Listens for any other event, such as a click or a focusin.

  • type (string)
  • listener (EventListenerOrEventListenerObject)
  • options? (boolean | AddEventListenerOptions)

chooseBasemap​

chooseBasemap(id: string): void;

Picks a basemap as the person does in Map options, so the choice is saved. Does nothing while the element has no map. An id the map does not offer is sent as mapcairn-error, as any mistake in what the page gave. See MapHandle. In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • id (string)

removeEventListener​

removeEventListener<K extends keyof MapCairnMapEventMap>(type: K, listener: (this: MapCairnMapElement, event: MapCairnMapEventMap[K]) => void, options?: boolean | EventListenerOptions): void;

Stops listening for one of the element's events.

  • type (K)
  • listener ((this: MapCairnMapElement, event: MapCairnMapEventMap[K]) => void)
  • options? (boolean | EventListenerOptions)

removeEventListener​

removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;

Stops listening for any other event.

  • type (string)
  • listener (EventListenerOrEventListenerObject)
  • options? (boolean | EventListenerOptions)

setLayerEnabled​

setLayerEnabled(id: string, enabled: boolean): void;

Turns a layer on or off. Does nothing while the element has no map. An enabled that is not true or false is sent as mapcairn-error, as any mistake in what the page gave. See MapHandle. In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • id (string)
  • enabled (boolean)

showMeasurement​

showMeasurement(mode: MeasureMode, points: readonly LatLng[]): void;

Opens the measure tool showing these points, replacing those of a measurement that is open. Does nothing while the element has no map. A mode or a point that is not valid is sent as mapcairn-error, checked first, so even when the page did not name the measure tool. See MapHandle. In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • mode (MeasureMode)
  • points (readonly LatLng[])

showResult​

showResult(result: Pick<SearchResult, "centre" | "bounds">): void;

Shows a search result as the search box does: fits its bounds to at most zoom 16, or moves to its centre at zoom 14 when it has none. Does nothing while the element has no map. A centre or bounds that are not valid are sent as mapcairn-error. See MapHandle. In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • result (Pick<SearchResult, "centre" | "bounds">)

See also​

Source: packages/map/src/element/elementTypes.ts:73