# MapCairnMapElement

The `<mapcairn-map>` element. A bare tag draws a map; attributes set the
starting view, `basemap` and `theme`, and the properties take the data an
attribute cannot hold. Give the element a height in CSS.

This is an interface exported by `@mapcairn/sdk/browser`, checked against version 0.2.0.

## Signature

```ts
import type { MapCairnMapElement } from "@mapcairn/sdk/browser";
 
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`, `basemaps`, `layers`, `languages`,
`regionId`, `mainLandmark`, `notes`, `privacyHref`, `about`, `creditsLink`,
`engineNotice` and `tour`, draw the map again when they change,
which resets what a person chose in it (the basemap, the theme and the
language, a measurement) and keeps only its view. 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

```ts
about: MountMapOptions["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

```ts
basemaps: readonly BasemapDefinition[] | undefined;
```

The basemaps offered, as plain definitions. The built-in ones when unset. Setting it draws the map again.

### brand

```ts
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

```ts
creditsLink: MountMapOptions["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

```ts
engineNotice: MountMapOptions["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

```ts
languages: readonly MountLanguage[] | undefined;
```

Languages to offer besides English. Setting it draws the map again.

### layers

```ts
layers: MountMapOptions["layers"];
```

The layers a person can turn on, as definitions or a function that loads them. Setting it draws the map again.

### layersState

```ts
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.layersState`. In releases
after `0.2.0`, not in `0.2.0` or any earlier release.

### mainLandmark

```ts
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

```ts
readonly map: MapHandle | undefined;
```

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

### notes

```ts
notes: MountMapOptions["notes"];
```

Notes in the page's words, for what the map does not know. See
`MountNotes`. 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

```ts
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

```ts
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

```ts
services: MountServices | undefined;
```

The providers the page writes: search, suggestions, location and a layer source. Setting it draws the map again.

### tour

```ts
tour: MountMapOptions["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

```ts
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

```ts
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

```ts
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

```ts
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.chooseBasemap`. In releases after `0.2.0`, not in `0.2.0` or any
earlier release.

- `id` (`string`)

### removeEventListener

```ts
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

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

Stops listening for any other event.

- `type` (`string`)
- `listener` (`EventListenerOrEventListenerObject`)
- `options?` (`boolean | EventListenerOptions`)

### setLayerEnabled

```ts
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.setLayerEnabled`. In
releases after `0.2.0`, not in `0.2.0` or any earlier release.

- `id` (`string`)
- `enabled` (`boolean`)

### showMeasurement

```ts
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.showMeasurement`. In releases after `0.2.0`, not in `0.2.0` or
any earlier release.

- `mode` (`MeasureMode`)
- `points` (`readonly LatLng[]`)

### showResult

```ts
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.showResult`. In releases after `0.2.0`,
not in `0.2.0` or any earlier release.

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

## See also

- [`MountMapOptions`](https://docs.mapcairn.com/api/sdk/browser/MountMapOptions.md)
- [`MapCairnMapEventMap`](https://docs.mapcairn.com/api/sdk/browser/MapCairnMapEventMap.md)
- [`BasemapDefinition`](https://docs.mapcairn.com/api/sdk/browser/BasemapDefinition.md)
- [`MountLanguage`](https://docs.mapcairn.com/api/sdk/browser/MountLanguage.md)
- [`MapStore`](https://docs.mapcairn.com/api/sdk/browser/MapStore.md)
- [`MapLayersState`](https://docs.mapcairn.com/api/sdk/browser/MapLayersState.md)
- [`MapHandle`](https://docs.mapcairn.com/api/sdk/browser/MapHandle.md)
- [`MountServices`](https://docs.mapcairn.com/api/sdk/browser/MountServices.md)
- [`MeasureMode`](https://docs.mapcairn.com/api/sdk/browser/MeasureMode.md)
- [`LatLng`](https://docs.mapcairn.com/api/sdk/browser/LatLng.md)
- [`SearchResult`](https://docs.mapcairn.com/api/sdk/browser/SearchResult.md)
- [`ViewState`](https://docs.mapcairn.com/api/sdk/browser/ViewState.md)

Source: [packages/sdk/src/browser/element/types.ts:71](https://github.com/MapCairn/mapcairn/blob/main/packages/sdk/src/browser/element/types.ts#L71)
