# A list beside the map, on Google Maps and MapLibre

Your locations as a list kept in sync with the map: a select menu, tag filters, nested groups with a checkbox each, a search box, nearest first, only what's in view, your own markup, or tabs with a details panel.

The list beside the map, your way: a menu, tags, nested groups, a search box, nearest first, what's in view, your own markup, or tabs.

## Select menu

A native select on the map, grouped by region, with an entry for all.

A native `<select>` on the map, top right, its places under their regions and a first entry that shows them all.

- **Try it**: choose a city and the map goes there; choose "All cities" and it fits them all again. Tick "North only": the map and the menu keep the North's.
- **HTML**: `list="select"`, `list-position`, `list-heading`, `fit-all` and `fit-all-label` on `<maplace-map>` ([Map attributes](/element/#map-attributes)), `group` on each `<maplace-location>` for its heading, and a script calling the element's `maplace.setFilter`.
- **Script** and **Bundler**: `list: { as: "select", heading, fitAll: true, fitAllLabel }` in the map's options ([List view options](/store/#list-view-options)), `group` on a location ([Every location](/locations/#every-location)), and [`setFilter(["North"])`](/store/#methods), a list of groups.
- **React**: `<LocationList as="select" heading fitAll fitAllLabel position="top-right" />` inside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)), and the `filter` prop of `<MaplaceProvider>` ([`<MaplaceProvider>`](/react/#maplaceprovider)).


### HTML on MapLibre

`packages/maplace/examples/menu/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- A native <select> on the map, top right, grouped by region; the checkbox shows the North only. -->
<p><label><input type="checkbox" id="menu-maplibre-north-only" /> North only</label></p>
<maplace-map id="menu-maplibre-map" list="select" list-position="top-right"
  list-heading="Choose a location:" fit-all fit-all-label="All cities">
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London" group="South"></maplace-location>
  <maplace-location location-id="edinburgh" lat="55.9533" lng="-3.1883" title="Edinburgh" group="North"></maplace-location>
  <maplace-location location-id="belfast" lat="54.5973" lng="-5.9301" title="Belfast" group="North"></maplace-location>
</maplace-map>
<script>
  document.getElementById('menu-maplibre-north-only').addEventListener('change', (event) => {
    document.getElementById('menu-maplibre-map').maplace.setFilter(event.target.checked ? ['North'] : undefined);
  });
</script>
```

### HTML on Google

`packages/maplace/examples/menu/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- A native <select> on the map, top right, grouped by region; the checkbox shows the North only. -->
<p><label><input type="checkbox" id="menu-north-only" /> North only</label></p>
<maplace-map id="menu-map" api-key="YOUR_KEY" list="select" list-position="top-right"
  list-heading="Choose a location:" fit-all fit-all-label="All cities">
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London" group="South"></maplace-location>
  <maplace-location location-id="edinburgh" lat="55.9533" lng="-3.1883" title="Edinburgh" group="North"></maplace-location>
  <maplace-location location-id="belfast" lat="54.5973" lng="-5.9301" title="Belfast" group="North"></maplace-location>
</maplace-map>
<script>
  document.getElementById('menu-north-only').addEventListener('change', (event) => {
    document.getElementById('menu-map').maplace.setFilter(event.target.checked ? ['North'] : undefined);
  });
</script>
```

### Script on MapLibre

`packages/maplace/examples/menu/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, the checkbox and what the map mounts on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #menu-maplibre-script-map { height: 24rem; }
</style>
<p><label><input type="checkbox" id="menu-maplibre-script-north-only" /> North only</label></p>
<div id="menu-maplibre-script-map"></div>
<script type="module">
  const maplace = Maplace.createMapLibreMap("#menu-maplibre-script-map", {
    locations: [
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
      { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
      { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
    ],
    list: { as: "select", heading: "Choose a location:", fitAll: true, fitAllLabel: "All cities" },
  });

  const northOnly = document.querySelector("#menu-maplibre-script-north-only");
  northOnly?.addEventListener("change", () => {
    maplace.setFilter(northOnly.checked ? ["North"] : undefined);
  });
</script>
```

### Script on Google

`packages/maplace/examples/menu/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, the checkbox and what the map mounts on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #menu-script-map { height: 24rem; }
</style>
<p><label><input type="checkbox" id="menu-script-north-only" /> North only</label></p>
<div id="menu-script-map"></div>
<script type="module">
  const maplace = Maplace.createGoogleMap("#menu-script-map", {
    apiKey: "YOUR_KEY",
    locations: [
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
      { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
      { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
    ],
    list: { as: "select", heading: "Choose a location:", fitAll: true, fitAllLabel: "All cities" },
  });

  const northOnly = document.querySelector("#menu-script-north-only");
  northOnly?.addEventListener("change", () => {
    maplace.setFilter(northOnly.checked ? ["North"] : undefined);
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/menu/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #menu-maplibre-vanilla-map { height: 24rem; }
</style>
<p><label><input type="checkbox" id="menu-maplibre-vanilla-north-only" /> North only</label></p>
<div id="menu-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/menu/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

const maplace = createMapLibreMap("#menu-maplibre-vanilla-map", {
  locations: [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
    { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
    { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
  ],
  list: { as: "select", heading: "Choose a location:", fitAll: true, fitAllLabel: "All cities" },
});

const northOnly = document.querySelector<HTMLInputElement>("#menu-maplibre-vanilla-north-only");
northOnly?.addEventListener("change", () => {
  maplace.setFilter(northOnly.checked ? ["North"] : undefined);
});
```

### Bundler on Google

`packages/maplace/examples/menu/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #menu-vanilla-map { height: 24rem; }
</style>
<p><label><input type="checkbox" id="menu-vanilla-north-only" /> North only</label></p>
<div id="menu-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/menu/vanilla.ts`

```ts
import { createGoogleMap } from "@maplacejs/maplace/google";

const maplace = createGoogleMap("#menu-vanilla-map", {
  locations: [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
    { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
    { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
  ],
  list: { as: "select", heading: "Choose a location:", fitAll: true, fitAllLabel: "All cities" },
});

const northOnly = document.querySelector<HTMLInputElement>("#menu-vanilla-north-only");
northOnly?.addEventListener("change", () => {
  maplace.setFilter(northOnly.checked ? ["North"] : undefined);
});
```

### React on MapLibre

`packages/maplace/examples/menu/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #menu-maplibre-react-root .map { height: 24rem; }
</style>
<div id="menu-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/menu/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
  { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
  { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
];
const NORTH = ["North"];

function Menu() {
  const [northOnly, setNorthOnly] = useState(false);
  return (
    <MaplaceProvider locations={cities} filter={northOnly ? NORTH : undefined}>
      <p>
        <label>
          <input
            type="checkbox"
            checked={northOnly}
            onChange={(event) => setNorthOnly(event.target.checked)}
          />{" "}
          North only
        </label>
      </p>
      <MaplaceMap createAdapter={createMapLibreAdapter} className="map">
        <LocationList
          as="select"
          heading="Choose a location:"
          fitAll
          fitAllLabel="All cities"
          position="top-right"
        />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("menu-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <Menu />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/menu/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #menu-react-root .map { height: 24rem; }
</style>
<div id="menu-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/menu/react.tsx`

```tsx
import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
  { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
  { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
];
const NORTH = ["North"];

function Menu() {
  const [northOnly, setNorthOnly] = useState(false);
  return (
    <MaplaceProvider locations={cities} filter={northOnly ? NORTH : undefined}>
      <p>
        <label>
          <input
            type="checkbox"
            checked={northOnly}
            onChange={(event) => setNorthOnly(event.target.checked)}
          />{" "}
          North only
        </label>
      </p>
      <MaplaceMap createAdapter={createGoogleAdapter} className="map">
        <LocationList
          as="select"
          heading="Choose a location:"
          fitAll
          fitAllLabel="All cities"
          position="top-right"
        />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("menu-react-root") as HTMLElement).render(
  <StrictMode>
    <Menu />
  </StrictMode>,
);
```

## Filter by tags

Places with several tags: tick some to see those with all of them.

A location has one `group`, its heading in the list, and as many `tags` as it needs. Tick a box and the map and the list keep the places with all the ticked tags; untick them all and every place is back. The boxes sit above the map, the list on it, top right.

- **Try it**: tick "Parking", then "Open late" too: the numbers after the headings follow what is listed.
- **HTML**: `tags="parking open-late"` on `<maplace-location>`, the tags split on spaces ([Location attributes](/element/#location-attributes)), `group-counts` on `<maplace-map>` for the numbers ([Map attributes](/element/#map-attributes)), and a script calling the element's `maplace.setFilter`.
- **Script** and **Bundler**: `tags: ["parking", "open-late"]` on a location ([Every location](/locations/#every-location)), `groupCounts` on the list ([List view options](/store/#list-view-options)), and [`setFilter({ tags })`](/store/#methods) with what is ticked: no tags ask for nothing, so no branch is needed for none.
- **React**: `<LocationList groupCounts />` and the `filter` prop of [`<MaplaceProvider>`](/react/#maplaceprovider), `filter={{ tags }}`, applied when its value changes.
- **With groups**: `setFilter({ groups: ["North"], tags: ["parking"] })` keeps what matches both; `setFilter(["North"])`, a list of groups alone, is what the [Select menu](/examples/lists/#menu) example does.


### HTML on MapLibre

`packages/maplace/examples/tags/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- Places with several tags, in a list on the map under their one group; the checkboxes show those with all the ticked tags. -->
<p id="tags-maplibre-filters">
  <label><input type="checkbox" value="parking" /> Parking</label>
  <label><input type="checkbox" value="open-late" /> Open late</label>
</p>
<maplace-map id="tags-maplibre-map" list list-position="top-right" list-heading="Places" group-counts>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome" group="Centre" tags="parking open-late"></maplace-location>
  <maplace-location location-id="bologna" lat="44.4949" lng="11.3426" title="Bologna" group="Centre"></maplace-location>
  <maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan" group="North" tags="parking"></maplace-location>
  <maplace-location location-id="turin" lat="45.0703" lng="7.6869" title="Turin" group="North" tags="open-late"></maplace-location>
  <maplace-location location-id="naples" lat="40.8518" lng="14.2681" title="Naples" group="South" tags="parking open-late"></maplace-location>
</maplace-map>
<script>
  document.getElementById('tags-maplibre-filters').addEventListener('change', (event) => {
    const ticked = event.currentTarget.querySelectorAll(':checked');
    document.getElementById('tags-maplibre-map').maplace.setFilter({ tags: Array.from(ticked, (box) => box.value) });
  });
</script>
```

### HTML on Google

`packages/maplace/examples/tags/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- Places with several tags, in a list on the map under their one group; the checkboxes show those with all the ticked tags. -->
<p id="tags-filters">
  <label><input type="checkbox" value="parking" /> Parking</label>
  <label><input type="checkbox" value="open-late" /> Open late</label>
</p>
<maplace-map id="tags-map" api-key="YOUR_KEY" list list-position="top-right" list-heading="Places" group-counts>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome" group="Centre" tags="parking open-late"></maplace-location>
  <maplace-location location-id="bologna" lat="44.4949" lng="11.3426" title="Bologna" group="Centre"></maplace-location>
  <maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan" group="North" tags="parking"></maplace-location>
  <maplace-location location-id="turin" lat="45.0703" lng="7.6869" title="Turin" group="North" tags="open-late"></maplace-location>
  <maplace-location location-id="naples" lat="40.8518" lng="14.2681" title="Naples" group="South" tags="parking open-late"></maplace-location>
</maplace-map>
<script>
  document.getElementById('tags-filters').addEventListener('change', (event) => {
    const ticked = event.currentTarget.querySelectorAll(':checked');
    document.getElementById('tags-map').maplace.setFilter({ tags: Array.from(ticked, (box) => box.value) });
  });
</script>
```

### Script on MapLibre

`packages/maplace/examples/tags/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, the checkboxes and what the map mounts on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #tags-maplibre-script-map { height: 24rem; }
</style>
<p id="tags-maplibre-script-filters">
  <label><input type="checkbox" value="parking" /> Parking</label>
  <label><input type="checkbox" value="open-late" /> Open late</label>
</p>
<div id="tags-maplibre-script-map"></div>
<script type="module">
  const maplace = Maplace.createMapLibreMap("#tags-maplibre-script-map", {
    locations: [
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre", tags: ["parking", "open-late"] },
      { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre" },
      { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North", tags: ["parking"] },
      { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North", tags: ["open-late"] },
      { id: "naples", lat: 40.8518, lng: 14.2681, title: "Naples", group: "South", tags: ["parking", "open-late"] },
    ],
    list: { heading: "Places", groupCounts: true },
  });

  const filters = document.querySelector("#tags-maplibre-script-filters");
  filters?.addEventListener("change", () => {
    const ticked = filters.querySelectorAll(":checked");
    maplace.setFilter({ tags: Array.from(ticked, (box) => box.value) });
  });
</script>
```

### Script on Google

`packages/maplace/examples/tags/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, the checkboxes and what the map mounts on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #tags-script-map { height: 24rem; }
</style>
<p id="tags-script-filters">
  <label><input type="checkbox" value="parking" /> Parking</label>
  <label><input type="checkbox" value="open-late" /> Open late</label>
</p>
<div id="tags-script-map"></div>
<script type="module">
  const maplace = Maplace.createGoogleMap("#tags-script-map", {
    apiKey: "YOUR_KEY",
    locations: [
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre", tags: ["parking", "open-late"] },
      { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre" },
      { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North", tags: ["parking"] },
      { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North", tags: ["open-late"] },
      { id: "naples", lat: 40.8518, lng: 14.2681, title: "Naples", group: "South", tags: ["parking", "open-late"] },
    ],
    list: { heading: "Places", groupCounts: true },
  });

  const filters = document.querySelector("#tags-script-filters");
  filters?.addEventListener("change", () => {
    const ticked = filters.querySelectorAll(":checked");
    maplace.setFilter({ tags: Array.from(ticked, (box) => box.value) });
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/tags/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #tags-maplibre-vanilla-map { height: 24rem; }
</style>
<p id="tags-maplibre-vanilla-filters">
  <label><input type="checkbox" value="parking" /> Parking</label>
  <label><input type="checkbox" value="open-late" /> Open late</label>
</p>
<div id="tags-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/tags/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

const maplace = createMapLibreMap("#tags-maplibre-vanilla-map", {
  locations: [
    {
      id: "rome",
      lat: 41.9028,
      lng: 12.4964,
      title: "Rome",
      group: "Centre",
      tags: ["parking", "open-late"],
    },
    { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre" },
    { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North", tags: ["parking"] },
    { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North", tags: ["open-late"] },
    {
      id: "naples",
      lat: 40.8518,
      lng: 14.2681,
      title: "Naples",
      group: "South",
      tags: ["parking", "open-late"],
    },
  ],
  list: { heading: "Places", groupCounts: true },
});

const filters = document.querySelector("#tags-maplibre-vanilla-filters");
filters?.addEventListener("change", () => {
  const ticked = filters.querySelectorAll<HTMLInputElement>(":checked");
  maplace.setFilter({ tags: Array.from(ticked, (box) => box.value) });
});
```

### Bundler on Google

`packages/maplace/examples/tags/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #tags-vanilla-map { height: 24rem; }
</style>
<p id="tags-vanilla-filters">
  <label><input type="checkbox" value="parking" /> Parking</label>
  <label><input type="checkbox" value="open-late" /> Open late</label>
</p>
<div id="tags-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/tags/vanilla.ts`

```ts
import { createGoogleMap } from "@maplacejs/maplace/google";

const maplace = createGoogleMap("#tags-vanilla-map", {
  locations: [
    {
      id: "rome",
      lat: 41.9028,
      lng: 12.4964,
      title: "Rome",
      group: "Centre",
      tags: ["parking", "open-late"],
    },
    { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre" },
    { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North", tags: ["parking"] },
    { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North", tags: ["open-late"] },
    {
      id: "naples",
      lat: 40.8518,
      lng: 14.2681,
      title: "Naples",
      group: "South",
      tags: ["parking", "open-late"],
    },
  ],
  list: { heading: "Places", groupCounts: true },
});

const filters = document.querySelector("#tags-vanilla-filters");
filters?.addEventListener("change", () => {
  const ticked = filters.querySelectorAll<HTMLInputElement>(":checked");
  maplace.setFilter({ tags: Array.from(ticked, (box) => box.value) });
});
```

### React on MapLibre

`packages/maplace/examples/tags/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #tags-maplibre-react-root .map { height: 24rem; }
</style>
<div id="tags-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/tags/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { Fragment, StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  {
    id: "rome",
    lat: 41.9028,
    lng: 12.4964,
    title: "Rome",
    group: "Centre",
    tags: ["parking", "open-late"],
  },
  { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre" },
  { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North", tags: ["parking"] },
  { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North", tags: ["open-late"] },
  {
    id: "naples",
    lat: 40.8518,
    lng: 14.2681,
    title: "Naples",
    group: "South",
    tags: ["parking", "open-late"],
  },
];
const CHOICES = [
  { tag: "parking", label: "Parking" },
  { tag: "open-late", label: "Open late" },
];

function Tags() {
  const [tags, setTags] = useState<readonly string[]>([]);
  return (
    <MaplaceProvider locations={cities} filter={{ tags }}>
      <p>
        {CHOICES.map(({ tag, label }) => (
          <Fragment key={tag}>
            <label>
              <input
                type="checkbox"
                checked={tags.includes(tag)}
                onChange={(event) =>
                  setTags(
                    event.target.checked ? [...tags, tag] : tags.filter((other) => other !== tag),
                  )
                }
              />{" "}
              {label}
            </label>{" "}
          </Fragment>
        ))}
      </p>
      <MaplaceMap createAdapter={createMapLibreAdapter} className="map">
        <LocationList heading="Places" groupCounts position="top-right" />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("tags-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <Tags />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/tags/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #tags-react-root .map { height: 24rem; }
</style>
<div id="tags-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/tags/react.tsx`

```tsx
import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { Fragment, StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  {
    id: "rome",
    lat: 41.9028,
    lng: 12.4964,
    title: "Rome",
    group: "Centre",
    tags: ["parking", "open-late"],
  },
  { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre" },
  { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North", tags: ["parking"] },
  { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North", tags: ["open-late"] },
  {
    id: "naples",
    lat: 40.8518,
    lng: 14.2681,
    title: "Naples",
    group: "South",
    tags: ["parking", "open-late"],
  },
];
const CHOICES = [
  { tag: "parking", label: "Parking" },
  { tag: "open-late", label: "Open late" },
];

function Tags() {
  const [tags, setTags] = useState<readonly string[]>([]);
  return (
    <MaplaceProvider locations={cities} filter={{ tags }}>
      <p>
        {CHOICES.map(({ tag, label }) => (
          <Fragment key={tag}>
            <label>
              <input
                type="checkbox"
                checked={tags.includes(tag)}
                onChange={(event) =>
                  setTags(
                    event.target.checked ? [...tags, tag] : tags.filter((other) => other !== tag),
                  )
                }
              />{" "}
              {label}
            </label>{" "}
          </Fragment>
        ))}
      </p>
      <MaplaceMap createAdapter={createGoogleAdapter} className="map">
        <LocationList heading="Places" groupCounts position="top-right" />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("tags-react-root") as HTMLElement).render(
  <StrictMode>
    <Tags />
  </StrictMode>,
);
```

## Filter by group

Offices by region and country, nested in the list, with a checkbox for each region and country.

A company's offices around the world, each in a region and a country: its `group` is a path, outermost first, so the list nests the countries under their regions, each heading counting everything under it, and a checkbox for each region and country above the list filters the map and the list.

- **Try it**: open Groups above the list and untick Italy: Europe's box is partly ticked, its count drops by Italy's offices, and Italy's pins leave the map. Click Europe: all of Europe is back. Untick every box and nothing is listed; tick them all and the filter asks for no group at all. Type in the search box while some boxes are unticked: the boxes set only the filter's groups, the box only its words, so each keeps what the other asked for.
- **A partly ticked group**: it shows its ticked subgroups, not entries of its own (those whose path ends at it, such as `group: ["Europe"]`): a group in the filter always takes all its subgroups. This map has none at a region.
- **HTML**: `group='["Europe","Italy"]'` on `<maplace-location>`, the path as JSON: a `group` starting with `[` is read as a path ([Location attributes](/element/#location-attributes)); `group-filter`, `group-counts` and `search` on `<maplace-map>` ([Map attributes](/element/#map-attributes)).
- **Script** and **Bundler**: `group: ["Europe", "Italy"]` on each office, up to 3 names ([Every location](/locations/#every-location)), and `groupFilter`, `groupCounts` and `search` on the list ([List view options](/store/#list-view-options)). The boxes call [`setFilter`](/store/#methods) for you: `setFilter([["Europe", "Italy"]])` asks for one path, Italy's offices, while `setFilter(["Europe", "Italy"])` asks for two groups, Europe and a top-level Italy; `setFilter(["Europe"])` shows Europe's countries too.
- **React**: `<LocationList groupFilter groupCounts search />` inside `<MaplaceProvider>` ([`<LocationList>`](/react/#locationlist)).


### HTML on MapLibre

`packages/maplace/examples/offices/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-maplibre-map { height: 36rem; }
    #offices-maplibre-map > .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<!-- A company's offices around the world, each in a region and a country (a group path, as JSON in the group attribute): the list nests the countries under their regions, with how many each holds, and a checkbox for each region and country above it filters the map and the list. -->
<maplace-map id="offices-maplibre-map" list list-heading="Offices" group-counts group-filter search
  search-label="Find an office">
  <maplace-location location-id="milan" lat="45.46" lng="9.19" title="Milan" group='["Europe","Italy"]'></maplace-location>
  <maplace-location location-id="rome" lat="41.9" lng="12.5" title="Rome" group='["Europe","Italy"]'></maplace-location>
  <maplace-location location-id="turin" lat="45.07" lng="7.69" title="Turin" group='["Europe","Italy"]'></maplace-location>
  <maplace-location location-id="paris" lat="48.86" lng="2.35" title="Paris" group='["Europe","France"]'></maplace-location>
  <maplace-location location-id="lyon" lat="45.76" lng="4.84" title="Lyon" group='["Europe","France"]'></maplace-location>
  <maplace-location location-id="london" lat="51.51" lng="-0.13" title="London" group='["Europe","United Kingdom"]'></maplace-location>
  <maplace-location location-id="manchester" lat="53.48" lng="-2.24" title="Manchester" group='["Europe","United Kingdom"]'></maplace-location>
  <maplace-location location-id="tokyo" lat="35.68" lng="139.69" title="Tokyo" group='["Asia","Japan"]'></maplace-location>
  <maplace-location location-id="osaka" lat="34.69" lng="135.5" title="Osaka" group='["Asia","Japan"]'></maplace-location>
  <maplace-location location-id="singapore" lat="1.29" lng="103.85" title="Singapore" group='["Asia","Singapore"]'></maplace-location>
  <maplace-location location-id="new-york" lat="40.71" lng="-74.01" title="New York" group='["Americas","United States"]'></maplace-location>
  <maplace-location location-id="chicago" lat="41.88" lng="-87.63" title="Chicago" group='["Americas","United States"]'></maplace-location>
  <maplace-location location-id="san-francisco" lat="37.77" lng="-122.42" title="San Francisco" group='["Americas","United States"]'></maplace-location>
  <maplace-location location-id="sao-paulo" lat="-23.55" lng="-46.63" title="São Paulo" group='["Americas","Brazil"]'></maplace-location>
  <maplace-location location-id="rio" lat="-22.91" lng="-43.17" title="Rio de Janeiro" group='["Americas","Brazil"]'></maplace-location>
  <maplace-location location-id="recife" lat="-8.05" lng="-34.88" title="Recife" group='["Americas","Brazil"]'></maplace-location>
</maplace-map>
```

### HTML on Google

`packages/maplace/examples/offices/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-map { height: 36rem; }
    #offices-map > .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<!-- A company's offices around the world, each in a region and a country (a group path, as JSON in the group attribute): the list nests the countries under their regions, with how many each holds, and a checkbox for each region and country above it filters the map and the list. -->
<maplace-map id="offices-map" api-key="YOUR_KEY" list list-heading="Offices" group-counts group-filter search
  search-label="Find an office">
  <maplace-location location-id="milan" lat="45.46" lng="9.19" title="Milan" group='["Europe","Italy"]'></maplace-location>
  <maplace-location location-id="rome" lat="41.9" lng="12.5" title="Rome" group='["Europe","Italy"]'></maplace-location>
  <maplace-location location-id="turin" lat="45.07" lng="7.69" title="Turin" group='["Europe","Italy"]'></maplace-location>
  <maplace-location location-id="paris" lat="48.86" lng="2.35" title="Paris" group='["Europe","France"]'></maplace-location>
  <maplace-location location-id="lyon" lat="45.76" lng="4.84" title="Lyon" group='["Europe","France"]'></maplace-location>
  <maplace-location location-id="london" lat="51.51" lng="-0.13" title="London" group='["Europe","United Kingdom"]'></maplace-location>
  <maplace-location location-id="manchester" lat="53.48" lng="-2.24" title="Manchester" group='["Europe","United Kingdom"]'></maplace-location>
  <maplace-location location-id="tokyo" lat="35.68" lng="139.69" title="Tokyo" group='["Asia","Japan"]'></maplace-location>
  <maplace-location location-id="osaka" lat="34.69" lng="135.5" title="Osaka" group='["Asia","Japan"]'></maplace-location>
  <maplace-location location-id="singapore" lat="1.29" lng="103.85" title="Singapore" group='["Asia","Singapore"]'></maplace-location>
  <maplace-location location-id="new-york" lat="40.71" lng="-74.01" title="New York" group='["Americas","United States"]'></maplace-location>
  <maplace-location location-id="chicago" lat="41.88" lng="-87.63" title="Chicago" group='["Americas","United States"]'></maplace-location>
  <maplace-location location-id="san-francisco" lat="37.77" lng="-122.42" title="San Francisco" group='["Americas","United States"]'></maplace-location>
  <maplace-location location-id="sao-paulo" lat="-23.55" lng="-46.63" title="São Paulo" group='["Americas","Brazil"]'></maplace-location>
  <maplace-location location-id="rio" lat="-22.91" lng="-43.17" title="Rio de Janeiro" group='["Americas","Brazil"]'></maplace-location>
  <maplace-location location-id="recife" lat="-8.05" lng="-34.88" title="Recife" group='["Americas","Brazil"]'></maplace-location>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/offices/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet and what the map and its list mount on, and the map made with Maplace; the offices by region and country, a checkbox for each above the list. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #offices-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #offices-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #offices-maplibre-script-list { display: contents; }
  #offices-maplibre-script-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-maplibre-script-map-and-list { flex-direction: column; height: 36rem; }
    #offices-maplibre-script-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="offices-maplibre-script-map-and-list">
  <div id="offices-maplibre-script-map"></div>
  <div id="offices-maplibre-script-list"></div>
</div>
<script type="module">
  // Each office in a region and a country: a group path, outermost first.
  const offices = await fetch("/examples/data/offices.json").then((response) => response.json());
  Maplace.createMapLibreMap("#offices-maplibre-script-map", {
    locations: offices,
    list: {
      container: "#offices-maplibre-script-list",
      heading: "Offices",
      groupCounts: true,
      groupFilter: true,
      search: true,
      searchLabel: "Find an office",
    },
  });
</script>
```

### Script on Google

`packages/maplace/examples/offices/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script and what the map and its list mount on, and the map made with Maplace, which adds Maps JS with your key; the offices by region and country, a checkbox for each above the list. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #offices-script-map-and-list { display: flex; height: 24rem; }
  #offices-script-map { flex: 1 1 auto; min-width: 0; }
  #offices-script-list { display: contents; }
  #offices-script-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-script-map-and-list { flex-direction: column; height: 36rem; }
    #offices-script-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="offices-script-map-and-list">
  <div id="offices-script-map"></div>
  <div id="offices-script-list"></div>
</div>
<script type="module">
  // Each office in a region and a country: a group path, outermost first.
  const offices = await fetch("/examples/data/offices.json").then((response) => response.json());
  Maplace.createGoogleMap("#offices-script-map", {
    apiKey: "YOUR_KEY",
    locations: offices,
    list: {
      container: "#offices-script-list",
      heading: "Offices",
      groupCounts: true,
      groupFilter: true,
      search: true,
      searchLabel: "Find an office",
    },
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/offices/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the map and its list mount on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #offices-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #offices-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #offices-maplibre-vanilla-list { display: contents; }
  #offices-maplibre-vanilla-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-maplibre-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #offices-maplibre-vanilla-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="offices-maplibre-vanilla-map-and-list">
  <div id="offices-maplibre-vanilla-map"></div>
  <div id="offices-maplibre-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/offices/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

// Each office in a region and a country: a group path, outermost first.
const offices: Location[] = await (await fetch("/examples/data/offices.json")).json();

createMapLibreMap("#offices-maplibre-vanilla-map", {
  locations: offices,
  list: {
    container: "#offices-maplibre-vanilla-list",
    heading: "Offices",
    groupCounts: true,
    groupFilter: true,
    search: true,
    searchLabel: "Find an office",
  },
});
```

### Bundler on Google

`packages/maplace/examples/offices/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #offices-vanilla-map-and-list { display: flex; height: 24rem; }
  #offices-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #offices-vanilla-list { display: contents; }
  #offices-vanilla-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #offices-vanilla-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="offices-vanilla-map-and-list">
  <div id="offices-vanilla-map"></div>
  <div id="offices-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/offices/vanilla.ts`

```ts
import type { Location } from "@maplacejs/maplace";
import { createGoogleMap } from "@maplacejs/maplace/google";

// Each office in a region and a country: a group path, outermost first.
const offices: Location[] = await (await fetch("/examples/data/offices.json")).json();

createGoogleMap("#offices-vanilla-map", {
  locations: offices,
  list: {
    container: "#offices-vanilla-list",
    heading: "Offices",
    groupCounts: true,
    groupFilter: true,
    search: true,
    searchLabel: "Find an office",
  },
});
```

### React on MapLibre

`packages/maplace/examples/offices/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #offices-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #offices-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #offices-maplibre-react-root .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-maplibre-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #offices-maplibre-react-root .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="offices-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/offices/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode, useEffect, useState } from "react";
import { createRoot } from "react-dom/client";

function Offices() {
  // Each office in a region and a country: a group path, outermost first.
  const [offices, setOffices] = useState<readonly Location[]>([]);
  useEffect(() => {
    fetch("/examples/data/offices.json")
      .then((response) => response.json())
      .then(setOffices);
  }, []);
  return (
    <MaplaceProvider locations={offices}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
        <LocationList
          heading="Offices"
          groupCounts
          groupFilter
          search
          searchLabel="Find an office"
        />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("offices-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <Offices />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/offices/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #offices-react-root .map-and-list { display: flex; height: 24rem; }
  #offices-react-root .map { flex: 1 1 auto; min-width: 0; }
  #offices-react-root .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #offices-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #offices-react-root .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="offices-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/offices/react.tsx`

```tsx
import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode, useEffect, useState } from "react";
import { createRoot } from "react-dom/client";

function Offices() {
  // Each office in a region and a country: a group path, outermost first.
  const [offices, setOffices] = useState<readonly Location[]>([]);
  useEffect(() => {
    fetch("/examples/data/offices.json")
      .then((response) => response.json())
      .then(setOffices);
  }, []);
  return (
    <MaplaceProvider locations={offices}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
        <LocationList
          heading="Offices"
          groupCounts
          groupFilter
          search
          searchLabel="Find an office"
        />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("offices-react-root") as HTMLElement).render(
  <StrictMode>
    <Offices />
  </StrictMode>,
);
```

## Search box

A box above the list that narrows the list and the map as you type.

A box above the list narrows the list and the map when your typing pauses: by a place's name, its group or its `searchText`, ignoring case and accents. A line under the box says how many are found, or that none is. The map doesn't move: choose an entry and it pans there.

- **Try it**: type "forli" to find Forlì, or "harbour" to find the places with that word in their `searchText`.
- **HTML**: `search` on `<maplace-map>` turns the box on and `search-label` sets its placeholder, while `no-matches-label` and `matches-label` set what the line under it says when nothing matches and before the count ([Map attributes](/element/#map-attributes)), and `search-text` on a `<maplace-location>` is what it also looks in ([Location attributes](/element/#location-attributes)).
- **Script** and **Bundler**: `list: { container, search: true, searchLabel: "Find a place" }` in the map's options ([List view options](/store/#list-view-options)), and `searchText` on a location ([Every location](/locations/#every-location)).
- **React**: `<LocationList search searchLabel="Find a place" />` beside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)).
- **Your own box**: the built-in box calls [`setFilter`](/store/#methods) once typing pauses, so the map doesn't redraw under each key, and keeps the rest of the filter. `setFilter` itself replaces the whole filter: a box or checkboxes of your own spread `getSnapshot().filter` to keep the query.


### HTML on MapLibre

`packages/maplace/examples/search/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-maplibre-map { height: 36rem; }
    #search-maplibre-map > .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<!-- Places in a list beside the map, under a search box: typing narrows the list and the map by name, group or search-text. -->
<maplace-map id="search-maplibre-map" list search search-label="Find a place">
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome" group="Centre"></maplace-location>
  <maplace-location location-id="bologna" lat="44.4949" lng="11.3426" title="Bologna" group="Centre" search-text="pasta"></maplace-location>
  <maplace-location location-id="forli" lat="44.2227" lng="12.0407" title="Forlì" group="Centre"></maplace-location>
  <maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan" group="North"></maplace-location>
  <maplace-location location-id="turin" lat="45.0703" lng="7.6869" title="Turin" group="North"></maplace-location>
  <maplace-location location-id="genoa" lat="44.4056" lng="8.9463" title="Genoa" group="North" search-text="pasta, harbour"></maplace-location>
  <maplace-location location-id="naples" lat="40.8518" lng="14.2681" title="Naples" group="South" search-text="pizza, harbour"></maplace-location>
  <maplace-location location-id="bari" lat="41.1171" lng="16.8719" title="Bari" group="South" search-text="harbour"></maplace-location>
</maplace-map>
```

### HTML on Google

`packages/maplace/examples/search/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-map { height: 36rem; }
    #search-map > .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<!-- Places in a list beside the map, under a search box: typing narrows the list and the map by name, group or search-text. -->
<maplace-map id="search-map" api-key="YOUR_KEY" list search search-label="Find a place">
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome" group="Centre"></maplace-location>
  <maplace-location location-id="bologna" lat="44.4949" lng="11.3426" title="Bologna" group="Centre" search-text="pasta"></maplace-location>
  <maplace-location location-id="forli" lat="44.2227" lng="12.0407" title="Forlì" group="Centre"></maplace-location>
  <maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan" group="North"></maplace-location>
  <maplace-location location-id="turin" lat="45.0703" lng="7.6869" title="Turin" group="North"></maplace-location>
  <maplace-location location-id="genoa" lat="44.4056" lng="8.9463" title="Genoa" group="North" search-text="pasta, harbour"></maplace-location>
  <maplace-location location-id="naples" lat="40.8518" lng="14.2681" title="Naples" group="South" search-text="pizza, harbour"></maplace-location>
  <maplace-location location-id="bari" lat="41.1171" lng="16.8719" title="Bari" group="South" search-text="harbour"></maplace-location>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/search/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet and what the map and its list mount on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #search-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #search-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #search-maplibre-script-list { display: contents; }
  #search-maplibre-script-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-maplibre-script-map-and-list { flex-direction: column; height: 36rem; }
    #search-maplibre-script-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="search-maplibre-script-map-and-list">
  <div id="search-maplibre-script-map"></div>
  <div id="search-maplibre-script-list"></div>
</div>
<script type="module">
  Maplace.createMapLibreMap("#search-maplibre-script-map", {
    locations: [
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre" },
      { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre", searchText: "pasta" },
      { id: "forli", lat: 44.2227, lng: 12.0407, title: "Forlì", group: "Centre" },
      { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North" },
      { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North" },
      {
        id: "genoa",
        lat: 44.4056,
        lng: 8.9463,
        title: "Genoa",
        group: "North",
        searchText: "pasta, harbour",
      },
      {
        id: "naples",
        lat: 40.8518,
        lng: 14.2681,
        title: "Naples",
        group: "South",
        searchText: "pizza, harbour",
      },
      { id: "bari", lat: 41.1171, lng: 16.8719, title: "Bari", group: "South", searchText: "harbour" },
    ],
    list: { container: "#search-maplibre-script-list", search: true, searchLabel: "Find a place" },
  });
</script>
```

### Script on Google

`packages/maplace/examples/search/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script and what the map and its list mount on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #search-script-map-and-list { display: flex; height: 24rem; }
  #search-script-map { flex: 1 1 auto; min-width: 0; }
  #search-script-list { display: contents; }
  #search-script-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-script-map-and-list { flex-direction: column; height: 36rem; }
    #search-script-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="search-script-map-and-list">
  <div id="search-script-map"></div>
  <div id="search-script-list"></div>
</div>
<script type="module">
  Maplace.createGoogleMap("#search-script-map", {
    apiKey: "YOUR_KEY",
    locations: [
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre" },
      { id: "bologna", lat: 44.4949, lng: 11.3426, title: "Bologna", group: "Centre", searchText: "pasta" },
      { id: "forli", lat: 44.2227, lng: 12.0407, title: "Forlì", group: "Centre" },
      { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North" },
      { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North" },
      {
        id: "genoa",
        lat: 44.4056,
        lng: 8.9463,
        title: "Genoa",
        group: "North",
        searchText: "pasta, harbour",
      },
      {
        id: "naples",
        lat: 40.8518,
        lng: 14.2681,
        title: "Naples",
        group: "South",
        searchText: "pizza, harbour",
      },
      { id: "bari", lat: 41.1171, lng: 16.8719, title: "Bari", group: "South", searchText: "harbour" },
    ],
    list: { container: "#search-script-list", search: true, searchLabel: "Find a place" },
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/search/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #search-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #search-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #search-maplibre-vanilla-list { display: contents; }
  #search-maplibre-vanilla-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-maplibre-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #search-maplibre-vanilla-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="search-maplibre-vanilla-map-and-list">
  <div id="search-maplibre-vanilla-map"></div>
  <div id="search-maplibre-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/search/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

createMapLibreMap("#search-maplibre-vanilla-map", {
  locations: [
    { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre" },
    {
      id: "bologna",
      lat: 44.4949,
      lng: 11.3426,
      title: "Bologna",
      group: "Centre",
      searchText: "pasta",
    },
    { id: "forli", lat: 44.2227, lng: 12.0407, title: "Forlì", group: "Centre" },
    { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North" },
    { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North" },
    {
      id: "genoa",
      lat: 44.4056,
      lng: 8.9463,
      title: "Genoa",
      group: "North",
      searchText: "pasta, harbour",
    },
    {
      id: "naples",
      lat: 40.8518,
      lng: 14.2681,
      title: "Naples",
      group: "South",
      searchText: "pizza, harbour",
    },
    {
      id: "bari",
      lat: 41.1171,
      lng: 16.8719,
      title: "Bari",
      group: "South",
      searchText: "harbour",
    },
  ],
  list: {
    container: "#search-maplibre-vanilla-list",
    search: true,
    searchLabel: "Find a place",
  },
});
```

### Bundler on Google

`packages/maplace/examples/search/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #search-vanilla-map-and-list { display: flex; height: 24rem; }
  #search-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #search-vanilla-list { display: contents; }
  #search-vanilla-list .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #search-vanilla-list .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="search-vanilla-map-and-list">
  <div id="search-vanilla-map"></div>
  <div id="search-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/search/vanilla.ts`

```ts
import { createGoogleMap } from "@maplacejs/maplace/google";

createGoogleMap("#search-vanilla-map", {
  locations: [
    { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre" },
    {
      id: "bologna",
      lat: 44.4949,
      lng: 11.3426,
      title: "Bologna",
      group: "Centre",
      searchText: "pasta",
    },
    { id: "forli", lat: 44.2227, lng: 12.0407, title: "Forlì", group: "Centre" },
    { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North" },
    { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North" },
    {
      id: "genoa",
      lat: 44.4056,
      lng: 8.9463,
      title: "Genoa",
      group: "North",
      searchText: "pasta, harbour",
    },
    {
      id: "naples",
      lat: 40.8518,
      lng: 14.2681,
      title: "Naples",
      group: "South",
      searchText: "pizza, harbour",
    },
    {
      id: "bari",
      lat: 41.1171,
      lng: 16.8719,
      title: "Bari",
      group: "South",
      searchText: "harbour",
    },
  ],
  list: {
    container: "#search-vanilla-list",
    search: true,
    searchLabel: "Find a place",
  },
});
```

### React on MapLibre

`packages/maplace/examples/search/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #search-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #search-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #search-maplibre-react-root .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-maplibre-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #search-maplibre-react-root .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="search-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/search/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre" },
  {
    id: "bologna",
    lat: 44.4949,
    lng: 11.3426,
    title: "Bologna",
    group: "Centre",
    searchText: "pasta",
  },
  { id: "forli", lat: 44.2227, lng: 12.0407, title: "Forlì", group: "Centre" },
  { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North" },
  { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North" },
  {
    id: "genoa",
    lat: 44.4056,
    lng: 8.9463,
    title: "Genoa",
    group: "North",
    searchText: "pasta, harbour",
  },
  {
    id: "naples",
    lat: 40.8518,
    lng: 14.2681,
    title: "Naples",
    group: "South",
    searchText: "pizza, harbour",
  },
  { id: "bari", lat: 41.1171, lng: 16.8719, title: "Bari", group: "South", searchText: "harbour" },
];

function Search() {
  return (
    <MaplaceProvider locations={cities}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
        <LocationList search searchLabel="Find a place" />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("search-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <Search />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/search/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #search-react-root .map-and-list { display: flex; height: 24rem; }
  #search-react-root .map { flex: 1 1 auto; min-width: 0; }
  #search-react-root .maplace-list { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size as the places narrow. */
  @media (width < 40rem) {
    #search-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #search-react-root .maplace-list { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="search-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/search/react.tsx`

```tsx
import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome", group: "Centre" },
  {
    id: "bologna",
    lat: 44.4949,
    lng: 11.3426,
    title: "Bologna",
    group: "Centre",
    searchText: "pasta",
  },
  { id: "forli", lat: 44.2227, lng: 12.0407, title: "Forlì", group: "Centre" },
  { id: "milan", lat: 45.4642, lng: 9.19, title: "Milan", group: "North" },
  { id: "turin", lat: 45.0703, lng: 7.6869, title: "Turin", group: "North" },
  {
    id: "genoa",
    lat: 44.4056,
    lng: 8.9463,
    title: "Genoa",
    group: "North",
    searchText: "pasta, harbour",
  },
  {
    id: "naples",
    lat: 40.8518,
    lng: 14.2681,
    title: "Naples",
    group: "South",
    searchText: "pizza, harbour",
  },
  { id: "bari", lat: 41.1171, lng: 16.8719, title: "Bari", group: "South", searchText: "harbour" },
];

function Search() {
  return (
    <MaplaceProvider locations={cities}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
        <LocationList search searchLabel="Find a place" />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("search-react-root") as HTMLElement).render(
  <StrictMode>
    <Search />
  </StrictMode>,
);
```

## Nearest first

A button on the map that sorts the list by distance from the visitor.

The **My location** button on the map asks the browser for the visitor's position only when it is pressed, then sorts the list nearest first, each entry saying how far in a straight line, marks the place with a dot and moves the map there.

- **Try it**: press **My location**, top left on the map, and allow it; press it again and the list goes back. If the visitor refuses, or the page isn't on HTTPS, a line under the button says "Location unavailable" and nothing else changes.
- **HTML**: `list-sort="distance"` and `my-location` on `<maplace-map>`, with `distance-unit="mile"` for miles ([Map attributes](/element/#map-attributes)).
- **Script** and **Bundler**: `sort: "distance"` in `list`, and `myLocation: true` in the map's options ([Distances](/store/#distances)).
- **React**: `<LocationList sort="distance" />`, and `<MyLocation />` inside the `<MaplaceMap>` ([`<MyLocation>`](/react/#mylocation)).
- **Another point**: [`setOrigin`](/store/#methods) takes any point, so a click measures from there: `map.on("mapClick", ({ position }) => map.setOrigin(position))`, and [a form of your own](/locations/#a-visitors-address) measures from a typed address.


### HTML on MapLibre

`packages/maplace/examples/nearest/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- Places in a list beside the map; the "My location" button on the map sorts it nearest first, each entry saying how far. -->
<maplace-map id="nearest-maplibre-map" list list-sort="distance" my-location>
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London"></maplace-location>
  <maplace-location location-id="bristol" lat="51.4545" lng="-2.5879" title="Bristol"></maplace-location>
  <maplace-location location-id="birmingham" lat="52.4862" lng="-1.8904" title="Birmingham"></maplace-location>
  <maplace-location location-id="manchester" lat="53.4808" lng="-2.2426" title="Manchester"></maplace-location>
  <maplace-location location-id="leeds" lat="53.8008" lng="-1.5491" title="Leeds"></maplace-location>
</maplace-map>
```

### HTML on Google

`packages/maplace/examples/nearest/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- Places in a list beside the map; the "My location" button on the map sorts it nearest first, each entry saying how far. -->
<maplace-map id="nearest-map" api-key="YOUR_KEY" list list-sort="distance" my-location>
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London"></maplace-location>
  <maplace-location location-id="bristol" lat="51.4545" lng="-2.5879" title="Bristol"></maplace-location>
  <maplace-location location-id="birmingham" lat="52.4862" lng="-1.8904" title="Birmingham"></maplace-location>
  <maplace-location location-id="manchester" lat="53.4808" lng="-2.2426" title="Manchester"></maplace-location>
  <maplace-location location-id="leeds" lat="53.8008" lng="-1.5491" title="Leeds"></maplace-location>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/nearest/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, what the map and its list mount on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #nearest-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #nearest-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #nearest-maplibre-script-list { display: contents; }
  #nearest-maplibre-script-list [role="listbox"] { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #nearest-maplibre-script-map-and-list { flex-direction: column; }
    #nearest-maplibre-script-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="nearest-maplibre-script-map-and-list">
  <div id="nearest-maplibre-script-map"></div>
  <div id="nearest-maplibre-script-list"></div>
</div>
<script type="module">
  Maplace.createMapLibreMap("#nearest-maplibre-script-map", {
    locations: [
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
      { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol" },
      { id: "birmingham", lat: 52.4862, lng: -1.8904, title: "Birmingham" },
      { id: "manchester", lat: 53.4808, lng: -2.2426, title: "Manchester" },
      { id: "leeds", lat: 53.8008, lng: -1.5491, title: "Leeds" },
    ],
    list: { container: "#nearest-maplibre-script-list", sort: "distance" },
    myLocation: true,
  });
</script>
```

### Script on Google

`packages/maplace/examples/nearest/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, what the map and its list mount on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #nearest-script-map-and-list { display: flex; height: 24rem; }
  #nearest-script-map { flex: 1 1 auto; min-width: 0; }
  #nearest-script-list { display: contents; }
  #nearest-script-list [role="listbox"] { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #nearest-script-map-and-list { flex-direction: column; }
    #nearest-script-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="nearest-script-map-and-list">
  <div id="nearest-script-map"></div>
  <div id="nearest-script-list"></div>
</div>
<script type="module">
  Maplace.createGoogleMap("#nearest-script-map", {
    apiKey: "YOUR_KEY",
    locations: [
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
      { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol" },
      { id: "birmingham", lat: 52.4862, lng: -1.8904, title: "Birmingham" },
      { id: "manchester", lat: 53.4808, lng: -2.2426, title: "Manchester" },
      { id: "leeds", lat: 53.8008, lng: -1.5491, title: "Leeds" },
    ],
    list: { container: "#nearest-script-list", sort: "distance" },
    myLocation: true,
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/nearest/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #nearest-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #nearest-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #nearest-maplibre-vanilla-list { display: contents; }
  #nearest-maplibre-vanilla-list [role="listbox"] { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #nearest-maplibre-vanilla-map-and-list { flex-direction: column; }
    #nearest-maplibre-vanilla-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="nearest-maplibre-vanilla-map-and-list">
  <div id="nearest-maplibre-vanilla-map"></div>
  <div id="nearest-maplibre-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/nearest/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

createMapLibreMap("#nearest-maplibre-vanilla-map", {
  locations: [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
    { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol" },
    { id: "birmingham", lat: 52.4862, lng: -1.8904, title: "Birmingham" },
    { id: "manchester", lat: 53.4808, lng: -2.2426, title: "Manchester" },
    { id: "leeds", lat: 53.8008, lng: -1.5491, title: "Leeds" },
  ],
  list: { container: "#nearest-maplibre-vanilla-list", sort: "distance" },
  myLocation: true,
});
```

### Bundler on Google

`packages/maplace/examples/nearest/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #nearest-vanilla-map-and-list { display: flex; height: 24rem; }
  #nearest-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #nearest-vanilla-list { display: contents; }
  #nearest-vanilla-list [role="listbox"] { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #nearest-vanilla-map-and-list { flex-direction: column; }
    #nearest-vanilla-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="nearest-vanilla-map-and-list">
  <div id="nearest-vanilla-map"></div>
  <div id="nearest-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/nearest/vanilla.ts`

```ts
import { createGoogleMap } from "@maplacejs/maplace/google";

createGoogleMap("#nearest-vanilla-map", {
  locations: [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
    { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol" },
    { id: "birmingham", lat: 52.4862, lng: -1.8904, title: "Birmingham" },
    { id: "manchester", lat: 53.4808, lng: -2.2426, title: "Manchester" },
    { id: "leeds", lat: 53.8008, lng: -1.5491, title: "Leeds" },
  ],
  list: { container: "#nearest-vanilla-list", sort: "distance" },
  myLocation: true,
});
```

### React on MapLibre

`packages/maplace/examples/nearest/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #nearest-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #nearest-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #nearest-maplibre-react-root [role="listbox"] { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #nearest-maplibre-react-root .map-and-list { flex-direction: column; }
    #nearest-maplibre-react-root [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="nearest-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/nearest/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider, MyLocation } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
  { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol" },
  { id: "birmingham", lat: 52.4862, lng: -1.8904, title: "Birmingham" },
  { id: "manchester", lat: 53.4808, lng: -2.2426, title: "Manchester" },
  { id: "leeds", lat: 53.8008, lng: -1.5491, title: "Leeds" },
];

function Nearest() {
  return (
    <MaplaceProvider locations={cities}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map">
          <MyLocation />
        </MaplaceMap>
        <LocationList sort="distance" />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("nearest-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <Nearest />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/nearest/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #nearest-react-root .map-and-list { display: flex; height: 24rem; }
  #nearest-react-root .map { flex: 1 1 auto; min-width: 0; }
  #nearest-react-root [role="listbox"] { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #nearest-react-root .map-and-list { flex-direction: column; }
    #nearest-react-root [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="nearest-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/nearest/react.tsx`

```tsx
import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider, MyLocation } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
  { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol" },
  { id: "birmingham", lat: 52.4862, lng: -1.8904, title: "Birmingham" },
  { id: "manchester", lat: 53.4808, lng: -2.2426, title: "Manchester" },
  { id: "leeds", lat: 53.8008, lng: -1.5491, title: "Leeds" },
];

function Nearest() {
  return (
    <MaplaceProvider locations={cities}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map">
          <MyLocation />
        </MaplaceMap>
        <LocationList sort="distance" />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("nearest-react-root") as HTMLElement).render(
  <StrictMode>
    <Nearest />
  </StrictMode>,
);
```

## This area

A switch above the list: every place, or only those in view as the map moves.

The list on the map, top left, has a switch above it: every place, or only those in view as the map moves.

- **Try it**: "All", pressed at first, lists every capital. Press "This area", and the list holds those in view, listing again as you pan or zoom; choosing an entry moves the map too. Over an empty patch of sea, the list says so. "All" lists them all again.
- **HTML**: `list-scope="viewport"` on `<maplace-map>`, beside `list` and `list-position`, with `area-only-label`, `show-all-label` and `empty-area-label` for its wording ([Map attributes](/element/#map-attributes)).
- **Script** and **Bundler**: `list: { scope: "viewport", position: "top-left" }` in the map's options, with `areaOnlyLabel`, `showAllLabel` and `emptyAreaLabel` ([List view options](/store/#list-view-options); `position`, [on Google](/google/#creategooglemap), [on MapLibre](/maplibre/#createmaplibremap)).
- **React**: `<LocationList scope="viewport" position="top-left" />` inside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)).
- **Its corner**: any of the four, `top-left` here. Left of the map is where a list has the most room on Google, which stacks its fullscreen button, camera control and Pegman on the right ([On-map controls](/google/#on-map-controls)). Without a `position`, the list goes top right.


### HTML on MapLibre

`packages/maplace/examples/this-area/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- A list on the map that follows it: its switch lists "All", or in "This area" what is in view as the map moves. -->
<maplace-map id="this-area-maplibre-map" list list-position="top-left" list-scope="viewport">
  <maplace-location location-id="lisbon" lat="38.7223" lng="-9.1393" title="Lisbon"></maplace-location>
  <maplace-location location-id="madrid" lat="40.4168" lng="-3.7038" title="Madrid"></maplace-location>
  <maplace-location location-id="paris" lat="48.8566" lng="2.3522" title="Paris"></maplace-location>
  <maplace-location location-id="brussels" lat="50.8503" lng="4.3517" title="Brussels"></maplace-location>
  <maplace-location location-id="amsterdam" lat="52.3676" lng="4.9041" title="Amsterdam"></maplace-location>
  <maplace-location location-id="berlin" lat="52.52" lng="13.405" title="Berlin"></maplace-location>
  <maplace-location location-id="copenhagen" lat="55.6761" lng="12.5683" title="Copenhagen"></maplace-location>
  <maplace-location location-id="vienna" lat="48.2082" lng="16.3738" title="Vienna"></maplace-location>
  <maplace-location location-id="prague" lat="50.0755" lng="14.4378" title="Prague"></maplace-location>
  <maplace-location location-id="warsaw" lat="52.2297" lng="21.0122" title="Warsaw"></maplace-location>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome"></maplace-location>
  <maplace-location location-id="athens" lat="37.9838" lng="23.7275" title="Athens"></maplace-location>
</maplace-map>
```

### HTML on Google

`packages/maplace/examples/this-area/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- A list on the map that follows it: its switch lists "All", or in "This area" what is in view as the map moves. -->
<maplace-map id="this-area-map" api-key="YOUR_KEY" list list-position="top-left" list-scope="viewport">
  <maplace-location location-id="lisbon" lat="38.7223" lng="-9.1393" title="Lisbon"></maplace-location>
  <maplace-location location-id="madrid" lat="40.4168" lng="-3.7038" title="Madrid"></maplace-location>
  <maplace-location location-id="paris" lat="48.8566" lng="2.3522" title="Paris"></maplace-location>
  <maplace-location location-id="brussels" lat="50.8503" lng="4.3517" title="Brussels"></maplace-location>
  <maplace-location location-id="amsterdam" lat="52.3676" lng="4.9041" title="Amsterdam"></maplace-location>
  <maplace-location location-id="berlin" lat="52.52" lng="13.405" title="Berlin"></maplace-location>
  <maplace-location location-id="copenhagen" lat="55.6761" lng="12.5683" title="Copenhagen"></maplace-location>
  <maplace-location location-id="vienna" lat="48.2082" lng="16.3738" title="Vienna"></maplace-location>
  <maplace-location location-id="prague" lat="50.0755" lng="14.4378" title="Prague"></maplace-location>
  <maplace-location location-id="warsaw" lat="52.2297" lng="21.0122" title="Warsaw"></maplace-location>
  <maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome"></maplace-location>
  <maplace-location location-id="athens" lat="37.9838" lng="23.7275" title="Athens"></maplace-location>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/this-area/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, what the map mounts on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #this-area-maplibre-script-map { height: 24rem; }
</style>
<div id="this-area-maplibre-script-map"></div>
<script type="module">
  Maplace.createMapLibreMap("#this-area-maplibre-script-map", {
    locations: [
      { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
      { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
      { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
      { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
      { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
      { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
      { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
      { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
      { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
      { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
      { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
    ],
    list: { scope: "viewport", position: "top-left" },
  });
</script>
```

### Script on Google

`packages/maplace/examples/this-area/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, what the map mounts on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #this-area-script-map { height: 24rem; }
</style>
<div id="this-area-script-map"></div>
<script type="module">
  Maplace.createGoogleMap("#this-area-script-map", {
    apiKey: "YOUR_KEY",
    locations: [
      { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
      { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
      { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
      { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
      { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
      { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
      { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
      { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
      { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
      { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
      { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
      { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
    ],
    list: { scope: "viewport", position: "top-left" },
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/this-area/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #this-area-maplibre-vanilla-map { height: 24rem; }
</style>
<div id="this-area-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/this-area/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

createMapLibreMap("#this-area-maplibre-vanilla-map", {
  locations: [
    { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
    { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
    { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
    { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
    { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
    { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
    { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
    { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
    { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
    { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
    { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
    { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
  ],
  // On the map, top-left: a list switched between "All" and "This area", what is in view.
  list: { scope: "viewport", position: "top-left" },
});
```

### Bundler on Google

`packages/maplace/examples/this-area/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #this-area-vanilla-map { height: 24rem; }
</style>
<div id="this-area-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/this-area/vanilla.ts`

```ts
import { createGoogleMap } from "@maplacejs/maplace/google";

createGoogleMap("#this-area-vanilla-map", {
  locations: [
    { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
    { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
    { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
    { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
    { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
    { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
    { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
    { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
    { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
    { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
    { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
    { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
  ],
  // On the map, top-left: a list switched between "All" and "This area", what is in view.
  list: { scope: "viewport", position: "top-left" },
});
```

### React on MapLibre

`packages/maplace/examples/this-area/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #this-area-maplibre-react-root .map { height: 24rem; }
</style>
<div id="this-area-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/this-area/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

const capitals: Location[] = [
  { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
  { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
  { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
  { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
  { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
  { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
  { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
  { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
  { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
  { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
  { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
  { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
];

function ThisArea() {
  return (
    <MaplaceProvider locations={capitals}>
      <MaplaceMap createAdapter={createMapLibreAdapter} className="map">
        {/* A list switched between "All" and "This area", what is in view as the map moves. */}
        <LocationList scope="viewport" position="top-left" />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("this-area-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <ThisArea />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/this-area/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #this-area-react-root .map { height: 24rem; }
</style>
<div id="this-area-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/this-area/react.tsx`

```tsx
import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

const capitals: Location[] = [
  { id: "lisbon", lat: 38.7223, lng: -9.1393, title: "Lisbon" },
  { id: "madrid", lat: 40.4168, lng: -3.7038, title: "Madrid" },
  { id: "paris", lat: 48.8566, lng: 2.3522, title: "Paris" },
  { id: "brussels", lat: 50.8503, lng: 4.3517, title: "Brussels" },
  { id: "amsterdam", lat: 52.3676, lng: 4.9041, title: "Amsterdam" },
  { id: "berlin", lat: 52.52, lng: 13.405, title: "Berlin" },
  { id: "copenhagen", lat: 55.6761, lng: 12.5683, title: "Copenhagen" },
  { id: "vienna", lat: 48.2082, lng: 16.3738, title: "Vienna" },
  { id: "prague", lat: 50.0755, lng: 14.4378, title: "Prague" },
  { id: "warsaw", lat: 52.2297, lng: 21.0122, title: "Warsaw" },
  { id: "rome", lat: 41.9028, lng: 12.4964, title: "Rome" },
  { id: "athens", lat: 37.9838, lng: 23.7275, title: "Athens" },
];

function ThisArea() {
  return (
    <MaplaceProvider locations={capitals}>
      <MaplaceMap createAdapter={createGoogleAdapter} className="map">
        {/* A list switched between "All" and "This area", what is in view as the map moves. */}
        <LocationList scope="viewport" position="top-left" />
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("this-area-react-root") as HTMLElement).render(
  <StrictMode>
    <ThisArea />
  </StrictMode>,
);
```

## Your own list

Define your own: here a radio per place, and one to fit all, on the map.

Maplace.js's lists are views of its store, and yours can be any element you build: one that calls the store's `select` and `fitAll`, and redraws when the store changes. This one is a radio per place and one to fit them all; each version below shows a way to put it on the map.

- **Try it**: choose a radio and the map goes to that place; choose "Fit all" and it shows them all. Cambridge is on the map only, left out with `listed="false"`.
- **HTML**: define it by name with [`defineListView(name, factory)`](/element/#list-views), `Maplace.defineListView` on the CDN script, and name it in `list`: `checks` here, `maplibre-checks` on the MapLibre page, since one document defines a name once. The factory gets the store and `listed()`, the locations Maplace.js's own lists would show, and returns `{ element, destroy }`; `list-position` places it as it does the built-in lists.
- **Script**: the Bundler version's code on the CDN script's `Maplace`, with no build step: `Maplace.createMaplace`, `Maplace.listedLocations` and the adapter's `mountControl`, as below.
- **Bundler**: redraw the element from [`listedLocations(snapshot)`](/store/#listed-locations) whenever the store's [`subscribe`](/store/#methods) calls back, and put it on the map with the adapter's [`mountControl(node, position)`](/store/#adapters).
- **React**: a component reading the store with [`useMaplace()`](/react/#usemaplace) and `useSyncExternalStore`, inside a [`<MapControl>`](/react/#mapcontrol).


### HTML on MapLibre

`packages/maplace/examples/custom-list/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- A list view of your own: a radio per listed location and one to fit them all, defined by
     name and placed on the map as Maplace.js's own lists are. -->
<style>
  #custom-list-maplibre-map fieldset { border: 0; padding: 0; }
  #custom-list-maplibre-map fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<maplace-map id="custom-list-maplibre-map" list="maplibre-checks" list-position="top-right"
  list-heading="Choose a location:">
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London"></maplace-location>
  <maplace-location location-id="york" lat="53.9591" lng="-1.0815" title="York"></maplace-location>
  <maplace-location location-id="bath" lat="51.3811" lng="-2.359" title="Bath"></maplace-location>
  <maplace-location location-id="oxford" lat="51.752" lng="-1.2577" title="Oxford"></maplace-location>
  <maplace-location location-id="cambridge" lat="52.2053" lng="0.1218" title="Cambridge" listed="false"></maplace-location>
</maplace-map>
<script>
  Maplace.defineListView('maplibre-checks', (maplace, { options, listed }) => {
    const fieldset = document.createElement('fieldset');
    const legend = document.createElement('legend');
    legend.textContent = options.heading ?? 'Locations';
    const choices = document.createElement('div');
    fieldset.append(legend, choices);

    /** A radio choosing `id`, or fitting every location when `id` is empty. */
    function choice(id, title) {
      const radio = document.createElement('input');
      radio.type = 'radio';
      radio.name = 'custom-list-maplibre-choice';
      radio.value = id;
      radio.addEventListener('change', () => {
        maplace.select(id || undefined);
        if (!id) maplace.fitAll();
      });
      const label = document.createElement('label');
      label.append(radio, ` ${title}`);
      return label;
    }

    // The choices are made again when the listed locations change; the selection is checked.
    let listedIds;
    function render() {
      const locations = listed();
      const ids = locations.map(({ id }) => id).join();
      if (ids !== listedIds) {
        listedIds = ids;
        choices.replaceChildren(choice('', 'Fit all'), ...locations.map(({ id, title }) => choice(id, title ?? id)));
      }
      const selected = maplace.getSnapshot().selectedId ?? '';
      for (const radio of choices.querySelectorAll('input')) radio.checked = radio.value === selected;
    }

    render();
    const unsubscribe = maplace.subscribe(render);
    return { element: fieldset, destroy: () => { unsubscribe(); fieldset.remove(); } };
  });
</script>
```

### HTML on Google

`packages/maplace/examples/custom-list/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- A list view of your own: a radio per listed location and one to fit them all, defined by
     name and placed on the map as Maplace.js's own lists are. -->
<style>
  #custom-list-map fieldset { border: 0; padding: 0; }
  #custom-list-map fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<maplace-map id="custom-list-map" api-key="YOUR_KEY" list="checks" list-position="top-right"
  list-heading="Choose a location:">
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London"></maplace-location>
  <maplace-location location-id="york" lat="53.9591" lng="-1.0815" title="York"></maplace-location>
  <maplace-location location-id="bath" lat="51.3811" lng="-2.359" title="Bath"></maplace-location>
  <maplace-location location-id="oxford" lat="51.752" lng="-1.2577" title="Oxford"></maplace-location>
  <maplace-location location-id="cambridge" lat="52.2053" lng="0.1218" title="Cambridge" listed="false"></maplace-location>
</maplace-map>
<script>
  Maplace.defineListView('checks', (maplace, { options, listed }) => {
    const fieldset = document.createElement('fieldset');
    const legend = document.createElement('legend');
    legend.textContent = options.heading ?? 'Locations';
    const choices = document.createElement('div');
    fieldset.append(legend, choices);

    /** A radio choosing `id`, or fitting every location when `id` is empty. */
    function choice(id, title) {
      const radio = document.createElement('input');
      radio.type = 'radio';
      radio.name = 'custom-list-choice';
      radio.value = id;
      radio.addEventListener('change', () => {
        maplace.select(id || undefined);
        if (!id) maplace.fitAll();
      });
      const label = document.createElement('label');
      label.append(radio, ` ${title}`);
      return label;
    }

    // The choices are made again when the listed locations change; the selection is checked.
    let listedIds;
    function render() {
      const locations = listed();
      const ids = locations.map(({ id }) => id).join();
      if (ids !== listedIds) {
        listedIds = ids;
        choices.replaceChildren(choice('', 'Fit all'), ...locations.map(({ id, title }) => choice(id, title ?? id)));
      }
      const selected = maplace.getSnapshot().selectedId ?? '';
      for (const radio of choices.querySelectorAll('input')) radio.checked = radio.value === selected;
    }

    render();
    const unsubscribe = maplace.subscribe(render);
    return { element: fieldset, destroy: () => { unsubscribe(); fieldset.remove(); } };
  });
</script>
```

### Script on MapLibre

`packages/maplace/examples/custom-list/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, what the map mounts on, and the map made with Maplace's store and MapLibre adapter, with a list of your own on it. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #custom-list-maplibre-script-map { height: 24rem; }
  #custom-list-maplibre-script-map fieldset { border: 0; padding: 0; }
  #custom-list-maplibre-script-map fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<div id="custom-list-maplibre-script-map"></div>
<script type="module">
  const locations = [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
    { id: "york", lat: 53.9591, lng: -1.0815, title: "York" },
    { id: "bath", lat: 51.3811, lng: -2.359, title: "Bath" },
    { id: "oxford", lat: 51.752, lng: -1.2577, title: "Oxford" },
    { id: "cambridge", lat: 52.2053, lng: 0.1218, title: "Cambridge", listed: false },
  ];

  /** A radio choosing `id`, or fitting every location when `id` is empty. */
  function choice(maplace, id, title) {
    const radio = document.createElement("input");
    radio.type = "radio";
    radio.name = "custom-list-maplibre-script-choice";
    radio.value = id;
    radio.addEventListener("change", () => {
      maplace.select(id || undefined);
      if (!id) maplace.fitAll();
    });
    const label = document.createElement("label");
    label.append(radio, ` ${title}`);
    return label;
  }

  /**
   * A list of your own: a radio per location Maplace.js's lists would list, and one to fit them all.
   * The choices are made again when those change; the selection is checked.
   */
  function checksMenu(maplace, heading) {
    const fieldset = document.createElement("fieldset");
    const legend = document.createElement("legend");
    legend.textContent = heading;
    const choices = document.createElement("div");
    fieldset.append(legend, choices);
    let listedIds;
    const render = () => {
      const listed = Maplace.listedLocations(maplace.getSnapshot());
      const ids = listed.map(({ id }) => id).join();
      if (ids !== listedIds) {
        listedIds = ids;
        const entries = listed.map(({ id, title }) => choice(maplace, id, title ?? id));
        choices.replaceChildren(choice(maplace, "", "Fit all"), ...entries);
      }
      const selected = maplace.getSnapshot().selectedId ?? "";
      for (const radio of choices.querySelectorAll("input"))
        radio.checked = radio.value === selected;
    };
    render();
    maplace.subscribe(render);
    return fieldset;
  }

  const maplace = Maplace.createMaplace({ locations });
  const adapter = Maplace.createMapLibreAdapter();
  maplace.attach(adapter, "#custom-list-maplibre-script-map");
  adapter.mountControl(checksMenu(maplace, "Choose a location:"), "top-right");
</script>
```

### Script on Google

`packages/maplace/examples/custom-list/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, what the map mounts on, and the map made with Maplace's store and Google adapter, which adds Maps JS with your key, with a list of your own on it. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #custom-list-script-map { height: 24rem; }
  #custom-list-script-map fieldset { border: 0; padding: 0; }
  #custom-list-script-map fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<div id="custom-list-script-map"></div>
<script type="module">
  const locations = [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
    { id: "york", lat: 53.9591, lng: -1.0815, title: "York" },
    { id: "bath", lat: 51.3811, lng: -2.359, title: "Bath" },
    { id: "oxford", lat: 51.752, lng: -1.2577, title: "Oxford" },
    { id: "cambridge", lat: 52.2053, lng: 0.1218, title: "Cambridge", listed: false },
  ];

  /** A radio choosing `id`, or fitting every location when `id` is empty. */
  function choice(maplace, id, title) {
    const radio = document.createElement("input");
    radio.type = "radio";
    radio.name = "custom-list-script-choice";
    radio.value = id;
    radio.addEventListener("change", () => {
      maplace.select(id || undefined);
      if (!id) maplace.fitAll();
    });
    const label = document.createElement("label");
    label.append(radio, ` ${title}`);
    return label;
  }

  /**
   * A list of your own: a radio per location Maplace.js's lists would list, and one to fit them all.
   * The choices are made again when those change; the selection is checked.
   */
  function checksMenu(maplace, heading) {
    const fieldset = document.createElement("fieldset");
    const legend = document.createElement("legend");
    legend.textContent = heading;
    const choices = document.createElement("div");
    fieldset.append(legend, choices);
    let listedIds;
    const render = () => {
      const listed = Maplace.listedLocations(maplace.getSnapshot());
      const ids = listed.map(({ id }) => id).join();
      if (ids !== listedIds) {
        listedIds = ids;
        const entries = listed.map(({ id, title }) => choice(maplace, id, title ?? id));
        choices.replaceChildren(choice(maplace, "", "Fit all"), ...entries);
      }
      const selected = maplace.getSnapshot().selectedId ?? "";
      for (const radio of choices.querySelectorAll("input"))
        radio.checked = radio.value === selected;
    };
    render();
    maplace.subscribe(render);
    return fieldset;
  }

  const maplace = Maplace.createMaplace({ locations });
  const adapter = Maplace.createGoogleAdapter({ apiKey: "YOUR_KEY" });
  maplace.attach(adapter, "#custom-list-script-map");
  adapter.mountControl(checksMenu(maplace, "Choose a location:"), "top-right");
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/custom-list/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #custom-list-maplibre-vanilla-map { height: 24rem; }
  #custom-list-maplibre-vanilla-map fieldset { border: 0; padding: 0; }
  #custom-list-maplibre-vanilla-map fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<div id="custom-list-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/custom-list/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import { createMaplace, type Location, listedLocations, type Maplace } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";

const locations: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
  { id: "york", lat: 53.9591, lng: -1.0815, title: "York" },
  { id: "bath", lat: 51.3811, lng: -2.359, title: "Bath" },
  { id: "oxford", lat: 51.752, lng: -1.2577, title: "Oxford" },
  { id: "cambridge", lat: 52.2053, lng: 0.1218, title: "Cambridge", listed: false },
];

/** A radio choosing `id`, or fitting every location when `id` is empty. */
function choice(maplace: Maplace, id: string, title: string): HTMLLabelElement {
  const radio = document.createElement("input");
  radio.type = "radio";
  radio.name = "custom-list-maplibre-vanilla-choice";
  radio.value = id;
  radio.addEventListener("change", () => {
    maplace.select(id || undefined);
    if (!id) maplace.fitAll();
  });
  const label = document.createElement("label");
  label.append(radio, ` ${title}`);
  return label;
}

/**
 * A list of your own: a radio per location Maplace.js's lists would list, and one to fit them all.
 * The choices are made again when those change; the selection is checked.
 */
function checksMenu(maplace: Maplace, heading: string): HTMLFieldSetElement {
  const fieldset = document.createElement("fieldset");
  const legend = document.createElement("legend");
  legend.textContent = heading;
  const choices = document.createElement("div");
  fieldset.append(legend, choices);
  let listedIds: string | undefined;
  const render = () => {
    const listed = listedLocations(maplace.getSnapshot());
    const ids = listed.map(({ id }) => id).join();
    if (ids !== listedIds) {
      listedIds = ids;
      const entries = listed.map(({ id, title }) => choice(maplace, id, title ?? id));
      choices.replaceChildren(choice(maplace, "", "Fit all"), ...entries);
    }
    const selected = maplace.getSnapshot().selectedId ?? "";
    for (const radio of choices.querySelectorAll("input")) radio.checked = radio.value === selected;
  };
  render();
  maplace.subscribe(render);
  return fieldset;
}

const maplace = createMaplace({ locations });
const adapter = createMapLibreAdapter();
maplace.attach(adapter, "#custom-list-maplibre-vanilla-map");
adapter.mountControl(checksMenu(maplace, "Choose a location:"), "top-right");
```

### Bundler on Google

`packages/maplace/examples/custom-list/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #custom-list-vanilla-map { height: 24rem; }
  #custom-list-vanilla-map fieldset { border: 0; padding: 0; }
  #custom-list-vanilla-map fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<div id="custom-list-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/custom-list/vanilla.ts`

```ts
import { createMaplace, type Location, listedLocations, type Maplace } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";

const locations: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
  { id: "york", lat: 53.9591, lng: -1.0815, title: "York" },
  { id: "bath", lat: 51.3811, lng: -2.359, title: "Bath" },
  { id: "oxford", lat: 51.752, lng: -1.2577, title: "Oxford" },
  { id: "cambridge", lat: 52.2053, lng: 0.1218, title: "Cambridge", listed: false },
];

/** A radio choosing `id`, or fitting every location when `id` is empty. */
function choice(maplace: Maplace, id: string, title: string): HTMLLabelElement {
  const radio = document.createElement("input");
  radio.type = "radio";
  radio.name = "custom-list-vanilla-choice";
  radio.value = id;
  radio.addEventListener("change", () => {
    maplace.select(id || undefined);
    if (!id) maplace.fitAll();
  });
  const label = document.createElement("label");
  label.append(radio, ` ${title}`);
  return label;
}

/**
 * A list of your own: a radio per location Maplace.js's lists would list, and one to fit them all.
 * The choices are made again when those change; the selection is checked.
 */
function checksMenu(maplace: Maplace, heading: string): HTMLFieldSetElement {
  const fieldset = document.createElement("fieldset");
  const legend = document.createElement("legend");
  legend.textContent = heading;
  const choices = document.createElement("div");
  fieldset.append(legend, choices);
  let listedIds: string | undefined;
  const render = () => {
    const listed = listedLocations(maplace.getSnapshot());
    const ids = listed.map(({ id }) => id).join();
    if (ids !== listedIds) {
      listedIds = ids;
      const entries = listed.map(({ id, title }) => choice(maplace, id, title ?? id));
      choices.replaceChildren(choice(maplace, "", "Fit all"), ...entries);
    }
    const selected = maplace.getSnapshot().selectedId ?? "";
    for (const radio of choices.querySelectorAll("input")) radio.checked = radio.value === selected;
  };
  render();
  maplace.subscribe(render);
  return fieldset;
}

const maplace = createMaplace({ locations });
const adapter = createGoogleAdapter();
maplace.attach(adapter, "#custom-list-vanilla-map");
adapter.mountControl(checksMenu(maplace, "Choose a location:"), "top-right");
```

### React on MapLibre

`packages/maplace/examples/custom-list/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #custom-list-maplibre-react-root .map { height: 24rem; }
  #custom-list-maplibre-react-root fieldset { border: 0; padding: 0; }
  #custom-list-maplibre-react-root fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<div id="custom-list-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/custom-list/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import { type Location, listedLocations } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { MapControl, MaplaceMap, MaplaceProvider, useMaplace } from "@maplacejs/maplace/react";
import { StrictMode, useSyncExternalStore } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
  { id: "york", lat: 53.9591, lng: -1.0815, title: "York" },
  { id: "bath", lat: 51.3811, lng: -2.359, title: "Bath" },
  { id: "oxford", lat: 51.752, lng: -1.2577, title: "Oxford" },
  { id: "cambridge", lat: 52.2053, lng: 0.1218, title: "Cambridge", listed: false },
];

/**
 * A list of your own: a radio per location Maplace.js's lists would list, and one to fit them all;
 * the selection is checked.
 */
function ChecksMenu({ heading }: { readonly heading: string }) {
  const maplace = useMaplace();
  const snapshot = useSyncExternalStore(maplace.subscribe, maplace.getSnapshot);
  const choose = (id: string) => {
    maplace.select(id || undefined);
    if (!id) maplace.fitAll();
  };
  const choices = [{ id: "", title: "Fit all" }, ...listedLocations(snapshot)];
  return (
    <fieldset>
      <legend>{heading}</legend>
      <div>
        {choices.map(({ id, title }) => (
          <label key={id}>
            <input
              type="radio"
              name="custom-list-maplibre-react-choice"
              value={id}
              checked={(snapshot.selectedId ?? "") === id}
              onChange={() => choose(id)}
            />{" "}
            {title ?? id}
          </label>
        ))}
      </div>
    </fieldset>
  );
}

function CustomList() {
  return (
    <MaplaceProvider locations={cities}>
      <MaplaceMap createAdapter={createMapLibreAdapter} className="map">
        <MapControl position="top-right">
          <ChecksMenu heading="Choose a location:" />
        </MapControl>
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("custom-list-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <CustomList />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/custom-list/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #custom-list-react-root .map { height: 24rem; }
  #custom-list-react-root fieldset { border: 0; padding: 0; }
  #custom-list-react-root fieldset label { display: inline-block; margin-right: 0.75rem; }
</style>
<div id="custom-list-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/custom-list/react.tsx`

```tsx
import { type Location, listedLocations } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { MapControl, MaplaceMap, MaplaceProvider, useMaplace } from "@maplacejs/maplace/react";
import { StrictMode, useSyncExternalStore } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London" },
  { id: "york", lat: 53.9591, lng: -1.0815, title: "York" },
  { id: "bath", lat: 51.3811, lng: -2.359, title: "Bath" },
  { id: "oxford", lat: 51.752, lng: -1.2577, title: "Oxford" },
  { id: "cambridge", lat: 52.2053, lng: 0.1218, title: "Cambridge", listed: false },
];

/**
 * A list of your own: a radio per location Maplace.js's lists would list, and one to fit them all;
 * the selection is checked.
 */
function ChecksMenu({ heading }: { readonly heading: string }) {
  const maplace = useMaplace();
  const snapshot = useSyncExternalStore(maplace.subscribe, maplace.getSnapshot);
  const choose = (id: string) => {
    maplace.select(id || undefined);
    if (!id) maplace.fitAll();
  };
  const choices = [{ id: "", title: "Fit all" }, ...listedLocations(snapshot)];
  return (
    <fieldset>
      <legend>{heading}</legend>
      <div>
        {choices.map(({ id, title }) => (
          <label key={id}>
            <input
              type="radio"
              name="custom-list-react-choice"
              value={id}
              checked={(snapshot.selectedId ?? "") === id}
              onChange={() => choose(id)}
            />{" "}
            {title ?? id}
          </label>
        ))}
      </div>
    </fieldset>
  );
}

function CustomList() {
  return (
    <MaplaceProvider locations={cities}>
      <MaplaceMap createAdapter={createGoogleAdapter} className="map">
        <MapControl position="top-right">
          <ChecksMenu heading="Choose a location:" />
        </MapControl>
      </MaplaceMap>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("custom-list-react-root") as HTMLElement).render(
  <StrictMode>
    <CustomList />
  </StrictMode>,
);
```

## Tabs

The list outside the map; a details panel follows the selection.

The list leaves the map and becomes a row of tabs above it, with a panel under them that follows the selection.

- **Try it**: choose a tab and the map goes there, the panel saying a line about it; picking a pin does the same to the tabs. It starts on London.
- **HTML**: `list` and `selected-id` on `<maplace-map>` ([Map attributes](/element/#map-attributes)), the page's CSS drawing the list as tabs through its `role="listbox"` and `role="option"`, and a `maplace-selectionchange` listener filling the panel ([Events](/element/#events)).
- **Script** and **Bundler**: `selectedId` in the map's options and `list: { container }` to mount the list on a node of yours ([Options](/store/#options), [List view options](/store/#list-view-options)), and a `selectionChange` listener ([Events](/store/#events)).
- **React**: `defaultSelectedId` on `<MaplaceProvider>`, `<LocationList />` outside the `<MaplaceMap>`, and a component reading the selection with [`useMaplace()`](/react/#usemaplace).


### HTML on MapLibre

`packages/maplace/examples/tabs/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- The list sits outside the map, styled as tabs above it, starting on the first place; the chosen tab's details sit right below the tabs, above the map, and follow the selection. -->
<style>
  #tabs-maplibre-map { flex-direction: column; }
  #tabs-maplibre-map > [role="listbox"] { order: -2; display: flex; flex: none; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-maplibre-map > [role="listbox"] > [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-maplibre-map > [role="listbox"] > [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-maplibre-map > #tabs-maplibre-details { order: -1; padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<maplace-map id="tabs-maplibre-map" list selected-id="london">
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London" zoom="6"></maplace-location>
  <maplace-location location-id="edinburgh" lat="55.9533" lng="-3.1883" title="Edinburgh" zoom="6"></maplace-location>
  <aside id="tabs-maplibre-details"></aside>
</maplace-map>
<script>
  const tabsMapLibreNotes = { london: 'Capital of the United Kingdom.', edinburgh: 'Capital of Scotland, home of the Fringe arts festival.' };
  const tabsMapLibreMap = document.getElementById('tabs-maplibre-map');
  function showTabsMapLibreNote(id) {
    document.getElementById('tabs-maplibre-details').textContent = tabsMapLibreNotes[id] ?? '';
  }
  showTabsMapLibreNote(tabsMapLibreMap.maplace.getSnapshot().selectedId);
  tabsMapLibreMap.addEventListener('maplace-selectionchange', (event) => showTabsMapLibreNote(event.detail.id));
</script>
```

### HTML on Google

`packages/maplace/examples/tabs/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- The list sits outside the map, styled as tabs above it, starting on the first place; the chosen tab's details sit right below the tabs, above the map, and follow the selection. -->
<style>
  #tabs-map { flex-direction: column; }
  #tabs-map > [role="listbox"] { order: -2; display: flex; flex: none; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-map > [role="listbox"] > [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-map > [role="listbox"] > [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-map > #tabs-details { order: -1; padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<maplace-map id="tabs-map" api-key="YOUR_KEY" list selected-id="london">
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London" zoom="6"></maplace-location>
  <maplace-location location-id="edinburgh" lat="55.9533" lng="-3.1883" title="Edinburgh" zoom="6"></maplace-location>
  <aside id="tabs-details"></aside>
</maplace-map>
<script>
  const tabsNotes = { london: 'Capital of the United Kingdom.', edinburgh: 'Capital of Scotland, home of the Fringe arts festival.' };
  const tabsMap = document.getElementById('tabs-map');
  function showTabsNote(id) {
    document.getElementById('tabs-details').textContent = tabsNotes[id] ?? '';
  }
  showTabsNote(tabsMap.maplace.getSnapshot().selectedId);
  tabsMap.addEventListener('maplace-selectionchange', (event) => showTabsNote(event.detail.id));
</script>
```

### Script on MapLibre

`packages/maplace/examples/tabs/maplibre/script.html`

```html
<!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, what the tabs, their details and the map mount on, and the map made with Maplace. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
  #tabs-maplibre-script-panel { display: flex; flex-direction: column; height: 24rem; }
  #tabs-maplibre-script-map { flex: 1 1 auto; min-height: 0; }
  #tabs-maplibre-script-list [role="listbox"] { display: flex; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-maplibre-script-list [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-maplibre-script-list [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-maplibre-script-details { padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<div id="tabs-maplibre-script-panel">
  <div id="tabs-maplibre-script-list"></div>
  <aside id="tabs-maplibre-script-details"></aside>
  <div id="tabs-maplibre-script-map"></div>
</div>
<script type="module">
  const notes = {
    london: "Capital of the United Kingdom.",
    edinburgh: "Capital of Scotland, home of the Fringe arts festival.",
  };
  const maplace = Maplace.createMapLibreMap("#tabs-maplibre-script-map", {
    selectedId: "london",
    locations: [
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London", zoom: 6 },
      { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", zoom: 6 },
    ],
    list: { container: "#tabs-maplibre-script-list" },
  });

  const details = document.querySelector("#tabs-maplibre-script-details");
  showNote(maplace.getSnapshot().selectedId);
  maplace.on("selectionChange", ({ id }) => showNote(id));

  /** The chosen tab's details, in the panel below the tabs. */
  function showNote(id) {
    if (details) details.textContent = id === undefined ? "" : (notes[id] ?? "");
  }
</script>
```

### Script on Google

`packages/maplace/examples/tabs/script.html`

```html
<!doctype html>
<!-- A page of your own script: the CDN script, what the tabs, their details and the map mount on, and the map made with Maplace, which adds Maps JS with your key. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
  #tabs-script-panel { display: flex; flex-direction: column; height: 24rem; }
  #tabs-script-map { flex: 1 1 auto; min-height: 0; }
  #tabs-script-list [role="listbox"] { display: flex; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-script-list [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-script-list [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-script-details { padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<div id="tabs-script-panel">
  <div id="tabs-script-list"></div>
  <aside id="tabs-script-details"></aside>
  <div id="tabs-script-map"></div>
</div>
<script type="module">
  const notes = {
    london: "Capital of the United Kingdom.",
    edinburgh: "Capital of Scotland, home of the Fringe arts festival.",
  };
  const maplace = Maplace.createGoogleMap("#tabs-script-map", {
    apiKey: "YOUR_KEY",
    selectedId: "london",
    locations: [
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London", zoom: 6 },
      { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", zoom: 6 },
    ],
    list: { container: "#tabs-script-list" },
  });

  const details = document.querySelector("#tabs-script-details");
  showNote(maplace.getSnapshot().selectedId);
  maplace.on("selectionChange", ({ id }) => showNote(id));

  /** The chosen tab's details, in the panel below the tabs. */
  function showNote(id) {
    if (details) details.textContent = id === undefined ? "" : (notes[id] ?? "");
  }
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/tabs/maplibre/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #tabs-maplibre-vanilla-panel { display: flex; flex-direction: column; height: 24rem; }
  #tabs-maplibre-vanilla-map { flex: 1 1 auto; min-height: 0; }
  #tabs-maplibre-vanilla-list [role="listbox"] { display: flex; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-maplibre-vanilla-list [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-maplibre-vanilla-list [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-maplibre-vanilla-details { padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<div id="tabs-maplibre-vanilla-panel">
  <div id="tabs-maplibre-vanilla-list"></div>
  <aside id="tabs-maplibre-vanilla-details"></aside>
  <div id="tabs-maplibre-vanilla-map"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/tabs/maplibre/vanilla.ts`

```ts
import "maplibre-gl/dist/maplibre-gl.css";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";

const notes: Readonly<Record<string, string>> = {
  london: "Capital of the United Kingdom.",
  edinburgh: "Capital of Scotland, home of the Fringe arts festival.",
};
const maplace = createMapLibreMap("#tabs-maplibre-vanilla-map", {
  selectedId: "london",
  locations: [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London", zoom: 6 },
    { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", zoom: 6 },
  ],
  list: { container: "#tabs-maplibre-vanilla-list" },
});

const details = document.querySelector("#tabs-maplibre-vanilla-details");
showNote(maplace.getSnapshot().selectedId);
maplace.on("selectionChange", ({ id }) => showNote(id));

/** The chosen tab's details, in the panel below the tabs. */
function showNote(id: string | undefined): void {
  if (details) details.textContent = id === undefined ? "" : (notes[id] ?? "");
}
```

### Bundler on Google

`packages/maplace/examples/tabs/vanilla.html`

```html
<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #tabs-vanilla-panel { display: flex; flex-direction: column; height: 24rem; }
  #tabs-vanilla-map { flex: 1 1 auto; min-height: 0; }
  #tabs-vanilla-list [role="listbox"] { display: flex; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-vanilla-list [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-vanilla-list [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-vanilla-details { padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<div id="tabs-vanilla-panel">
  <div id="tabs-vanilla-list"></div>
  <aside id="tabs-vanilla-details"></aside>
  <div id="tabs-vanilla-map"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/tabs/vanilla.ts`

```ts
import { createGoogleMap } from "@maplacejs/maplace/google";

const notes: Readonly<Record<string, string>> = {
  london: "Capital of the United Kingdom.",
  edinburgh: "Capital of Scotland, home of the Fringe arts festival.",
};
const maplace = createGoogleMap("#tabs-vanilla-map", {
  selectedId: "london",
  locations: [
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London", zoom: 6 },
    { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", zoom: 6 },
  ],
  list: { container: "#tabs-vanilla-list" },
});

const details = document.querySelector("#tabs-vanilla-details");
showNote(maplace.getSnapshot().selectedId);
maplace.on("selectionChange", ({ id }) => showNote(id));

/** The chosen tab's details, in the panel below the tabs. */
function showNote(id: string | undefined): void {
  if (details) details.textContent = id === undefined ? "" : (notes[id] ?? "");
}
```

### React on MapLibre

`packages/maplace/examples/tabs/maplibre/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
  #tabs-maplibre-react-root .panel { display: flex; flex-direction: column; height: 24rem; }
  #tabs-maplibre-react-root .map { flex: 1 1 auto; min-height: 0; }
  #tabs-maplibre-react-root [role="listbox"] { display: flex; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-maplibre-react-root [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-maplibre-react-root [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-maplibre-react-root aside { padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<div id="tabs-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/tabs/maplibre/react.tsx`

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { LocationList, MaplaceMap, MaplaceProvider, useMaplace } from "@maplacejs/maplace/react";
import { StrictMode, useSyncExternalStore } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London", zoom: 6 },
  { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", zoom: 6 },
];
const notes: Readonly<Record<string, string>> = {
  london: "Capital of the United Kingdom.",
  edinburgh: "Capital of Scotland, home of the Fringe arts festival.",
};

const noteOf = (id: string | undefined) => (id === undefined ? "" : (notes[id] ?? ""));

/** The chosen place's note, read from the store: the selection it starts on, and every one after. */
function TabDetails() {
  const maplace = useMaplace();
  const selectedId = useSyncExternalStore(
    maplace.subscribe,
    () => maplace.getSnapshot().selectedId,
  );
  return <aside>{noteOf(selectedId)}</aside>;
}

function Tabs() {
  return (
    <MaplaceProvider locations={cities} defaultSelectedId="london">
      <div className="panel">
        <LocationList />
        <TabDetails />
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("tabs-maplibre-react-root") as HTMLElement).render(
  <StrictMode>
    <Tabs />
  </StrictMode>,
);
```

### React on Google

`packages/maplace/examples/tabs/react.html`

```html
<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->
<script>
  (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
    key: "YOUR_KEY",
    v: "weekly",
  });
</script>
<style>
  #tabs-react-root .panel { display: flex; flex-direction: column; height: 24rem; }
  #tabs-react-root .map { flex: 1 1 auto; min-height: 0; }
  #tabs-react-root [role="listbox"] { display: flex; gap: 0.25rem; padding: 0.5rem 0.75rem 0; box-shadow: inset 0 -1px color-mix(in srgb, currentColor 25%, transparent); }
  #tabs-react-root [role="option"] { padding: 0.5rem 1rem; border: 1px solid transparent; border-bottom: 0; border-radius: 0.5rem 0.5rem 0 0; }
  #tabs-react-root [aria-selected="true"] { position: relative; border-color: color-mix(in srgb, currentColor 25%, transparent); background: Canvas; font-weight: 600; }
  #tabs-react-root aside { padding: 0.75rem 1.25rem 1rem; line-height: 1.5; }
</style>
<div id="tabs-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/tabs/react.tsx`

```tsx
import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { LocationList, MaplaceMap, MaplaceProvider, useMaplace } from "@maplacejs/maplace/react";
import { StrictMode, useSyncExternalStore } from "react";
import { createRoot } from "react-dom/client";

const cities: Location[] = [
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London", zoom: 6 },
  { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", zoom: 6 },
];
const notes: Readonly<Record<string, string>> = {
  london: "Capital of the United Kingdom.",
  edinburgh: "Capital of Scotland, home of the Fringe arts festival.",
};

const noteOf = (id: string | undefined) => (id === undefined ? "" : (notes[id] ?? ""));

/** The chosen place's note, read from the store: the selection it starts on, and every one after. */
function TabDetails() {
  const maplace = useMaplace();
  const selectedId = useSyncExternalStore(
    maplace.subscribe,
    () => maplace.getSnapshot().selectedId,
  );
  return <aside>{noteOf(selectedId)}</aside>;
}

function Tabs() {
  return (
    <MaplaceProvider locations={cities} defaultSelectedId="london">
      <div className="panel">
        <LocationList />
        <TabDetails />
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
      </div>
    </MaplaceProvider>
  );
}

createRoot(document.getElementById("tabs-react-root") as HTMLElement).render(
  <StrictMode>
    <Tabs />
  </StrictMode>,
);
```
