# List beside the map

The list outside the map, where it goes by default, grouped by region, with an entry for all.

## How it works

The list where a list goes unless you give it a corner: beside the map, under it on a phone. Its places sit under their regions, after a first entry that fits them all. Choose an entry and the map goes there; choose a place on the map and its entry is selected.

- **HTML**: `list` on `<maplace-map>`, with `list-heading`, `fit-all` and `fit-all-label` ([Map attributes](/element/#map-attributes)), and `group` on each `<maplace-location>` for its heading. `list-position` is `outside` unless you name a corner.
- **Script** and **Bundler**: `list: { container, heading, fitAll: true, fitAllLabel }` in the map's options, the list mounted on a node of yours beside the map's ([List view options](/store/#list-view-options)), and `group` on a location ([Every location](/locations/#every-location)).
- **React**: `<LocationList heading fitAll fitAllLabel />` beside the `<MaplaceMap>`, not inside it ([`<LocationList>`](/react/#locationlist)).

## Code

### HTML on MapLibre

`packages/maplace/examples/side-list/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) {
    #side-list-maplibre-map { height: 36rem; }
    #side-list-maplibre-map > .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<!-- A list beside the map, where a list goes unless it is given a corner: the places under their regions, and a first entry that fits them all. -->
<maplace-map id="side-list-maplibre-map" list list-heading="Cities" fit-all fit-all-label="All cities">
  <maplace-location location-id="edinburgh" lat="55.9533" lng="-3.1883" title="Edinburgh" group="North"></maplace-location>
  <maplace-location location-id="glasgow" lat="55.8642" lng="-4.2518" title="Glasgow" group="North"></maplace-location>
  <maplace-location location-id="belfast" lat="54.5973" lng="-5.9301" title="Belfast" group="North"></maplace-location>
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London" group="South"></maplace-location>
  <maplace-location location-id="bristol" lat="51.4545" lng="-2.5879" title="Bristol" group="South"></maplace-location>
  <maplace-location location-id="cardiff" lat="51.4816" lng="-3.1791" title="Cardiff" group="South"></maplace-location>
</maplace-map>
```

### HTML on Google

`packages/maplace/examples/side-list/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) {
    #side-list-map { height: 36rem; }
    #side-list-map > .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<!-- A list beside the map, where a list goes unless it is given a corner: the places under their regions, and a first entry that fits them all. -->
<maplace-map id="side-list-map" api-key="YOUR_KEY" list list-heading="Cities" fit-all fit-all-label="All cities">
  <maplace-location location-id="edinburgh" lat="55.9533" lng="-3.1883" title="Edinburgh" group="North"></maplace-location>
  <maplace-location location-id="glasgow" lat="55.8642" lng="-4.2518" title="Glasgow" group="North"></maplace-location>
  <maplace-location location-id="belfast" lat="54.5973" lng="-5.9301" title="Belfast" group="North"></maplace-location>
  <maplace-location location-id="london" lat="51.5074" lng="-0.1278" title="London" group="South"></maplace-location>
  <maplace-location location-id="bristol" lat="51.4545" lng="-2.5879" title="Bristol" group="South"></maplace-location>
  <maplace-location location-id="cardiff" lat="51.4816" lng="-3.1791" title="Cardiff" group="South"></maplace-location>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/side-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 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>
  #side-list-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #side-list-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #side-list-maplibre-script-list { display: contents; }
  #side-list-maplibre-script-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #side-list-maplibre-script-map-and-list { flex-direction: column; height: 36rem; }
    #side-list-maplibre-script-list .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="side-list-maplibre-script-map-and-list">
  <div id="side-list-maplibre-script-map"></div>
  <div id="side-list-maplibre-script-list"></div>
</div>
<script type="module">
  Maplace.createMapLibreMap("#side-list-maplibre-script-map", {
    locations: [
      { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
      { id: "glasgow", lat: 55.8642, lng: -4.2518, title: "Glasgow", group: "North" },
      { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
      { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol", group: "South" },
      { id: "cardiff", lat: 51.4816, lng: -3.1791, title: "Cardiff", group: "South" },
    ],
    list: { container: "#side-list-maplibre-script-list", heading: "Cities", fitAll: true, fitAllLabel: "All cities" },
  });
</script>
```

### Script on Google

`packages/maplace/examples/side-list/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>
  #side-list-script-map-and-list { display: flex; height: 24rem; }
  #side-list-script-map { flex: 1 1 auto; min-width: 0; }
  #side-list-script-list { display: contents; }
  #side-list-script-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #side-list-script-map-and-list { flex-direction: column; height: 36rem; }
    #side-list-script-list .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="side-list-script-map-and-list">
  <div id="side-list-script-map"></div>
  <div id="side-list-script-list"></div>
</div>
<script type="module">
  Maplace.createGoogleMap("#side-list-script-map", {
    apiKey: "YOUR_KEY",
    locations: [
      { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
      { id: "glasgow", lat: 55.8642, lng: -4.2518, title: "Glasgow", group: "North" },
      { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
      { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
      { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol", group: "South" },
      { id: "cardiff", lat: 51.4816, lng: -3.1791, title: "Cardiff", group: "South" },
    ],
    list: { container: "#side-list-script-list", heading: "Cities", fitAll: true, fitAllLabel: "All cities" },
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/side-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>
  #side-list-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #side-list-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #side-list-maplibre-vanilla-list { display: contents; }
  #side-list-maplibre-vanilla-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #side-list-maplibre-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #side-list-maplibre-vanilla-list .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="side-list-maplibre-vanilla-map-and-list">
  <div id="side-list-maplibre-vanilla-map"></div>
  <div id="side-list-maplibre-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

createMapLibreMap("#side-list-maplibre-vanilla-map", {
  locations: [
    { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
    { id: "glasgow", lat: 55.8642, lng: -4.2518, title: "Glasgow", group: "North" },
    { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
    { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol", group: "South" },
    { id: "cardiff", lat: 51.4816, lng: -3.1791, title: "Cardiff", group: "South" },
  ],
  list: {
    container: "#side-list-maplibre-vanilla-list",
    heading: "Cities",
    fitAll: true,
    fitAllLabel: "All cities",
  },
});
```

### Bundler on Google

`packages/maplace/examples/side-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>
  #side-list-vanilla-map-and-list { display: flex; height: 24rem; }
  #side-list-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #side-list-vanilla-list { display: contents; }
  #side-list-vanilla-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #side-list-vanilla-map-and-list { flex-direction: column; height: 36rem; }
    #side-list-vanilla-list .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="side-list-vanilla-map-and-list">
  <div id="side-list-vanilla-map"></div>
  <div id="side-list-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

createGoogleMap("#side-list-vanilla-map", {
  locations: [
    { id: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
    { id: "glasgow", lat: 55.8642, lng: -4.2518, title: "Glasgow", group: "North" },
    { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
    { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
    { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol", group: "South" },
    { id: "cardiff", lat: 51.4816, lng: -3.1791, title: "Cardiff", group: "South" },
  ],
  list: {
    container: "#side-list-vanilla-list",
    heading: "Cities",
    fitAll: true,
    fitAllLabel: "All cities",
  },
});
```

### React on MapLibre

`packages/maplace/examples/side-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>
  #side-list-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #side-list-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #side-list-maplibre-react-root .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #side-list-maplibre-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #side-list-maplibre-react-root .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="side-list-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/side-list/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: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
  { id: "glasgow", lat: 55.8642, lng: -4.2518, title: "Glasgow", group: "North" },
  { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
  { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol", group: "South" },
  { id: "cardiff", lat: 51.4816, lng: -3.1791, title: "Cardiff", group: "South" },
];

function SideList() {
  return (
    <MaplaceProvider locations={cities}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
        <LocationList heading="Cities" fitAll fitAllLabel="All cities" />
      </div>
    </MaplaceProvider>
  );
}

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

### React on Google

`packages/maplace/examples/side-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>
  #side-list-react-root .map-and-list { display: flex; height: 24rem; }
  #side-list-react-root .map { flex: 1 1 auto; min-width: 0; }
  #side-list-react-root .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, its half staying that size. */
  @media (width < 40rem) {
    #side-list-react-root .map-and-list { flex-direction: column; height: 36rem; }
    #side-list-react-root .maplace-list-view { flex: 0 0 50%; max-height: 50%; }
  }
</style>
<div id="side-list-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/side-list/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: "edinburgh", lat: 55.9533, lng: -3.1883, title: "Edinburgh", group: "North" },
  { id: "glasgow", lat: 55.8642, lng: -4.2518, title: "Glasgow", group: "North" },
  { id: "belfast", lat: 54.5973, lng: -5.9301, title: "Belfast", group: "North" },
  { id: "london", lat: 51.5074, lng: -0.1278, title: "London", group: "South" },
  { id: "bristol", lat: 51.4545, lng: -2.5879, title: "Bristol", group: "South" },
  { id: "cardiff", lat: 51.4816, lng: -3.1791, title: "Cardiff", group: "South" },
];

function SideList() {
  return (
    <MaplaceProvider locations={cities}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
        <LocationList heading="Cities" fitAll fitAllLabel="All cities" />
      </div>
    </MaplaceProvider>
  );
}

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