# Circles, lines and areas on Google Maps and MapLibre

Circles, polylines, great-circle flights and polygons in your own colours, with popups and markers on the same map. Circles, polylines and polygons can be made editable, each edit written back to your data.

Circles, lines (straight, bowed or on great circles) and areas in their own colours, some to edit, and all of them with markers on one map.

## Circles

Areas in their own colours, with popups; resize the third and see its radius.

Areas by radius in metres, each in its own colours, the first two with a popup, the centre selected at the start; the third resizes, its radius shown below the map as it changes.

- **Try it**: pick "Within 15 km" and it turns orange, its selected style, its popup opening. Drag the edge of "Change my size", which has neither, and the line below follows.
- **HTML**: `type="circle"`, `radius`, `shape-style`, `selected-style` and `editable` on `<maplace-location>`, a `<template>` inside each of the first two for its popup ([Location attributes](/element/#location-attributes)), `selected-id` on the map, and `maplace-locationedit` and `maplace-locationchange` listeners ([Events](/element/#events)).
- **Script** and **Bundler**: `type: "circle"`, `radius`, `style`, `selectedStyle`, `content` and `editable` on a location ([Circles](/locations/#circles), [Styles](/locations/#styles)), and `locationEdit` while dragging and `locationChange` once dropped ([Events](/store/#events)).
- **React**: the same circles, their text in `data` for `popupContent` on `<MaplaceMap>`, with `onLocationEdit` and `onLocationChange` on `<MaplaceProvider>` ([Event props](/react/#event-props)).


### HTML on MapLibre

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- Circles in their own colours, with popups, the centre selected at start; drag the third
     circle's edge and its radius shows below the map. -->
<maplace-map id="circles-maplibre-map" list selected-id="center">
  <maplace-location location-id="center" type="circle" lat="41.9028" lng="12.4964" radius="5000" title="Within 5 km"
    shape-style='{"stroke":"#1d4ed8","fill":"#3b82f6"}' selected-style='{"stroke":"#c2410c","fill":"#f97316"}'>
    <template><p>The historic centre, on foot.</p></template>
  </maplace-location>
  <maplace-location location-id="ring" type="circle" lat="41.9028" lng="12.4964" radius="15000" title="Within 15 km"
    shape-style='{"stroke":"#15803d","fill":"#22c55e"}' selected-style='{"stroke":"#c2410c","fill":"#f97316"}'>
    <template><p>Inside the ring road, by bike.</p></template>
  </maplace-location>
  <maplace-location location-id="resizable" type="circle" lat="41.8" lng="12.75" radius="8000" title="Change my size"
    editable shape-style='{"stroke":"#7c3aed","fill":"#a78bfa"}'></maplace-location>
</maplace-map>
<p><output id="circles-maplibre-radius">Radius: 8.0 km</output></p>
<script>
  function showCirclesMapLibreRadius(id, radius) {
    if (id !== 'resizable') return;
    document.getElementById('circles-maplibre-radius').textContent = `Radius: ${(radius / 1000).toFixed(1)} km`;
  }
  const circlesMapLibreMap = document.getElementById('circles-maplibre-map');
  circlesMapLibreMap.addEventListener('maplace-locationedit', (event) => {
    showCirclesMapLibreRadius(event.detail.location.id, event.detail.geometry.radius);
  });
  circlesMapLibreMap.addEventListener('maplace-locationchange', (event) => {
    showCirclesMapLibreRadius(event.detail.location.id, event.detail.location.radius);
  });
</script>
```

### HTML on Google

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- Circles in their own colours, with popups, the centre selected at start; drag the third
     circle's edge and its radius shows below the map. -->
<maplace-map id="circles-map" api-key="YOUR_KEY" list selected-id="center">
  <maplace-location location-id="center" type="circle" lat="41.9028" lng="12.4964" radius="5000" title="Within 5 km"
    shape-style='{"stroke":"#1d4ed8","fill":"#3b82f6"}' selected-style='{"stroke":"#c2410c","fill":"#f97316"}'>
    <template><p>The historic centre, on foot.</p></template>
  </maplace-location>
  <maplace-location location-id="ring" type="circle" lat="41.9028" lng="12.4964" radius="15000" title="Within 15 km"
    shape-style='{"stroke":"#15803d","fill":"#22c55e"}' selected-style='{"stroke":"#c2410c","fill":"#f97316"}'>
    <template><p>Inside the ring road, by bike.</p></template>
  </maplace-location>
  <maplace-location location-id="resizable" type="circle" lat="41.8" lng="12.75" radius="8000" title="Change my size"
    editable shape-style='{"stroke":"#7c3aed","fill":"#a78bfa"}'></maplace-location>
</maplace-map>
<p><output id="circles-radius">Radius: 8.0 km</output></p>
<script>
  function showCirclesRadius(id, radius) {
    if (id !== 'resizable') return;
    document.getElementById('circles-radius').textContent = `Radius: ${(radius / 1000).toFixed(1)} km`;
  }
  const circlesMap = document.getElementById('circles-map');
  circlesMap.addEventListener('maplace-locationedit', (event) => {
    showCirclesRadius(event.detail.location.id, event.detail.geometry.radius);
  });
  circlesMap.addEventListener('maplace-locationchange', (event) => {
    showCirclesRadius(event.detail.location.id, event.detail.location.radius);
  });
</script>
```

### Script on MapLibre

`packages/maplace/examples/circles/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, its list and the radius readout 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>
  #circles-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #circles-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #circles-maplibre-script-list { display: contents; }
  #circles-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) {
    #circles-maplibre-script-map-and-list { flex-direction: column; }
    #circles-maplibre-script-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="circles-maplibre-script-map-and-list">
  <div id="circles-maplibre-script-map"></div>
  <div id="circles-maplibre-script-list"></div>
</div>
<p><output id="circles-maplibre-script-radius">Radius: 8.0 km</output></p>
<script type="module">
  const center = { lat: 41.9028, lng: 12.4964 };
  const selectedStyle = { stroke: "#c2410c", fill: "#f97316" };
  const maplace = Maplace.createMapLibreMap("#circles-maplibre-script-map", {
    selectedId: "center",
    locations: [
      {
        id: "center",
        type: "circle",
        center,
        radius: 5_000,
        title: "Within 5 km",
        style: { stroke: "#1d4ed8", fill: "#3b82f6" },
        selectedStyle,
        content: () => popupOf("The historic centre, on foot."),
      },
      {
        id: "ring",
        type: "circle",
        center,
        radius: 15_000,
        title: "Within 15 km",
        style: { stroke: "#15803d", fill: "#22c55e" },
        selectedStyle,
        content: () => popupOf("Inside the ring road, by bike."),
      },
      {
        id: "resizable",
        type: "circle",
        center: { lat: 41.8, lng: 12.75 },
        radius: 8_000,
        title: "Change my size",
        editable: true,
        style: { stroke: "#7c3aed", fill: "#a78bfa" },
      },
    ],
    list: { container: "#circles-maplibre-script-list" },
  });

  maplace.on("locationEdit", ({ location, geometry }) => {
    if (geometry.type === "circle") showRadius(location.id, geometry.radius);
  });
  maplace.on("locationChange", ({ location }) => {
    if (location.type === "circle") showRadius(location.id, location.radius);
  });

  const readout = document.querySelector("#circles-maplibre-script-radius");
  /** The editable circle's radius, while it is resized and once it is. */
  function showRadius(id, radius) {
    if (readout && id === "resizable")
      readout.textContent = `Radius: ${(radius / 1000).toFixed(1)} km`;
  }

  /** A popup's content: a line about the area, under its title (the popup's heading). */
  function popupOf(about) {
    const text = document.createElement("p");
    text.textContent = about;
    return text;
  }
</script>
```

### Script on Google

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

```html
<!doctype html>
<!-- A page of your own script: the CDN script, what the map, its list and the radius readout 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>
  #circles-script-map-and-list { display: flex; height: 24rem; }
  #circles-script-map { flex: 1 1 auto; min-width: 0; }
  #circles-script-list { display: contents; }
  #circles-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) {
    #circles-script-map-and-list { flex-direction: column; }
    #circles-script-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="circles-script-map-and-list">
  <div id="circles-script-map"></div>
  <div id="circles-script-list"></div>
</div>
<p><output id="circles-script-radius">Radius: 8.0 km</output></p>
<script type="module">
  const center = { lat: 41.9028, lng: 12.4964 };
  const selectedStyle = { stroke: "#c2410c", fill: "#f97316" };
  const maplace = Maplace.createGoogleMap("#circles-script-map", {
    apiKey: "YOUR_KEY",
    selectedId: "center",
    locations: [
      {
        id: "center",
        type: "circle",
        center,
        radius: 5_000,
        title: "Within 5 km",
        style: { stroke: "#1d4ed8", fill: "#3b82f6" },
        selectedStyle,
        content: () => popupOf("The historic centre, on foot."),
      },
      {
        id: "ring",
        type: "circle",
        center,
        radius: 15_000,
        title: "Within 15 km",
        style: { stroke: "#15803d", fill: "#22c55e" },
        selectedStyle,
        content: () => popupOf("Inside the ring road, by bike."),
      },
      {
        id: "resizable",
        type: "circle",
        center: { lat: 41.8, lng: 12.75 },
        radius: 8_000,
        title: "Change my size",
        editable: true,
        style: { stroke: "#7c3aed", fill: "#a78bfa" },
      },
    ],
    list: { container: "#circles-script-list" },
  });

  maplace.on("locationEdit", ({ location, geometry }) => {
    if (geometry.type === "circle") showRadius(location.id, geometry.radius);
  });
  maplace.on("locationChange", ({ location }) => {
    if (location.type === "circle") showRadius(location.id, location.radius);
  });

  const readout = document.querySelector("#circles-script-radius");
  /** The editable circle's radius, while it is resized and once it is. */
  function showRadius(id, radius) {
    if (readout && id === "resizable")
      readout.textContent = `Radius: ${(radius / 1000).toFixed(1)} km`;
  }

  /** A popup's content: a line about the area, under its title (the popup's heading). */
  function popupOf(about) {
    const text = document.createElement("p");
    text.textContent = about;
    return text;
  }
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/circles/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>
  #circles-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #circles-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #circles-maplibre-vanilla-list { display: contents; }
  #circles-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) {
    #circles-maplibre-vanilla-map-and-list { flex-direction: column; }
    #circles-maplibre-vanilla-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="circles-maplibre-vanilla-map-and-list">
  <div id="circles-maplibre-vanilla-map"></div>
  <div id="circles-maplibre-vanilla-list"></div>
</div>
<p><output id="circles-maplibre-vanilla-radius">Radius: 8.0 km</output></p>
<script type="module" src="./vanilla.ts"></script>
```

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

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

const center = { lat: 41.9028, lng: 12.4964 };
const selectedStyle = { stroke: "#c2410c", fill: "#f97316" };
const maplace = createMapLibreMap("#circles-maplibre-vanilla-map", {
  selectedId: "center",
  locations: [
    {
      id: "center",
      type: "circle",
      center,
      radius: 5_000,
      title: "Within 5 km",
      style: { stroke: "#1d4ed8", fill: "#3b82f6" },
      selectedStyle,
      content: () => popupOf("The historic centre, on foot."),
    },
    {
      id: "ring",
      type: "circle",
      center,
      radius: 15_000,
      title: "Within 15 km",
      style: { stroke: "#15803d", fill: "#22c55e" },
      selectedStyle,
      content: () => popupOf("Inside the ring road, by bike."),
    },
    {
      id: "resizable",
      type: "circle",
      center: { lat: 41.8, lng: 12.75 },
      radius: 8_000,
      title: "Change my size",
      editable: true,
      style: { stroke: "#7c3aed", fill: "#a78bfa" },
    },
  ],
  list: { container: "#circles-maplibre-vanilla-list" },
});

maplace.on("locationEdit", ({ location, geometry }) => {
  if (geometry.type === "circle") showRadius(location.id, geometry.radius);
});
maplace.on("locationChange", ({ location }) => {
  if (location.type === "circle") showRadius(location.id, location.radius);
});

const readout = document.querySelector<HTMLOutputElement>("#circles-maplibre-vanilla-radius");
/** The editable circle's radius, while it is resized and once it is. */
function showRadius(id: string, radius: number): void {
  if (readout && id === "resizable")
    readout.textContent = `Radius: ${(radius / 1000).toFixed(1)} km`;
}

/** A popup's content: a line about the area, under its title (the popup's heading). */
function popupOf(about: string): HTMLParagraphElement {
  const text = document.createElement("p");
  text.textContent = about;
  return text;
}
```

### Bundler on Google

`packages/maplace/examples/circles/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>
  #circles-vanilla-map-and-list { display: flex; height: 24rem; }
  #circles-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #circles-vanilla-list { display: contents; }
  #circles-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) {
    #circles-vanilla-map-and-list { flex-direction: column; }
    #circles-vanilla-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="circles-vanilla-map-and-list">
  <div id="circles-vanilla-map"></div>
  <div id="circles-vanilla-list"></div>
</div>
<p><output id="circles-vanilla-radius">Radius: 8.0 km</output></p>
<script type="module" src="./vanilla.ts"></script>
```

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

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

const center = { lat: 41.9028, lng: 12.4964 };
const selectedStyle = { stroke: "#c2410c", fill: "#f97316" };
const maplace = createGoogleMap("#circles-vanilla-map", {
  selectedId: "center",
  locations: [
    {
      id: "center",
      type: "circle",
      center,
      radius: 5_000,
      title: "Within 5 km",
      style: { stroke: "#1d4ed8", fill: "#3b82f6" },
      selectedStyle,
      content: () => popupOf("The historic centre, on foot."),
    },
    {
      id: "ring",
      type: "circle",
      center,
      radius: 15_000,
      title: "Within 15 km",
      style: { stroke: "#15803d", fill: "#22c55e" },
      selectedStyle,
      content: () => popupOf("Inside the ring road, by bike."),
    },
    {
      id: "resizable",
      type: "circle",
      center: { lat: 41.8, lng: 12.75 },
      radius: 8_000,
      title: "Change my size",
      editable: true,
      style: { stroke: "#7c3aed", fill: "#a78bfa" },
    },
  ],
  list: { container: "#circles-vanilla-list" },
});

maplace.on("locationEdit", ({ location, geometry }) => {
  if (geometry.type === "circle") showRadius(location.id, geometry.radius);
});
maplace.on("locationChange", ({ location }) => {
  if (location.type === "circle") showRadius(location.id, location.radius);
});

const readout = document.querySelector<HTMLOutputElement>("#circles-vanilla-radius");
/** The editable circle's radius, while it is resized and once it is. */
function showRadius(id: string, radius: number): void {
  if (readout && id === "resizable")
    readout.textContent = `Radius: ${(radius / 1000).toFixed(1)} km`;
}

/** A popup's content: a line about the area, under its title (the popup's heading). */
function popupOf(about: string): HTMLParagraphElement {
  const text = document.createElement("p");
  text.textContent = about;
  return text;
}
```

### React on MapLibre

`packages/maplace/examples/circles/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>
  #circles-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #circles-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #circles-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) {
    #circles-maplibre-react-root .map-and-list { flex-direction: column; }
    #circles-maplibre-react-root [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="circles-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

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

```tsx
import "maplibre-gl/dist/maplibre-gl.css";
import type { Geometry, 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";

/** Your own fields, in each location's `data`. */
interface Area {
  readonly about: string;
}

const center = { lat: 41.9028, lng: 12.4964 };
const selectedStyle = { stroke: "#c2410c", fill: "#f97316" };
const circles: Location<Area>[] = [
  {
    id: "center",
    type: "circle",
    center,
    radius: 5_000,
    title: "Within 5 km",
    style: { stroke: "#1d4ed8", fill: "#3b82f6" },
    selectedStyle,
    data: { about: "The historic centre, on foot." },
  },
  {
    id: "ring",
    type: "circle",
    center,
    radius: 15_000,
    title: "Within 15 km",
    style: { stroke: "#15803d", fill: "#22c55e" },
    selectedStyle,
    data: { about: "Inside the ring road, by bike." },
  },
  {
    id: "resizable",
    type: "circle",
    center: { lat: 41.8, lng: 12.75 },
    radius: 8_000,
    title: "Change my size",
    editable: true,
    style: { stroke: "#7c3aed", fill: "#a78bfa" },
  },
];

// Outside the component, so a render of the page around it doesn't render every popup again.
const popupContent = ({ data }: Location<Area>) => (data ? <p>{data.about}</p> : null);

/** A circle's radius; other shapes have none. */
const radiusOf = (shape: Geometry | Location<Area>) =>
  "radius" in shape ? shape.radius : undefined;

function Circles() {
  const [radius, setRadius] = useState(8_000);
  // The editable circle's radius, while it is resized and once it is.
  const showRadius = (id: string, shape: Geometry | Location<Area>) => {
    const resized = radiusOf(shape);
    if (id === "resizable" && resized !== undefined) setRadius(resized);
  };
  return (
    <MaplaceProvider
      locations={circles}
      defaultSelectedId="center"
      onLocationEdit={({ location, geometry }) => showRadius(location.id, geometry)}
      onLocationChange={({ location }) => showRadius(location.id, location)}
    >
      <div className="map-and-list">
        <MaplaceMap
          createAdapter={createMapLibreAdapter}
          className="map"
          popupContent={popupContent}
        />
        <LocationList />
      </div>
      <p>
        <output>Radius: {(radius / 1000).toFixed(1)} km</output>
      </p>
    </MaplaceProvider>
  );
}

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

### React on Google

`packages/maplace/examples/circles/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>
  #circles-react-root .map-and-list { display: flex; height: 24rem; }
  #circles-react-root .map { flex: 1 1 auto; min-width: 0; }
  #circles-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) {
    #circles-react-root .map-and-list { flex-direction: column; }
    #circles-react-root [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="circles-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

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

```tsx
import type { Geometry, 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";

/** Your own fields, in each location's `data`. */
interface Area {
  readonly about: string;
}

const center = { lat: 41.9028, lng: 12.4964 };
const selectedStyle = { stroke: "#c2410c", fill: "#f97316" };
const circles: Location<Area>[] = [
  {
    id: "center",
    type: "circle",
    center,
    radius: 5_000,
    title: "Within 5 km",
    style: { stroke: "#1d4ed8", fill: "#3b82f6" },
    selectedStyle,
    data: { about: "The historic centre, on foot." },
  },
  {
    id: "ring",
    type: "circle",
    center,
    radius: 15_000,
    title: "Within 15 km",
    style: { stroke: "#15803d", fill: "#22c55e" },
    selectedStyle,
    data: { about: "Inside the ring road, by bike." },
  },
  {
    id: "resizable",
    type: "circle",
    center: { lat: 41.8, lng: 12.75 },
    radius: 8_000,
    title: "Change my size",
    editable: true,
    style: { stroke: "#7c3aed", fill: "#a78bfa" },
  },
];

// Outside the component, so a render of the page around it doesn't render every popup again.
const popupContent = ({ data }: Location<Area>) => (data ? <p>{data.about}</p> : null);

/** A circle's radius; other shapes have none. */
const radiusOf = (shape: Geometry | Location<Area>) =>
  "radius" in shape ? shape.radius : undefined;

function Circles() {
  const [radius, setRadius] = useState(8_000);
  // The editable circle's radius, while it is resized and once it is.
  const showRadius = (id: string, shape: Geometry | Location<Area>) => {
    const resized = radiusOf(shape);
    if (id === "resizable" && resized !== undefined) setRadius(resized);
  };
  return (
    <MaplaceProvider
      locations={circles}
      defaultSelectedId="center"
      onLocationEdit={({ location, geometry }) => showRadius(location.id, geometry)}
      onLocationChange={({ location }) => showRadius(location.id, location)}
    >
      <div className="map-and-list">
        <MaplaceMap
          createAdapter={createGoogleAdapter}
          className="map"
          popupContent={popupContent}
        />
        <LocationList />
      </div>
      <p>
        <output>Radius: {(radius / 1000).toFixed(1)} km</output>
      </p>
    </MaplaceProvider>
  );
}

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

## Editable polyline

A trail to edit, with places along it.

A trail you can edit, Cinque Terre's coastal path, with the villages along it as markers of their own and in the list beside the map.

- **Try it**: drag a point of the line, or the middle of a segment to add one. Pick a village for its popup. The line itself is listed too, as a location.
- **HTML**: a `<script type="application/json">` inside `<maplace-map>` holding the data, as a path takes more than an attribute ([Data](/element/#data)); `list` and `list-heading` on the map ([Map attributes](/element/#map-attributes)).
- **Script** and **Bundler**: `type: "polyline"`, `path` and `editable` on a location ([Polylines](/locations/#polylines)), and `list: { container, heading }` ([List view options](/store/#list-view-options)).
- **React**: the same locations on `<MaplaceProvider>`, and `<LocationList heading="Along the trail" />` beside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)).


### HTML on MapLibre

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- A trail to edit (drag a point, or the middle of a segment), Cinque Terre's coastal path, with
     the villages along it and a list beside the map under a heading, all from inline JSON. -->
<maplace-map list list-heading="Along the trail">
  <script type="application/json">
    [{ "id": "trail", "type": "polyline", "title": "Sentiero Azzurro", "editable": true,
       "path": [{ "lat": 44.0996, "lng": 9.7377 }, { "lat": 44.1066, "lng": 9.7285 }, { "lat": 44.1197, "lng": 9.7103 },
                { "lat": 44.1348, "lng": 9.6847 }, { "lat": 44.1462, "lng": 9.6548 }] },
     { "id": "manarola", "lat": 44.1066, "lng": 9.7285, "title": "Manarola", "content": "Its harbour, and the houses above it." },
     { "id": "corniglia", "lat": 44.1197, "lng": 9.7103, "title": "Corniglia", "content": "The village on the cliff top." },
     { "id": "vernazza", "lat": 44.1348, "lng": 9.6847, "title": "Vernazza", "content": "A harbour and its castle's tower." }]
  </script>
</maplace-map>
```

### HTML on Google

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- A trail to edit (drag a point, or the middle of a segment), Cinque Terre's coastal path, with
     the villages along it and a list beside the map under a heading, all from inline JSON. -->
<maplace-map api-key="YOUR_KEY" list list-heading="Along the trail">
  <script type="application/json">
    [{ "id": "trail", "type": "polyline", "title": "Sentiero Azzurro", "editable": true,
       "path": [{ "lat": 44.0996, "lng": 9.7377 }, { "lat": 44.1066, "lng": 9.7285 }, { "lat": 44.1197, "lng": 9.7103 },
                { "lat": 44.1348, "lng": 9.6847 }, { "lat": 44.1462, "lng": 9.6548 }] },
     { "id": "manarola", "lat": 44.1066, "lng": 9.7285, "title": "Manarola", "content": "Its harbour, and the houses above it." },
     { "id": "corniglia", "lat": 44.1197, "lng": 9.7103, "title": "Corniglia", "content": "The village on the cliff top." },
     { "id": "vernazza", "lat": 44.1348, "lng": 9.6847, "title": "Vernazza", "content": "A harbour and its castle's tower." }]
  </script>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/polyline/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>
  #polyline-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #polyline-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #polyline-maplibre-script-list { display: contents; }
  #polyline-maplibre-script-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #polyline-maplibre-script-map-and-list { flex-direction: column; }
    #polyline-maplibre-script-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="polyline-maplibre-script-map-and-list">
  <div id="polyline-maplibre-script-map"></div>
  <div id="polyline-maplibre-script-list"></div>
</div>
<script type="module">
  // Cinque Terre's coastal path, Riomaggiore to Monterosso, through the villages between.
  const path = [
    { lat: 44.0996, lng: 9.7377 },
    { lat: 44.1066, lng: 9.7285 },
    { lat: 44.1197, lng: 9.7103 },
    { lat: 44.1348, lng: 9.6847 },
    { lat: 44.1462, lng: 9.6548 },
  ];
  const locations = [
    // Editable: drag a point, or the middle of a segment.
    { id: "trail", type: "polyline", title: "Sentiero Azzurro", editable: true, path },
    {
      id: "manarola",
      lat: 44.1066,
      lng: 9.7285,
      title: "Manarola",
      content: "Its harbour, and the houses above it.",
    },
    {
      id: "corniglia",
      lat: 44.1197,
      lng: 9.7103,
      title: "Corniglia",
      content: "The village on the cliff top.",
    },
    {
      id: "vernazza",
      lat: 44.1348,
      lng: 9.6847,
      title: "Vernazza",
      content: "A harbour and its castle's tower.",
    },
  ];
  Maplace.createMapLibreMap("#polyline-maplibre-script-map", {
    locations,
    list: { container: "#polyline-maplibre-script-list", heading: "Along the trail" },
  });
</script>
```

### Script on Google

`packages/maplace/examples/polyline/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>
  #polyline-script-map-and-list { display: flex; height: 24rem; }
  #polyline-script-map { flex: 1 1 auto; min-width: 0; }
  #polyline-script-list { display: contents; }
  #polyline-script-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #polyline-script-map-and-list { flex-direction: column; }
    #polyline-script-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="polyline-script-map-and-list">
  <div id="polyline-script-map"></div>
  <div id="polyline-script-list"></div>
</div>
<script type="module">
  // Cinque Terre's coastal path, Riomaggiore to Monterosso, through the villages between.
  const path = [
    { lat: 44.0996, lng: 9.7377 },
    { lat: 44.1066, lng: 9.7285 },
    { lat: 44.1197, lng: 9.7103 },
    { lat: 44.1348, lng: 9.6847 },
    { lat: 44.1462, lng: 9.6548 },
  ];
  const locations = [
    // Editable: drag a point, or the middle of a segment.
    { id: "trail", type: "polyline", title: "Sentiero Azzurro", editable: true, path },
    {
      id: "manarola",
      lat: 44.1066,
      lng: 9.7285,
      title: "Manarola",
      content: "Its harbour, and the houses above it.",
    },
    {
      id: "corniglia",
      lat: 44.1197,
      lng: 9.7103,
      title: "Corniglia",
      content: "The village on the cliff top.",
    },
    {
      id: "vernazza",
      lat: 44.1348,
      lng: 9.6847,
      title: "Vernazza",
      content: "A harbour and its castle's tower.",
    },
  ];
  Maplace.createGoogleMap("#polyline-script-map", {
    apiKey: "YOUR_KEY",
    locations,
    list: { container: "#polyline-script-list", heading: "Along the trail" },
  });
</script>
```

### Bundler on MapLibre

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

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

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

// Cinque Terre's coastal path, Riomaggiore to Monterosso, through the villages between.
const path: LatLng[] = [
  { lat: 44.0996, lng: 9.7377 },
  { lat: 44.1066, lng: 9.7285 },
  { lat: 44.1197, lng: 9.7103 },
  { lat: 44.1348, lng: 9.6847 },
  { lat: 44.1462, lng: 9.6548 },
];
const locations: Location[] = [
  // Editable: drag a point, or the middle of a segment.
  { id: "trail", type: "polyline", title: "Sentiero Azzurro", editable: true, path },
  {
    id: "manarola",
    lat: 44.1066,
    lng: 9.7285,
    title: "Manarola",
    content: "Its harbour, and the houses above it.",
  },
  {
    id: "corniglia",
    lat: 44.1197,
    lng: 9.7103,
    title: "Corniglia",
    content: "The village on the cliff top.",
  },
  {
    id: "vernazza",
    lat: 44.1348,
    lng: 9.6847,
    title: "Vernazza",
    content: "A harbour and its castle's tower.",
  },
];
createMapLibreMap("#polyline-maplibre-vanilla-map", {
  locations,
  list: { container: "#polyline-maplibre-vanilla-list", heading: "Along the trail" },
});
```

### Bundler on Google

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

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

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

// Cinque Terre's coastal path, Riomaggiore to Monterosso, through the villages between.
const path: LatLng[] = [
  { lat: 44.0996, lng: 9.7377 },
  { lat: 44.1066, lng: 9.7285 },
  { lat: 44.1197, lng: 9.7103 },
  { lat: 44.1348, lng: 9.6847 },
  { lat: 44.1462, lng: 9.6548 },
];
const locations: Location[] = [
  // Editable: drag a point, or the middle of a segment.
  { id: "trail", type: "polyline", title: "Sentiero Azzurro", editable: true, path },
  {
    id: "manarola",
    lat: 44.1066,
    lng: 9.7285,
    title: "Manarola",
    content: "Its harbour, and the houses above it.",
  },
  {
    id: "corniglia",
    lat: 44.1197,
    lng: 9.7103,
    title: "Corniglia",
    content: "The village on the cliff top.",
  },
  {
    id: "vernazza",
    lat: 44.1348,
    lng: 9.6847,
    title: "Vernazza",
    content: "A harbour and its castle's tower.",
  },
];
createGoogleMap("#polyline-vanilla-map", {
  locations,
  list: { container: "#polyline-vanilla-list", heading: "Along the trail" },
});
```

### React on MapLibre

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

`packages/maplace/examples/polyline/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 trail: Location[] = [
  // Cinque Terre's coastal path, Riomaggiore to Monterosso, through the villages between.
  // Editable: drag a point, or the middle of a segment.
  {
    id: "trail",
    type: "polyline",
    title: "Sentiero Azzurro",
    editable: true,
    path: [
      { lat: 44.0996, lng: 9.7377 },
      { lat: 44.1066, lng: 9.7285 },
      { lat: 44.1197, lng: 9.7103 },
      { lat: 44.1348, lng: 9.6847 },
      { lat: 44.1462, lng: 9.6548 },
    ],
  },
  {
    id: "manarola",
    lat: 44.1066,
    lng: 9.7285,
    title: "Manarola",
    content: "Its harbour, and the houses above it.",
  },
  {
    id: "corniglia",
    lat: 44.1197,
    lng: 9.7103,
    title: "Corniglia",
    content: "The village on the cliff top.",
  },
  {
    id: "vernazza",
    lat: 44.1348,
    lng: 9.6847,
    title: "Vernazza",
    content: "A harbour and its castle's tower.",
  },
];

function Polyline() {
  return (
    <MaplaceProvider locations={trail}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
        <LocationList heading="Along the trail" />
      </div>
    </MaplaceProvider>
  );
}

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

### React on Google

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

`packages/maplace/examples/polyline/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 trail: Location[] = [
  // Cinque Terre's coastal path, Riomaggiore to Monterosso, through the villages between.
  // Editable: drag a point, or the middle of a segment.
  {
    id: "trail",
    type: "polyline",
    title: "Sentiero Azzurro",
    editable: true,
    path: [
      { lat: 44.0996, lng: 9.7377 },
      { lat: 44.1066, lng: 9.7285 },
      { lat: 44.1197, lng: 9.7103 },
      { lat: 44.1348, lng: 9.6847 },
      { lat: 44.1462, lng: 9.6548 },
    ],
  },
  {
    id: "manarola",
    lat: 44.1066,
    lng: 9.7285,
    title: "Manarola",
    content: "Its harbour, and the houses above it.",
  },
  {
    id: "corniglia",
    lat: 44.1197,
    lng: 9.7103,
    title: "Corniglia",
    content: "The village on the cliff top.",
  },
  {
    id: "vernazza",
    lat: 44.1348,
    lng: 9.6847,
    title: "Vernazza",
    content: "A harbour and its castle's tower.",
  },
];

function Polyline() {
  return (
    <MaplaceProvider locations={trail}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
        <LocationList heading="Along the trail" />
      </div>
    </MaplaceProvider>
  );
}

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

## Flights

Great circles from one city to eight, the scheduled ones dashed; slide the flight to New York along its way.

London's flights out, each along its great circle, the shortest way on the earth: a polyline of two points with `geodesic: true`, listed beside the map, while the cities and the plane are on the map only. The flights still scheduled are dashed, and the one to New York is in the air: drawn active, travelled as far as the slider says, with its plane there.

- **Try it**: pick a flight in the list and the map goes to it, drawn heavier; click a flight on the map and the list follows. London to Tokyo crosses the Arctic, as the plane does. Drag the slider: the flight to New York fades behind its plane as it goes; hover or pick another flight and it draws over the active one.
- **HTML**: a `<script type="application/json">` inside `<maplace-map>` holding the data, as a path takes more than an attribute ([Data](/element/#data)); `list` and `list-heading` on the map ([Map attributes](/element/#map-attributes)); and a few lines of script for the slider, once the map is ready (`maplace.whenReady()`), setting the flight's `progress` and the plane at `Maplace.pointAlong` through the element's `locations` property ([Properties and methods](/element/#properties-and-methods)).
- **The looks**: `strokeDash: "dashed"` in a flight's `style` ([Styles](/locations/#styles)); `active: true` and `progress` on the flight in the air, its travelled part faded unless `travelledStyle` says otherwise ([Polylines](/locations/#polylines)); the plane a marker at `pointAlong(flight, progress)` ([A point along a line](/locations/#a-point-along-a-line)), moved with every new set of locations.
- **Script** and **Bundler**: `type: "polyline"`, `path` and `geodesic` on each flight ([Curves and great circles](/locations/#curves-and-great-circles)), `listed: false` on each city ([Common fields](/locations/#every-location)), and `list: { container, heading }` ([List view options](/store/#list-view-options)).
- **React**: the same locations on `<MaplaceProvider>`, and `<LocationList heading="Flights from London" />` beside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)).
- **On MapLibre, a globe**: `globe` on the map (`globe: true` in the options; in React, `createAdapter={() => createMapLibreAdapter({ globe: true })}`) opens it as the earth, with a "Globe" toggle that flattens it ([Globe](/maplibre/#globe)). The globe shows London's half: turn it, or flatten it, to see every flight. Google's map has no globe.


### HTML on MapLibre

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- London's flights out, each along its great circle, the shortest way on the earth, from
     the hub to a city, listed beside the map, on a globe its toggle flattens, the cities and the plane on the map only.
     The ones still scheduled are dashed; the one to New York is in the air, active, travelled as
     far as the slider says, its plane there. -->
<style>
  #flights-maplibre-flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
</style>
<label id="flights-maplibre-flown">London → New York, flown
  <input id="flights-maplibre-flown-input" type="range" min="0" max="1" step="0.01" value="0.4">
</label>
<maplace-map id="flights-maplibre-map" list list-heading="Flights from London" globe>
  <script type="application/json">
    [{ "id": "london", "lat": 51.5074, "lng": -0.1278, "title": "London", "listed": false },
     { "id": "new-york", "lat": 40.7128, "lng": -74.006, "title": "New York", "listed": false },
     { "id": "sao-paulo", "lat": -23.5505, "lng": -46.6333, "title": "São Paulo", "listed": false },
     { "id": "cape-town", "lat": -33.9249, "lng": 18.4241, "title": "Cape Town", "listed": false },
     { "id": "dubai", "lat": 25.2048, "lng": 55.2708, "title": "Dubai", "listed": false },
     { "id": "mumbai", "lat": 19.076, "lng": 72.8777, "title": "Mumbai", "listed": false },
     { "id": "singapore", "lat": 1.3521, "lng": 103.8198, "title": "Singapore", "listed": false },
     { "id": "tokyo", "lat": 35.6895, "lng": 139.6917, "title": "Tokyo", "listed": false },
     { "id": "sydney", "lat": -33.8688, "lng": 151.2093, "title": "Sydney", "listed": false },
     { "id": "london-new-york", "type": "polyline", "title": "London → New York", "geodesic": true, "active": true, "progress": 0.4,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 40.7128, "lng": -74.006 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-sao-paulo", "type": "polyline", "title": "London → São Paulo", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": -23.5505, "lng": -46.6333 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-cape-town", "type": "polyline", "title": "London → Cape Town", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": -33.9249, "lng": 18.4241 }],
       "style": { "stroke": "#2563eb", "strokeDash": "dashed" } },
     { "id": "london-dubai", "type": "polyline", "title": "London → Dubai", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 25.2048, "lng": 55.2708 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-mumbai", "type": "polyline", "title": "London → Mumbai", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 19.076, "lng": 72.8777 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-singapore", "type": "polyline", "title": "London → Singapore", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 1.3521, "lng": 103.8198 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-tokyo", "type": "polyline", "title": "London → Tokyo", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 35.6895, "lng": 139.6917 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-sydney", "type": "polyline", "title": "London → Sydney", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": -33.8688, "lng": 151.2093 }],
       "style": { "stroke": "#2563eb", "strokeDash": "dashed" } }]
  </script>
</maplace-map>
<script type="module">
  // The slider flies the flight to New York: its progress, and the plane where that puts it.
  const map = document.getElementById("flights-maplibre-map");
  const flown = document.getElementById("flights-maplibre-flown-input");
  const plane = { id: "plane", title: "The plane to New York", listed: false,
    icon: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E" };
  // The flights reach the map as it opens, after this script runs.
  await map.maplace.whenReady();
  const locations = map.locations;
  function fly() {
    const progress = flown.valueAsNumber;
    const current = locations.map((location) =>
      location.id === "london-new-york" ? { ...location, progress } : location,
    );
    const inTheAir = current.find(({ id }) => id === "london-new-york");
    map.locations = [...current, { ...plane, ...Maplace.pointAlong(inTheAir, progress) }];
  }
  fly();
  flown.addEventListener("input", fly);
</script>
```

### HTML on Google

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- London's flights out, each along its great circle, the shortest way on the earth, from
     the hub to a city, listed beside the map, the cities and the plane on the map only.
     The ones still scheduled are dashed; the one to New York is in the air, active, travelled as
     far as the slider says, its plane there. -->
<style>
  #flights-flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
</style>
<label id="flights-flown">London → New York, flown
  <input id="flights-flown-input" type="range" min="0" max="1" step="0.01" value="0.4">
</label>
<maplace-map id="flights-map" api-key="YOUR_KEY" list list-heading="Flights from London">
  <script type="application/json">
    [{ "id": "london", "lat": 51.5074, "lng": -0.1278, "title": "London", "listed": false },
     { "id": "new-york", "lat": 40.7128, "lng": -74.006, "title": "New York", "listed": false },
     { "id": "sao-paulo", "lat": -23.5505, "lng": -46.6333, "title": "São Paulo", "listed": false },
     { "id": "cape-town", "lat": -33.9249, "lng": 18.4241, "title": "Cape Town", "listed": false },
     { "id": "dubai", "lat": 25.2048, "lng": 55.2708, "title": "Dubai", "listed": false },
     { "id": "mumbai", "lat": 19.076, "lng": 72.8777, "title": "Mumbai", "listed": false },
     { "id": "singapore", "lat": 1.3521, "lng": 103.8198, "title": "Singapore", "listed": false },
     { "id": "tokyo", "lat": 35.6895, "lng": 139.6917, "title": "Tokyo", "listed": false },
     { "id": "sydney", "lat": -33.8688, "lng": 151.2093, "title": "Sydney", "listed": false },
     { "id": "london-new-york", "type": "polyline", "title": "London → New York", "geodesic": true, "active": true, "progress": 0.4,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 40.7128, "lng": -74.006 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-sao-paulo", "type": "polyline", "title": "London → São Paulo", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": -23.5505, "lng": -46.6333 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-cape-town", "type": "polyline", "title": "London → Cape Town", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": -33.9249, "lng": 18.4241 }],
       "style": { "stroke": "#2563eb", "strokeDash": "dashed" } },
     { "id": "london-dubai", "type": "polyline", "title": "London → Dubai", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 25.2048, "lng": 55.2708 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-mumbai", "type": "polyline", "title": "London → Mumbai", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 19.076, "lng": 72.8777 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-singapore", "type": "polyline", "title": "London → Singapore", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 1.3521, "lng": 103.8198 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-tokyo", "type": "polyline", "title": "London → Tokyo", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": 35.6895, "lng": 139.6917 }],
       "style": { "stroke": "#2563eb" } },
     { "id": "london-sydney", "type": "polyline", "title": "London → Sydney", "geodesic": true,
       "path": [{ "lat": 51.5074, "lng": -0.1278 }, { "lat": -33.8688, "lng": 151.2093 }],
       "style": { "stroke": "#2563eb", "strokeDash": "dashed" } }]
  </script>
</maplace-map>
<script type="module">
  // The slider flies the flight to New York: its progress, and the plane where that puts it.
  const map = document.getElementById("flights-map");
  const flown = document.getElementById("flights-flown-input");
  const plane = { id: "plane", title: "The plane to New York", listed: false,
    icon: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E" };
  // The flights reach the map as it opens, after this script runs.
  await map.maplace.whenReady();
  const locations = map.locations;
  function fly() {
    const progress = flown.valueAsNumber;
    const current = locations.map((location) =>
      location.id === "london-new-york" ? { ...location, progress } : location,
    );
    const inTheAir = current.find(({ id }) => id === "london-new-york");
    map.locations = [...current, { ...plane, ...Maplace.pointAlong(inTheAir, progress) }];
  }
  fly();
  flown.addEventListener("input", fly);
</script>
```

### Script on MapLibre

`packages/maplace/examples/flights/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>
  #flights-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #flights-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #flights-maplibre-script-list { display: contents; }
  #flights-maplibre-script-list .maplace-list-view { flex: 0 1 16rem; }
  #flights-maplibre-script-flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #flights-maplibre-script-map-and-list { flex-direction: column; }
    #flights-maplibre-script-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<label id="flights-maplibre-script-flown">London → New York, flown
  <input id="flights-maplibre-script-flown-input" type="range" min="0" max="1" step="0.01" value="0.4">
</label>
<div id="flights-maplibre-script-map-and-list">
  <div id="flights-maplibre-script-map"></div>
  <div id="flights-maplibre-script-list"></div>
</div>
<script type="module">
  // London's flights out, each along its great circle, the shortest way on the earth, the ones
  // still scheduled dashed. The flight to New York is in the air: drawn active, travelled as far as
  // the slider says, with its plane there.
  const london = { lat: 51.5074, lng: -0.1278 };
  const newYork = { id: "new-york", name: "New York", lat: 40.7128, lng: -74.006 };
  const cities = [
    newYork,
    { id: "sao-paulo", name: "São Paulo", lat: -23.5505, lng: -46.6333 },
    { id: "cape-town", name: "Cape Town", lat: -33.9249, lng: 18.4241 },
    { id: "dubai", name: "Dubai", lat: 25.2048, lng: 55.2708 },
    { id: "mumbai", name: "Mumbai", lat: 19.076, lng: 72.8777 },
    { id: "singapore", name: "Singapore", lat: 1.3521, lng: 103.8198 },
    { id: "tokyo", name: "Tokyo", lat: 35.6895, lng: 139.6917 },
    { id: "sydney", name: "Sydney", lat: -33.8688, lng: 151.2093 },
  ];
  const scheduled = new Set(["cape-town", "sydney"]);
  /** A plane, nose up, as an image. */
  const plane =
    "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E";

  function flightTo({ id, name, lat, lng }) {
    return {
      id: `london-${id}`,
      type: "polyline",
      title: `London → ${name}`,
      path: [london, { lat, lng }],
      geodesic: true,
      style: scheduled.has(id) ? { stroke: "#2563eb", strokeDash: "dashed" } : { stroke: "#2563eb" },
    };
  }

  // Made once, so a move of the slider changes only the flight in the air and its plane.
  const places = [
    // The cities and the plane on the map only; the list holds the flights.
    { id: "london", ...london, title: "London", listed: false },
    ...cities.map(({ id, name, lat, lng }) => ({ id, lat, lng, title: name, listed: false })),
  ];
  const toNewYork = flightTo(newYork);
  const otherFlights = cities.slice(1).map(flightTo);

  /** The map's locations, the flight to New York `flown` (0 to 1) of the way there. */
  function flightsWith(flown) {
    const inTheAir = { ...toNewYork, active: true, progress: flown };
    const at = Maplace.pointAlong(inTheAir, flown);
    const planeThere = { id: "plane", ...at, title: "The plane to New York", icon: plane, listed: false };
    return [...places, inTheAir, ...otherFlights, planeThere];
  }

  const flown = document.getElementById("flights-maplibre-script-flown-input");
  const maplace = Maplace.createMapLibreMap("#flights-maplibre-script-map", {
    locations: flightsWith(flown.valueAsNumber),
    // The earth as a globe, with a toggle on the map to flatten it.
    globe: true,
    list: { container: "#flights-maplibre-script-list", heading: "Flights from London" },
  });
  flown.addEventListener("input", () => maplace.setLocations(flightsWith(flown.valueAsNumber)));
</script>
```

### Script on Google

`packages/maplace/examples/flights/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>
  #flights-script-map-and-list { display: flex; height: 24rem; }
  #flights-script-map { flex: 1 1 auto; min-width: 0; }
  #flights-script-list { display: contents; }
  #flights-script-list .maplace-list-view { flex: 0 1 16rem; }
  #flights-script-flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #flights-script-map-and-list { flex-direction: column; }
    #flights-script-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<label id="flights-script-flown">London → New York, flown
  <input id="flights-script-flown-input" type="range" min="0" max="1" step="0.01" value="0.4">
</label>
<div id="flights-script-map-and-list">
  <div id="flights-script-map"></div>
  <div id="flights-script-list"></div>
</div>
<script type="module">
  // London's flights out, each along its great circle, the shortest way on the earth, the ones
  // still scheduled dashed. The flight to New York is in the air: drawn active, travelled as far as
  // the slider says, with its plane there.
  const london = { lat: 51.5074, lng: -0.1278 };
  const newYork = { id: "new-york", name: "New York", lat: 40.7128, lng: -74.006 };
  const cities = [
    newYork,
    { id: "sao-paulo", name: "São Paulo", lat: -23.5505, lng: -46.6333 },
    { id: "cape-town", name: "Cape Town", lat: -33.9249, lng: 18.4241 },
    { id: "dubai", name: "Dubai", lat: 25.2048, lng: 55.2708 },
    { id: "mumbai", name: "Mumbai", lat: 19.076, lng: 72.8777 },
    { id: "singapore", name: "Singapore", lat: 1.3521, lng: 103.8198 },
    { id: "tokyo", name: "Tokyo", lat: 35.6895, lng: 139.6917 },
    { id: "sydney", name: "Sydney", lat: -33.8688, lng: 151.2093 },
  ];
  const scheduled = new Set(["cape-town", "sydney"]);
  /** A plane, nose up, as an image. */
  const plane =
    "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E";

  function flightTo({ id, name, lat, lng }) {
    return {
      id: `london-${id}`,
      type: "polyline",
      title: `London → ${name}`,
      path: [london, { lat, lng }],
      geodesic: true,
      style: scheduled.has(id) ? { stroke: "#2563eb", strokeDash: "dashed" } : { stroke: "#2563eb" },
    };
  }

  // Made once, so a move of the slider changes only the flight in the air and its plane.
  const places = [
    // The cities and the plane on the map only; the list holds the flights.
    { id: "london", ...london, title: "London", listed: false },
    ...cities.map(({ id, name, lat, lng }) => ({ id, lat, lng, title: name, listed: false })),
  ];
  const toNewYork = flightTo(newYork);
  const otherFlights = cities.slice(1).map(flightTo);

  /** The map's locations, the flight to New York `flown` (0 to 1) of the way there. */
  function flightsWith(flown) {
    const inTheAir = { ...toNewYork, active: true, progress: flown };
    const at = Maplace.pointAlong(inTheAir, flown);
    const planeThere = { id: "plane", ...at, title: "The plane to New York", icon: plane, listed: false };
    return [...places, inTheAir, ...otherFlights, planeThere];
  }

  const flown = document.getElementById("flights-script-flown-input");
  const maplace = Maplace.createGoogleMap("#flights-script-map", {
    apiKey: "YOUR_KEY",
    locations: flightsWith(flown.valueAsNumber),
    list: { container: "#flights-script-list", heading: "Flights from London" },
  });
  flown.addEventListener("input", () => maplace.setLocations(flightsWith(flown.valueAsNumber)));
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/flights/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>
  #flights-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #flights-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #flights-maplibre-vanilla-list { display: contents; }
  #flights-maplibre-vanilla-list .maplace-list-view { flex: 0 1 16rem; }
  #flights-maplibre-vanilla-flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #flights-maplibre-vanilla-map-and-list { flex-direction: column; }
    #flights-maplibre-vanilla-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<label id="flights-maplibre-vanilla-flown">London → New York, flown
  <input id="flights-maplibre-vanilla-flown-input" type="range" min="0" max="1" step="0.01" value="0.4">
</label>
<div id="flights-maplibre-vanilla-map-and-list">
  <div id="flights-maplibre-vanilla-map"></div>
  <div id="flights-maplibre-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

// London's flights out, each along its great circle, the shortest way on the earth, the ones
// still scheduled dashed. The flight to New York is in the air: drawn active, travelled as far as
// the slider says, with its plane there.
const london: LatLng = { lat: 51.5074, lng: -0.1278 };
const newYork = { id: "new-york", name: "New York", lat: 40.7128, lng: -74.006 };
const cities = [
  newYork,
  { id: "sao-paulo", name: "São Paulo", lat: -23.5505, lng: -46.6333 },
  { id: "cape-town", name: "Cape Town", lat: -33.9249, lng: 18.4241 },
  { id: "dubai", name: "Dubai", lat: 25.2048, lng: 55.2708 },
  { id: "mumbai", name: "Mumbai", lat: 19.076, lng: 72.8777 },
  { id: "singapore", name: "Singapore", lat: 1.3521, lng: 103.8198 },
  { id: "tokyo", name: "Tokyo", lat: 35.6895, lng: 139.6917 },
  { id: "sydney", name: "Sydney", lat: -33.8688, lng: 151.2093 },
];
const scheduled = new Set(["cape-town", "sydney"]);
/** A plane, nose up, as an image. */
const plane =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E";

function flightTo({ id, name, lat, lng }: typeof newYork): PolylineLocation {
  return {
    id: `london-${id}`,
    type: "polyline",
    title: `London → ${name}`,
    path: [london, { lat, lng }],
    geodesic: true,
    style: scheduled.has(id) ? { stroke: "#2563eb", strokeDash: "dashed" } : { stroke: "#2563eb" },
  };
}

// Made once, so a move of the slider changes only the flight in the air and its plane.
const places: Location[] = [
  // The cities and the plane on the map only; the list holds the flights.
  { id: "london", ...london, title: "London", listed: false },
  ...cities.map(({ id, name, lat, lng }) => ({ id, lat, lng, title: name, listed: false })),
];
const toNewYork = flightTo(newYork);
const otherFlights = cities.slice(1).map(flightTo);

/** The map's locations, the flight to New York `flown` (0 to 1) of the way there. */
function flightsWith(flown: number): Location[] {
  const inTheAir: PolylineLocation = { ...toNewYork, active: true, progress: flown };
  const at = pointAlong(inTheAir, flown);
  const planeThere = {
    id: "plane",
    ...at,
    title: "The plane to New York",
    icon: plane,
    listed: false,
  };
  return [...places, inTheAir, ...otherFlights, planeThere];
}

const flown = document.getElementById("flights-maplibre-vanilla-flown-input") as HTMLInputElement;
const maplace = createMapLibreMap("#flights-maplibre-vanilla-map", {
  locations: flightsWith(flown.valueAsNumber),
  // The earth as a globe, with a toggle on the map to flatten it.
  globe: true,
  list: { container: "#flights-maplibre-vanilla-list", heading: "Flights from London" },
});
flown.addEventListener("input", () => maplace.setLocations(flightsWith(flown.valueAsNumber)));
```

### Bundler on Google

`packages/maplace/examples/flights/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>
  #flights-vanilla-map-and-list { display: flex; height: 24rem; }
  #flights-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #flights-vanilla-list { display: contents; }
  #flights-vanilla-list .maplace-list-view { flex: 0 1 16rem; }
  #flights-vanilla-flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #flights-vanilla-map-and-list { flex-direction: column; }
    #flights-vanilla-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<label id="flights-vanilla-flown">London → New York, flown
  <input id="flights-vanilla-flown-input" type="range" min="0" max="1" step="0.01" value="0.4">
</label>
<div id="flights-vanilla-map-and-list">
  <div id="flights-vanilla-map"></div>
  <div id="flights-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

// London's flights out, each along its great circle, the shortest way on the earth, the ones
// still scheduled dashed. The flight to New York is in the air: drawn active, travelled as far as
// the slider says, with its plane there.
const london: LatLng = { lat: 51.5074, lng: -0.1278 };
const newYork = { id: "new-york", name: "New York", lat: 40.7128, lng: -74.006 };
const cities = [
  newYork,
  { id: "sao-paulo", name: "São Paulo", lat: -23.5505, lng: -46.6333 },
  { id: "cape-town", name: "Cape Town", lat: -33.9249, lng: 18.4241 },
  { id: "dubai", name: "Dubai", lat: 25.2048, lng: 55.2708 },
  { id: "mumbai", name: "Mumbai", lat: 19.076, lng: 72.8777 },
  { id: "singapore", name: "Singapore", lat: 1.3521, lng: 103.8198 },
  { id: "tokyo", name: "Tokyo", lat: 35.6895, lng: 139.6917 },
  { id: "sydney", name: "Sydney", lat: -33.8688, lng: 151.2093 },
];
const scheduled = new Set(["cape-town", "sydney"]);
/** A plane, nose up, as an image. */
const plane =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E";

function flightTo({ id, name, lat, lng }: typeof newYork): PolylineLocation {
  return {
    id: `london-${id}`,
    type: "polyline",
    title: `London → ${name}`,
    path: [london, { lat, lng }],
    geodesic: true,
    style: scheduled.has(id) ? { stroke: "#2563eb", strokeDash: "dashed" } : { stroke: "#2563eb" },
  };
}

// Made once, so a move of the slider changes only the flight in the air and its plane.
const places: Location[] = [
  // The cities and the plane on the map only; the list holds the flights.
  { id: "london", ...london, title: "London", listed: false },
  ...cities.map(({ id, name, lat, lng }) => ({ id, lat, lng, title: name, listed: false })),
];
const toNewYork = flightTo(newYork);
const otherFlights = cities.slice(1).map(flightTo);

/** The map's locations, the flight to New York `flown` (0 to 1) of the way there. */
function flightsWith(flown: number): Location[] {
  const inTheAir: PolylineLocation = { ...toNewYork, active: true, progress: flown };
  const at = pointAlong(inTheAir, flown);
  const planeThere = {
    id: "plane",
    ...at,
    title: "The plane to New York",
    icon: plane,
    listed: false,
  };
  return [...places, inTheAir, ...otherFlights, planeThere];
}

const flown = document.getElementById("flights-vanilla-flown-input") as HTMLInputElement;
const maplace = createGoogleMap("#flights-vanilla-map", {
  locations: flightsWith(flown.valueAsNumber),
  list: { container: "#flights-vanilla-list", heading: "Flights from London" },
});
flown.addEventListener("input", () => maplace.setLocations(flightsWith(flown.valueAsNumber)));
```

### React on MapLibre

`packages/maplace/examples/flights/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>
  #flights-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #flights-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #flights-maplibre-react-root .maplace-list-view { flex: 0 1 16rem; }
  #flights-maplibre-react-root .flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #flights-maplibre-react-root .map-and-list { flex-direction: column; }
    #flights-maplibre-react-root .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="flights-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

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

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

// London's flights out, each along its great circle, the shortest way on the earth, the ones
// still scheduled dashed. The flight to New York is in the air: drawn active, travelled as far as
// the slider says, with its plane there.
const london: LatLng = { lat: 51.5074, lng: -0.1278 };
const newYork = { id: "new-york", name: "New York", lat: 40.7128, lng: -74.006 };
const cities = [
  newYork,
  { id: "sao-paulo", name: "São Paulo", lat: -23.5505, lng: -46.6333 },
  { id: "cape-town", name: "Cape Town", lat: -33.9249, lng: 18.4241 },
  { id: "dubai", name: "Dubai", lat: 25.2048, lng: 55.2708 },
  { id: "mumbai", name: "Mumbai", lat: 19.076, lng: 72.8777 },
  { id: "singapore", name: "Singapore", lat: 1.3521, lng: 103.8198 },
  { id: "tokyo", name: "Tokyo", lat: 35.6895, lng: 139.6917 },
  { id: "sydney", name: "Sydney", lat: -33.8688, lng: 151.2093 },
];
const scheduled = new Set(["cape-town", "sydney"]);
/** A plane, nose up, as an image. */
const plane =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E";

function flightTo({ id, name, lat, lng }: typeof newYork): PolylineLocation {
  return {
    id: `london-${id}`,
    type: "polyline",
    title: `London → ${name}`,
    path: [london, { lat, lng }],
    geodesic: true,
    style: scheduled.has(id) ? { stroke: "#2563eb", strokeDash: "dashed" } : { stroke: "#2563eb" },
  };
}

// Made once, so a move of the slider changes only the flight in the air and its plane.
const places: Location[] = [
  // The cities and the plane on the map only; the list holds the flights.
  { id: "london", ...london, title: "London", listed: false },
  ...cities.map(({ id, name, lat, lng }) => ({ id, lat, lng, title: name, listed: false })),
];
const toNewYork = flightTo(newYork);
const otherFlights = cities.slice(1).map(flightTo);

/** The map's locations, the flight to New York `flown` (0 to 1) of the way there. */
function flightsWith(flown: number): Location[] {
  const inTheAir: PolylineLocation = { ...toNewYork, active: true, progress: flown };
  const at = pointAlong(inTheAir, flown);
  const planeThere = {
    id: "plane",
    ...at,
    title: "The plane to New York",
    icon: plane,
    listed: false,
  };
  return [...places, inTheAir, ...otherFlights, planeThere];
}

// The earth as a globe, with a toggle on the map to flatten it.
const onTheGlobe = () => createMapLibreAdapter({ globe: true });

function Flights() {
  const [flown, setFlown] = useState(0.4);
  const flights = useMemo(() => flightsWith(flown), [flown]);
  return (
    <MaplaceProvider locations={flights}>
      <label className="flown">
        London → New York, flown{" "}
        <input
          type="range"
          min={0}
          max={1}
          step={0.01}
          value={flown}
          onChange={(event) => setFlown(event.target.valueAsNumber)}
        />
      </label>
      <div className="map-and-list">
        <MaplaceMap createAdapter={onTheGlobe} className="map" />
        <LocationList heading="Flights from London" />
      </div>
    </MaplaceProvider>
  );
}

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

### React on Google

`packages/maplace/examples/flights/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>
  #flights-react-root .map-and-list { display: flex; height: 24rem; }
  #flights-react-root .map { flex: 1 1 auto; min-width: 0; }
  #flights-react-root .maplace-list-view { flex: 0 1 16rem; }
  #flights-react-root .flown { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #flights-react-root .map-and-list { flex-direction: column; }
    #flights-react-root .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="flights-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

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

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

// London's flights out, each along its great circle, the shortest way on the earth, the ones
// still scheduled dashed. The flight to New York is in the air: drawn active, travelled as far as
// the slider says, with its plane there.
const london: LatLng = { lat: 51.5074, lng: -0.1278 };
const newYork = { id: "new-york", name: "New York", lat: 40.7128, lng: -74.006 };
const cities = [
  newYork,
  { id: "sao-paulo", name: "São Paulo", lat: -23.5505, lng: -46.6333 },
  { id: "cape-town", name: "Cape Town", lat: -33.9249, lng: 18.4241 },
  { id: "dubai", name: "Dubai", lat: 25.2048, lng: 55.2708 },
  { id: "mumbai", name: "Mumbai", lat: 19.076, lng: 72.8777 },
  { id: "singapore", name: "Singapore", lat: 1.3521, lng: 103.8198 },
  { id: "tokyo", name: "Tokyo", lat: 35.6895, lng: 139.6917 },
  { id: "sydney", name: "Sydney", lat: -33.8688, lng: 151.2093 },
];
const scheduled = new Set(["cape-town", "sydney"]);
/** A plane, nose up, as an image. */
const plane =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath fill='%231d4ed8' stroke='white' d='M12 2l1.5 7 8.5 4v2l-8.5-2.5-.5 5.5 2.5 2v1.5l-3.5-1-3.5 1V20l2.5-2-.5-5.5L2 15v-2l8.5-4z'/%3E%3C/svg%3E";

function flightTo({ id, name, lat, lng }: typeof newYork): PolylineLocation {
  return {
    id: `london-${id}`,
    type: "polyline",
    title: `London → ${name}`,
    path: [london, { lat, lng }],
    geodesic: true,
    style: scheduled.has(id) ? { stroke: "#2563eb", strokeDash: "dashed" } : { stroke: "#2563eb" },
  };
}

// Made once, so a move of the slider changes only the flight in the air and its plane.
const places: Location[] = [
  // The cities and the plane on the map only; the list holds the flights.
  { id: "london", ...london, title: "London", listed: false },
  ...cities.map(({ id, name, lat, lng }) => ({ id, lat, lng, title: name, listed: false })),
];
const toNewYork = flightTo(newYork);
const otherFlights = cities.slice(1).map(flightTo);

/** The map's locations, the flight to New York `flown` (0 to 1) of the way there. */
function flightsWith(flown: number): Location[] {
  const inTheAir: PolylineLocation = { ...toNewYork, active: true, progress: flown };
  const at = pointAlong(inTheAir, flown);
  const planeThere = {
    id: "plane",
    ...at,
    title: "The plane to New York",
    icon: plane,
    listed: false,
  };
  return [...places, inTheAir, ...otherFlights, planeThere];
}

function Flights() {
  const [flown, setFlown] = useState(0.4);
  const flights = useMemo(() => flightsWith(flown), [flown]);
  return (
    <MaplaceProvider locations={flights}>
      <label className="flown">
        London → New York, flown{" "}
        <input
          type="range"
          min={0}
          max={1}
          step={0.01}
          value={flown}
          onChange={(event) => setFlown(event.target.valueAsNumber)}
        />
      </label>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
        <LocationList heading="Flights from London" />
      </div>
    </MaplaceProvider>
  );
}

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

## Trade lanes

Air and sea lanes by colour; hover one, pick one for its volume.

Sea and air lanes between ports and airports, each a bowed line in its mode's colour, listed under Sea and Air.

- **Try it**: hover a lane on the map and it is drawn wider; pick one, drawn wider still, on the map or in the list, for its volume in a popup. Shanghai to Los Angeles crosses the Pacific, the short way.
- **HTML**: a `<script type="application/json">` inside `<maplace-map>` holding the lanes ([Data](/element/#data)), and `list` and `list-heading` on the map ([Map attributes](/element/#map-attributes)).
- **Script** and **Bundler**: `curve` on each lane ([Curves and great circles](/locations/#curves-and-great-circles)), its `group`, its `style`, `hoveredStyle` and `selectedStyle` ([Styles](/locations/#styles)), its volume as `content`, and `list: { container, heading }` ([List view options](/store/#list-view-options)).
- **React**: the same locations on `<MaplaceProvider>`, and `<LocationList heading="Trade lanes" />` beside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)).


### HTML on MapLibre

`packages/maplace/examples/trade-lanes/maplibre/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- Sea and air lanes as bowed lines, each coloured by its mode and wider hovered or
     selected, listed under Sea and Air; pick one for its volume (the figures are made up,
     for the example). -->
<maplace-map list list-heading="Trade lanes">
  <script type="application/json">
    [{ "id": "shanghai-los-angeles", "type": "polyline", "title": "Shanghai → Los Angeles", "group": "Sea", "curve": 0.2,
       "path": [{ "lat": 31.2304, "lng": 121.4737 }, { "lat": 34.0522, "lng": -118.2437 }],
       "style": { "stroke": "#0f766e" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "24,800 TEU a week" },
     { "id": "singapore-rotterdam", "type": "polyline", "title": "Singapore → Rotterdam", "group": "Sea", "curve": 0.2,
       "path": [{ "lat": 1.3521, "lng": 103.8198 }, { "lat": 51.9244, "lng": 4.4777 }],
       "style": { "stroke": "#0f766e" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "9,400 TEU a week" },
     { "id": "rotterdam-new-york", "type": "polyline", "title": "Rotterdam → New York", "group": "Sea", "curve": -0.2,
       "path": [{ "lat": 51.9244, "lng": 4.4777 }, { "lat": 40.7128, "lng": -74.006 }],
       "style": { "stroke": "#0f766e" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "3,100 TEU a week" },
     { "id": "hong-kong-anchorage", "type": "polyline", "title": "Hong Kong → Anchorage", "group": "Air", "curve": 0.2,
       "path": [{ "lat": 22.3193, "lng": 114.1694 }, { "lat": 61.2181, "lng": -149.9003 }],
       "style": { "stroke": "#7c3aed" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "1,500 t a week" },
     { "id": "frankfurt-chicago", "type": "polyline", "title": "Frankfurt → Chicago", "group": "Air", "curve": -0.2,
       "path": [{ "lat": 50.1109, "lng": 8.6821 }, { "lat": 41.8781, "lng": -87.6298 }],
       "style": { "stroke": "#7c3aed" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "820 t a week" },
     { "id": "dubai-nairobi", "type": "polyline", "title": "Dubai → Nairobi", "group": "Air", "curve": 0.2,
       "path": [{ "lat": 25.2048, "lng": 55.2708 }, { "lat": -1.2921, "lng": 36.8219 }],
       "style": { "stroke": "#7c3aed" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "310 t a week" }]
  </script>
</maplace-map>
```

### HTML on Google

`packages/maplace/examples/trade-lanes/page.html`

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- Sea and air lanes as bowed lines, each coloured by its mode and wider hovered or
     selected, listed under Sea and Air; pick one for its volume (the figures are made up,
     for the example). -->
<maplace-map api-key="YOUR_KEY" list list-heading="Trade lanes">
  <script type="application/json">
    [{ "id": "shanghai-los-angeles", "type": "polyline", "title": "Shanghai → Los Angeles", "group": "Sea", "curve": 0.2,
       "path": [{ "lat": 31.2304, "lng": 121.4737 }, { "lat": 34.0522, "lng": -118.2437 }],
       "style": { "stroke": "#0f766e" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "24,800 TEU a week" },
     { "id": "singapore-rotterdam", "type": "polyline", "title": "Singapore → Rotterdam", "group": "Sea", "curve": 0.2,
       "path": [{ "lat": 1.3521, "lng": 103.8198 }, { "lat": 51.9244, "lng": 4.4777 }],
       "style": { "stroke": "#0f766e" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "9,400 TEU a week" },
     { "id": "rotterdam-new-york", "type": "polyline", "title": "Rotterdam → New York", "group": "Sea", "curve": -0.2,
       "path": [{ "lat": 51.9244, "lng": 4.4777 }, { "lat": 40.7128, "lng": -74.006 }],
       "style": { "stroke": "#0f766e" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "3,100 TEU a week" },
     { "id": "hong-kong-anchorage", "type": "polyline", "title": "Hong Kong → Anchorage", "group": "Air", "curve": 0.2,
       "path": [{ "lat": 22.3193, "lng": 114.1694 }, { "lat": 61.2181, "lng": -149.9003 }],
       "style": { "stroke": "#7c3aed" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "1,500 t a week" },
     { "id": "frankfurt-chicago", "type": "polyline", "title": "Frankfurt → Chicago", "group": "Air", "curve": -0.2,
       "path": [{ "lat": 50.1109, "lng": 8.6821 }, { "lat": 41.8781, "lng": -87.6298 }],
       "style": { "stroke": "#7c3aed" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "820 t a week" },
     { "id": "dubai-nairobi", "type": "polyline", "title": "Dubai → Nairobi", "group": "Air", "curve": 0.2,
       "path": [{ "lat": 25.2048, "lng": 55.2708 }, { "lat": -1.2921, "lng": 36.8219 }],
       "style": { "stroke": "#7c3aed" }, "hoveredStyle": { "strokeWidth": 5 }, "selectedStyle": { "strokeWidth": 6 },
       "content": "310 t a week" }]
  </script>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/trade-lanes/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>
  #trade-lanes-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #trade-lanes-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #trade-lanes-maplibre-script-list { display: contents; }
  #trade-lanes-maplibre-script-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #trade-lanes-maplibre-script-map-and-list { flex-direction: column; }
    #trade-lanes-maplibre-script-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="trade-lanes-maplibre-script-map-and-list">
  <div id="trade-lanes-maplibre-script-map"></div>
  <div id="trade-lanes-maplibre-script-list"></div>
</div>
<script type="module">
  // Sea and air lanes, each coloured by its mode. The volumes are made up, for the example.
  // A curve bows each lane for the look: to the left of travel, to the right when negative.
  const colours = { Sea: "#0f766e", Air: "#7c3aed" };
  const routes = [
    {
      id: "shanghai-los-angeles",
      title: "Shanghai → Los Angeles",
      mode: "Sea",
      from: { lat: 31.2304, lng: 121.4737 },
      to: { lat: 34.0522, lng: -118.2437 },
      curve: 0.2,
      volume: "24,800 TEU a week",
    },
    {
      id: "singapore-rotterdam",
      title: "Singapore → Rotterdam",
      mode: "Sea",
      from: { lat: 1.3521, lng: 103.8198 },
      to: { lat: 51.9244, lng: 4.4777 },
      curve: 0.2,
      volume: "9,400 TEU a week",
    },
    {
      id: "rotterdam-new-york",
      title: "Rotterdam → New York",
      mode: "Sea",
      from: { lat: 51.9244, lng: 4.4777 },
      to: { lat: 40.7128, lng: -74.006 },
      curve: -0.2,
      volume: "3,100 TEU a week",
    },
    {
      id: "hong-kong-anchorage",
      title: "Hong Kong → Anchorage",
      mode: "Air",
      from: { lat: 22.3193, lng: 114.1694 },
      to: { lat: 61.2181, lng: -149.9003 },
      curve: 0.2,
      volume: "1,500 t a week",
    },
    {
      id: "frankfurt-chicago",
      title: "Frankfurt → Chicago",
      mode: "Air",
      from: { lat: 50.1109, lng: 8.6821 },
      to: { lat: 41.8781, lng: -87.6298 },
      curve: -0.2,
      volume: "820 t a week",
    },
    {
      id: "dubai-nairobi",
      title: "Dubai → Nairobi",
      mode: "Air",
      from: { lat: 25.2048, lng: 55.2708 },
      to: { lat: -1.2921, lng: 36.8219 },
      curve: 0.2,
      volume: "310 t a week",
    },
  ];
  const lanes = routes.map(({ id, title, mode, from, to, curve, volume }) => ({
    id,
    type: "polyline",
    title,
    group: mode,
    path: [from, to],
    curve,
    style: { stroke: colours[mode] },
    hoveredStyle: { strokeWidth: 5 },
    selectedStyle: { strokeWidth: 6 },
    content: volume,
  }));
  Maplace.createMapLibreMap("#trade-lanes-maplibre-script-map", {
    locations: lanes,
    list: { container: "#trade-lanes-maplibre-script-list", heading: "Trade lanes" },
  });
</script>
```

### Script on Google

`packages/maplace/examples/trade-lanes/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>
  #trade-lanes-script-map-and-list { display: flex; height: 24rem; }
  #trade-lanes-script-map { flex: 1 1 auto; min-width: 0; }
  #trade-lanes-script-list { display: contents; }
  #trade-lanes-script-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #trade-lanes-script-map-and-list { flex-direction: column; }
    #trade-lanes-script-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="trade-lanes-script-map-and-list">
  <div id="trade-lanes-script-map"></div>
  <div id="trade-lanes-script-list"></div>
</div>
<script type="module">
  // Sea and air lanes, each coloured by its mode. The volumes are made up, for the example.
  // A curve bows each lane for the look: to the left of travel, to the right when negative.
  const colours = { Sea: "#0f766e", Air: "#7c3aed" };
  const routes = [
    {
      id: "shanghai-los-angeles",
      title: "Shanghai → Los Angeles",
      mode: "Sea",
      from: { lat: 31.2304, lng: 121.4737 },
      to: { lat: 34.0522, lng: -118.2437 },
      curve: 0.2,
      volume: "24,800 TEU a week",
    },
    {
      id: "singapore-rotterdam",
      title: "Singapore → Rotterdam",
      mode: "Sea",
      from: { lat: 1.3521, lng: 103.8198 },
      to: { lat: 51.9244, lng: 4.4777 },
      curve: 0.2,
      volume: "9,400 TEU a week",
    },
    {
      id: "rotterdam-new-york",
      title: "Rotterdam → New York",
      mode: "Sea",
      from: { lat: 51.9244, lng: 4.4777 },
      to: { lat: 40.7128, lng: -74.006 },
      curve: -0.2,
      volume: "3,100 TEU a week",
    },
    {
      id: "hong-kong-anchorage",
      title: "Hong Kong → Anchorage",
      mode: "Air",
      from: { lat: 22.3193, lng: 114.1694 },
      to: { lat: 61.2181, lng: -149.9003 },
      curve: 0.2,
      volume: "1,500 t a week",
    },
    {
      id: "frankfurt-chicago",
      title: "Frankfurt → Chicago",
      mode: "Air",
      from: { lat: 50.1109, lng: 8.6821 },
      to: { lat: 41.8781, lng: -87.6298 },
      curve: -0.2,
      volume: "820 t a week",
    },
    {
      id: "dubai-nairobi",
      title: "Dubai → Nairobi",
      mode: "Air",
      from: { lat: 25.2048, lng: 55.2708 },
      to: { lat: -1.2921, lng: 36.8219 },
      curve: 0.2,
      volume: "310 t a week",
    },
  ];
  const lanes = routes.map(({ id, title, mode, from, to, curve, volume }) => ({
    id,
    type: "polyline",
    title,
    group: mode,
    path: [from, to],
    curve,
    style: { stroke: colours[mode] },
    hoveredStyle: { strokeWidth: 5 },
    selectedStyle: { strokeWidth: 6 },
    content: volume,
  }));
  Maplace.createGoogleMap("#trade-lanes-script-map", {
    apiKey: "YOUR_KEY",
    locations: lanes,
    list: { container: "#trade-lanes-script-list", heading: "Trade lanes" },
  });
</script>
```

### Bundler on MapLibre

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

`packages/maplace/examples/trade-lanes/maplibre/vanilla.ts`

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

// Sea and air lanes, each coloured by its mode. The volumes are made up, for the example.
// A curve bows each lane for the look: to the left of travel, to the right when negative.
const colours: Record<string, string> = { Sea: "#0f766e", Air: "#7c3aed" };
const routes = [
  {
    id: "shanghai-los-angeles",
    title: "Shanghai → Los Angeles",
    mode: "Sea",
    from: { lat: 31.2304, lng: 121.4737 },
    to: { lat: 34.0522, lng: -118.2437 },
    curve: 0.2,
    volume: "24,800 TEU a week",
  },
  {
    id: "singapore-rotterdam",
    title: "Singapore → Rotterdam",
    mode: "Sea",
    from: { lat: 1.3521, lng: 103.8198 },
    to: { lat: 51.9244, lng: 4.4777 },
    curve: 0.2,
    volume: "9,400 TEU a week",
  },
  {
    id: "rotterdam-new-york",
    title: "Rotterdam → New York",
    mode: "Sea",
    from: { lat: 51.9244, lng: 4.4777 },
    to: { lat: 40.7128, lng: -74.006 },
    curve: -0.2,
    volume: "3,100 TEU a week",
  },
  {
    id: "hong-kong-anchorage",
    title: "Hong Kong → Anchorage",
    mode: "Air",
    from: { lat: 22.3193, lng: 114.1694 },
    to: { lat: 61.2181, lng: -149.9003 },
    curve: 0.2,
    volume: "1,500 t a week",
  },
  {
    id: "frankfurt-chicago",
    title: "Frankfurt → Chicago",
    mode: "Air",
    from: { lat: 50.1109, lng: 8.6821 },
    to: { lat: 41.8781, lng: -87.6298 },
    curve: -0.2,
    volume: "820 t a week",
  },
  {
    id: "dubai-nairobi",
    title: "Dubai → Nairobi",
    mode: "Air",
    from: { lat: 25.2048, lng: 55.2708 },
    to: { lat: -1.2921, lng: 36.8219 },
    curve: 0.2,
    volume: "310 t a week",
  },
];
const lanes: Location[] = routes.map(
  ({ id, title, mode, from, to, curve, volume }): Location => ({
    id,
    type: "polyline",
    title,
    group: mode,
    path: [from, to],
    curve,
    style: { stroke: colours[mode] },
    hoveredStyle: { strokeWidth: 5 },
    selectedStyle: { strokeWidth: 6 },
    content: volume,
  }),
);
createMapLibreMap("#trade-lanes-maplibre-vanilla-map", {
  locations: lanes,
  list: { container: "#trade-lanes-maplibre-vanilla-list", heading: "Trade lanes" },
});
```

### Bundler on Google

`packages/maplace/examples/trade-lanes/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>
  #trade-lanes-vanilla-map-and-list { display: flex; height: 24rem; }
  #trade-lanes-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #trade-lanes-vanilla-list { display: contents; }
  #trade-lanes-vanilla-list .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #trade-lanes-vanilla-map-and-list { flex-direction: column; }
    #trade-lanes-vanilla-list .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="trade-lanes-vanilla-map-and-list">
  <div id="trade-lanes-vanilla-map"></div>
  <div id="trade-lanes-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

`packages/maplace/examples/trade-lanes/vanilla.ts`

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

// Sea and air lanes, each coloured by its mode. The volumes are made up, for the example.
// A curve bows each lane for the look: to the left of travel, to the right when negative.
const colours: Record<string, string> = { Sea: "#0f766e", Air: "#7c3aed" };
const routes = [
  {
    id: "shanghai-los-angeles",
    title: "Shanghai → Los Angeles",
    mode: "Sea",
    from: { lat: 31.2304, lng: 121.4737 },
    to: { lat: 34.0522, lng: -118.2437 },
    curve: 0.2,
    volume: "24,800 TEU a week",
  },
  {
    id: "singapore-rotterdam",
    title: "Singapore → Rotterdam",
    mode: "Sea",
    from: { lat: 1.3521, lng: 103.8198 },
    to: { lat: 51.9244, lng: 4.4777 },
    curve: 0.2,
    volume: "9,400 TEU a week",
  },
  {
    id: "rotterdam-new-york",
    title: "Rotterdam → New York",
    mode: "Sea",
    from: { lat: 51.9244, lng: 4.4777 },
    to: { lat: 40.7128, lng: -74.006 },
    curve: -0.2,
    volume: "3,100 TEU a week",
  },
  {
    id: "hong-kong-anchorage",
    title: "Hong Kong → Anchorage",
    mode: "Air",
    from: { lat: 22.3193, lng: 114.1694 },
    to: { lat: 61.2181, lng: -149.9003 },
    curve: 0.2,
    volume: "1,500 t a week",
  },
  {
    id: "frankfurt-chicago",
    title: "Frankfurt → Chicago",
    mode: "Air",
    from: { lat: 50.1109, lng: 8.6821 },
    to: { lat: 41.8781, lng: -87.6298 },
    curve: -0.2,
    volume: "820 t a week",
  },
  {
    id: "dubai-nairobi",
    title: "Dubai → Nairobi",
    mode: "Air",
    from: { lat: 25.2048, lng: 55.2708 },
    to: { lat: -1.2921, lng: 36.8219 },
    curve: 0.2,
    volume: "310 t a week",
  },
];
const lanes: Location[] = routes.map(
  ({ id, title, mode, from, to, curve, volume }): Location => ({
    id,
    type: "polyline",
    title,
    group: mode,
    path: [from, to],
    curve,
    style: { stroke: colours[mode] },
    hoveredStyle: { strokeWidth: 5 },
    selectedStyle: { strokeWidth: 6 },
    content: volume,
  }),
);
createGoogleMap("#trade-lanes-vanilla-map", {
  locations: lanes,
  list: { container: "#trade-lanes-vanilla-list", heading: "Trade lanes" },
});
```

### React on MapLibre

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

`packages/maplace/examples/trade-lanes/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";

// Sea and air lanes, each coloured by its mode. The volumes are made up, for the example.
// A curve bows each lane for the look: to the left of travel, to the right when negative.
const colours: Record<string, string> = { Sea: "#0f766e", Air: "#7c3aed" };
const routes = [
  {
    id: "shanghai-los-angeles",
    title: "Shanghai → Los Angeles",
    mode: "Sea",
    from: { lat: 31.2304, lng: 121.4737 },
    to: { lat: 34.0522, lng: -118.2437 },
    curve: 0.2,
    volume: "24,800 TEU a week",
  },
  {
    id: "singapore-rotterdam",
    title: "Singapore → Rotterdam",
    mode: "Sea",
    from: { lat: 1.3521, lng: 103.8198 },
    to: { lat: 51.9244, lng: 4.4777 },
    curve: 0.2,
    volume: "9,400 TEU a week",
  },
  {
    id: "rotterdam-new-york",
    title: "Rotterdam → New York",
    mode: "Sea",
    from: { lat: 51.9244, lng: 4.4777 },
    to: { lat: 40.7128, lng: -74.006 },
    curve: -0.2,
    volume: "3,100 TEU a week",
  },
  {
    id: "hong-kong-anchorage",
    title: "Hong Kong → Anchorage",
    mode: "Air",
    from: { lat: 22.3193, lng: 114.1694 },
    to: { lat: 61.2181, lng: -149.9003 },
    curve: 0.2,
    volume: "1,500 t a week",
  },
  {
    id: "frankfurt-chicago",
    title: "Frankfurt → Chicago",
    mode: "Air",
    from: { lat: 50.1109, lng: 8.6821 },
    to: { lat: 41.8781, lng: -87.6298 },
    curve: -0.2,
    volume: "820 t a week",
  },
  {
    id: "dubai-nairobi",
    title: "Dubai → Nairobi",
    mode: "Air",
    from: { lat: 25.2048, lng: 55.2708 },
    to: { lat: -1.2921, lng: 36.8219 },
    curve: 0.2,
    volume: "310 t a week",
  },
];
const lanes: Location[] = routes.map(
  ({ id, title, mode, from, to, curve, volume }): Location => ({
    id,
    type: "polyline",
    title,
    group: mode,
    path: [from, to],
    curve,
    style: { stroke: colours[mode] },
    hoveredStyle: { strokeWidth: 5 },
    selectedStyle: { strokeWidth: 6 },
    content: volume,
  }),
);

function TradeLanes() {
  return (
    <MaplaceProvider locations={lanes}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
        <LocationList heading="Trade lanes" />
      </div>
    </MaplaceProvider>
  );
}

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

### React on Google

`packages/maplace/examples/trade-lanes/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>
  #trade-lanes-react-root .map-and-list { display: flex; height: 24rem; }
  #trade-lanes-react-root .map { flex: 1 1 auto; min-width: 0; }
  #trade-lanes-react-root .maplace-list-view { flex: 0 1 16rem; }
  /* On a phone the list goes under the map, as the element's does. */
  @media (width < 40rem) {
    #trade-lanes-react-root .map-and-list { flex-direction: column; }
    #trade-lanes-react-root .maplace-list-view { flex: none; max-height: 40%; }
  }
</style>
<div id="trade-lanes-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/trade-lanes/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";

// Sea and air lanes, each coloured by its mode. The volumes are made up, for the example.
// A curve bows each lane for the look: to the left of travel, to the right when negative.
const colours: Record<string, string> = { Sea: "#0f766e", Air: "#7c3aed" };
const routes = [
  {
    id: "shanghai-los-angeles",
    title: "Shanghai → Los Angeles",
    mode: "Sea",
    from: { lat: 31.2304, lng: 121.4737 },
    to: { lat: 34.0522, lng: -118.2437 },
    curve: 0.2,
    volume: "24,800 TEU a week",
  },
  {
    id: "singapore-rotterdam",
    title: "Singapore → Rotterdam",
    mode: "Sea",
    from: { lat: 1.3521, lng: 103.8198 },
    to: { lat: 51.9244, lng: 4.4777 },
    curve: 0.2,
    volume: "9,400 TEU a week",
  },
  {
    id: "rotterdam-new-york",
    title: "Rotterdam → New York",
    mode: "Sea",
    from: { lat: 51.9244, lng: 4.4777 },
    to: { lat: 40.7128, lng: -74.006 },
    curve: -0.2,
    volume: "3,100 TEU a week",
  },
  {
    id: "hong-kong-anchorage",
    title: "Hong Kong → Anchorage",
    mode: "Air",
    from: { lat: 22.3193, lng: 114.1694 },
    to: { lat: 61.2181, lng: -149.9003 },
    curve: 0.2,
    volume: "1,500 t a week",
  },
  {
    id: "frankfurt-chicago",
    title: "Frankfurt → Chicago",
    mode: "Air",
    from: { lat: 50.1109, lng: 8.6821 },
    to: { lat: 41.8781, lng: -87.6298 },
    curve: -0.2,
    volume: "820 t a week",
  },
  {
    id: "dubai-nairobi",
    title: "Dubai → Nairobi",
    mode: "Air",
    from: { lat: 25.2048, lng: 55.2708 },
    to: { lat: -1.2921, lng: 36.8219 },
    curve: 0.2,
    volume: "310 t a week",
  },
];
const lanes: Location[] = routes.map(
  ({ id, title, mode, from, to, curve, volume }): Location => ({
    id,
    type: "polyline",
    title,
    group: mode,
    path: [from, to],
    curve,
    style: { stroke: colours[mode] },
    hoveredStyle: { strokeWidth: 5 },
    selectedStyle: { strokeWidth: 6 },
    content: volume,
  }),
);

function TradeLanes() {
  return (
    <MaplaceProvider locations={lanes}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
        <LocationList heading="Trade lanes" />
      </div>
    </MaplaceProvider>
  );
}

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

## Editable polygon

An area to edit: drag a corner, and the edit is written back.

A three-cornered park you can edit: each edit is written back to the store and announced, for your page to save.

- **Try it**: drag a corner, or the middle of an edge to add one; letting go calls the page's `save`, which the site shows under the map.
- **HTML**: a `<script type="application/json">` inside `<maplace-map>` holding the polygon ([Data](/element/#data)), and a `maplace-locationchange` listener ([Events](/element/#events)).
- **Script** and **Bundler**: `type: "polygon"`, `path` and `editable` on a location ([Polygons](/locations/#polygons)), and a `locationChange` listener ([Events](/store/#events)).
- **React**: the same location, with `onLocationChange` on `<MaplaceProvider>` ([Event props](/react/#event-props)).


### HTML on MapLibre

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- An editable area; edits are written back and announced. -->
<maplace-map id="polygon-maplibre-map">
  <script type="application/json">
    [{ "id": "park", "type": "polygon", "title": "Hyde Park", "editable": true,
       "path": [{ "lat": 51.512, "lng": -0.175 }, { "lat": 51.513, "lng": -0.16 }, { "lat": 51.503, "lng": -0.155 }] }]
  </script>
</maplace-map>
<script>
  document.getElementById('polygon-maplibre-map').addEventListener('maplace-locationchange', (event) => save(event.detail.location));
</script>
```

### HTML on Google

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- An editable area; edits are written back and announced. -->
<maplace-map id="polygon-map" api-key="YOUR_KEY">
  <script type="application/json">
    [{ "id": "park", "type": "polygon", "title": "Hyde Park", "editable": true,
       "path": [{ "lat": 51.512, "lng": -0.175 }, { "lat": 51.513, "lng": -0.16 }, { "lat": 51.503, "lng": -0.155 }] }]
  </script>
</maplace-map>
<script>
  document.getElementById('polygon-map').addEventListener('maplace-locationchange', (event) => save(event.detail.location));
</script>
```

### Script on MapLibre

`packages/maplace/examples/polygon/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>
  #polygon-maplibre-script-map { height: 24rem; }
</style>
<div id="polygon-maplibre-script-map"></div>
<script type="module">
  // save(location): your own code, writing an edited location back to your server.

  const locations = [
    {
      id: "park",
      type: "polygon",
      title: "Hyde Park",
      editable: true,
      path: [
        { lat: 51.512, lng: -0.175 },
        { lat: 51.513, lng: -0.16 },
        { lat: 51.503, lng: -0.155 },
      ],
    },
  ];
  const maplace = Maplace.createMapLibreMap("#polygon-maplibre-script-map", { locations });
  maplace.on("locationChange", ({ location }) => save(location));
</script>
```

### Script on Google

`packages/maplace/examples/polygon/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>
  #polygon-script-map { height: 24rem; }
</style>
<div id="polygon-script-map"></div>
<script type="module">
  // save(location): your own code, writing an edited location back to your server.

  const locations = [
    {
      id: "park",
      type: "polygon",
      title: "Hyde Park",
      editable: true,
      path: [
        { lat: 51.512, lng: -0.175 },
        { lat: 51.513, lng: -0.16 },
        { lat: 51.503, lng: -0.155 },
      ],
    },
  ];
  const maplace = Maplace.createGoogleMap("#polygon-script-map", { apiKey: "YOUR_KEY", locations });
  maplace.on("locationChange", ({ location }) => save(location));
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/polygon/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>
  #polygon-maplibre-vanilla-map { height: 24rem; }
</style>
<div id="polygon-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

/** Your own code, writing an edited location back to your server. */
declare function save(location: Location): Promise<void>;

const locations: Location[] = [
  {
    id: "park",
    type: "polygon",
    title: "Hyde Park",
    editable: true,
    path: [
      { lat: 51.512, lng: -0.175 },
      { lat: 51.513, lng: -0.16 },
      { lat: 51.503, lng: -0.155 },
    ],
  },
];
const maplace = createMapLibreMap("#polygon-maplibre-vanilla-map", { locations });
maplace.on("locationChange", ({ location }) => save(location));
```

### Bundler on Google

`packages/maplace/examples/polygon/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>
  #polygon-vanilla-map { height: 24rem; }
</style>
<div id="polygon-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

/** Your own code, writing an edited location back to your server. */
declare function save(location: Location): Promise<void>;

const locations: Location[] = [
  {
    id: "park",
    type: "polygon",
    title: "Hyde Park",
    editable: true,
    path: [
      { lat: 51.512, lng: -0.175 },
      { lat: 51.513, lng: -0.16 },
      { lat: 51.503, lng: -0.155 },
    ],
  },
];
const maplace = createGoogleMap("#polygon-vanilla-map", { locations });
maplace.on("locationChange", ({ location }) => save(location));
```

### React on MapLibre

`packages/maplace/examples/polygon/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>
  #polygon-maplibre-react-root .map { height: 24rem; }
</style>
<div id="polygon-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

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

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

/** Your own code, writing an edited location back to your server. */
declare function save(location: Location): Promise<void>;

const park: Location[] = [
  {
    id: "park",
    type: "polygon",
    title: "Hyde Park",
    editable: true,
    path: [
      { lat: 51.512, lng: -0.175 },
      { lat: 51.513, lng: -0.16 },
      { lat: 51.503, lng: -0.155 },
    ],
  },
];

function Polygon() {
  return (
    <MaplaceProvider locations={park} onLocationChange={({ location }) => void save(location)}>
      <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
    </MaplaceProvider>
  );
}

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

### React on Google

`packages/maplace/examples/polygon/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>
  #polygon-react-root .map { height: 24rem; }
</style>
<div id="polygon-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

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

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

/** Your own code, writing an edited location back to your server. */
declare function save(location: Location): Promise<void>;

const park: Location[] = [
  {
    id: "park",
    type: "polygon",
    title: "Hyde Park",
    editable: true,
    path: [
      { lat: 51.512, lng: -0.175 },
      { lat: 51.513, lng: -0.16 },
      { lat: 51.503, lng: -0.155 },
    ],
  },
];

function Polygon() {
  return (
    <MaplaceProvider locations={park} onLocationChange={({ location }) => void save(location)}>
      <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
    </MaplaceProvider>
  );
}

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

## Markers and shapes together

A marker, a circle, an area and a line on one map and in one list.

A marker, a circle, a polygon and a polyline on one map and in one list: each location says what it is with its own `type`, and everything else about them works alike.

- **Try it**: pick each entry in the list and the map goes to it. Click a shape or the marker on the map and the list follows.
- **HTML**: `list` on the map, and a `<script type="application/json">` inside `<maplace-map>` holding all four, as a path takes more than an attribute ([Data](/element/#data)).
- **Script** and **Bundler**: `type` on each location ([Markers](/locations/#markers), [Circles](/locations/#circles), [Polylines](/locations/#polylines), [Polygons](/locations/#polygons)), and `list: { container }` ([List view options](/store/#list-view-options)).
- **React**: the same locations on `<MaplaceProvider>`, and `<LocationList />` beside the `<MaplaceMap>` ([`<LocationList>`](/react/#locationlist)).


### HTML on MapLibre

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- A marker, a circle, a polygon and a polyline on one map and in one list: each location gives its
     own type, all from inline JSON. -->
<maplace-map list>
  <script type="application/json">
    [{ "id": "tower-of-london", "type": "marker", "title": "Tower of London", "lat": 51.5081, "lng": -0.0759 },
     { "id": "greenwich", "type": "circle", "title": "Greenwich", "center": { "lat": 51.4769, "lng": -0.0005 }, "radius": 500 },
     { "id": "hyde-park", "type": "polygon", "title": "Hyde Park",
       "path": [{ "lat": 51.5115, "lng": -0.1755 }, { "lat": 51.511, "lng": -0.16 }, { "lat": 51.503, "lng": -0.16 },
                { "lat": 51.5035, "lng": -0.1755 }] },
     { "id": "thames", "type": "polyline", "title": "Along the Thames",
       "path": [{ "lat": 51.5009, "lng": -0.1222 }, { "lat": 51.5085, "lng": -0.1166 }, { "lat": 51.5098, "lng": -0.1043 },
                { "lat": 51.5085, "lng": -0.0943 }, { "lat": 51.5079, "lng": -0.0877 }] }]
  </script>
</maplace-map>
```

### HTML on Google

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

```html
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- A marker, a circle, a polygon and a polyline on one map and in one list: each location gives its
     own type, all from inline JSON. -->
<maplace-map api-key="YOUR_KEY" list>
  <script type="application/json">
    [{ "id": "tower-of-london", "type": "marker", "title": "Tower of London", "lat": 51.5081, "lng": -0.0759 },
     { "id": "greenwich", "type": "circle", "title": "Greenwich", "center": { "lat": 51.4769, "lng": -0.0005 }, "radius": 500 },
     { "id": "hyde-park", "type": "polygon", "title": "Hyde Park",
       "path": [{ "lat": 51.5115, "lng": -0.1755 }, { "lat": 51.511, "lng": -0.16 }, { "lat": 51.503, "lng": -0.16 },
                { "lat": 51.5035, "lng": -0.1755 }] },
     { "id": "thames", "type": "polyline", "title": "Along the Thames",
       "path": [{ "lat": 51.5009, "lng": -0.1222 }, { "lat": 51.5085, "lng": -0.1166 }, { "lat": 51.5098, "lng": -0.1043 },
                { "lat": 51.5085, "lng": -0.0943 }, { "lat": 51.5079, "lng": -0.0877 }] }]
  </script>
</maplace-map>
```

### Script on MapLibre

`packages/maplace/examples/mixed/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>
  #mixed-maplibre-script-map-and-list { display: flex; height: 24rem; }
  #mixed-maplibre-script-map { flex: 1 1 auto; min-width: 0; }
  #mixed-maplibre-script-list { display: contents; }
  #mixed-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) {
    #mixed-maplibre-script-map-and-list { flex-direction: column; }
    #mixed-maplibre-script-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="mixed-maplibre-script-map-and-list">
  <div id="mixed-maplibre-script-map"></div>
  <div id="mixed-maplibre-script-list"></div>
</div>
<script type="module">
  const locations = [
    { id: "tower-of-london", type: "marker", title: "Tower of London", lat: 51.5081, lng: -0.0759 },
    {
      id: "greenwich",
      type: "circle",
      title: "Greenwich",
      center: { lat: 51.4769, lng: -0.0005 },
      radius: 500,
    },
    {
      id: "hyde-park",
      type: "polygon",
      title: "Hyde Park",
      path: [
        { lat: 51.5115, lng: -0.1755 },
        { lat: 51.511, lng: -0.16 },
        { lat: 51.503, lng: -0.16 },
        { lat: 51.5035, lng: -0.1755 },
      ],
    },
    {
      id: "thames",
      type: "polyline",
      title: "Along the Thames",
      path: [
        { lat: 51.5009, lng: -0.1222 },
        { lat: 51.5085, lng: -0.1166 },
        { lat: 51.5098, lng: -0.1043 },
        { lat: 51.5085, lng: -0.0943 },
        { lat: 51.5079, lng: -0.0877 },
      ],
    },
  ];
  Maplace.createMapLibreMap("#mixed-maplibre-script-map", {
    locations,
    list: { container: "#mixed-maplibre-script-list" },
  });
</script>
```

### Script on Google

`packages/maplace/examples/mixed/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>
  #mixed-script-map-and-list { display: flex; height: 24rem; }
  #mixed-script-map { flex: 1 1 auto; min-width: 0; }
  #mixed-script-list { display: contents; }
  #mixed-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) {
    #mixed-script-map-and-list { flex-direction: column; }
    #mixed-script-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="mixed-script-map-and-list">
  <div id="mixed-script-map"></div>
  <div id="mixed-script-list"></div>
</div>
<script type="module">
  const locations = [
    { id: "tower-of-london", type: "marker", title: "Tower of London", lat: 51.5081, lng: -0.0759 },
    {
      id: "greenwich",
      type: "circle",
      title: "Greenwich",
      center: { lat: 51.4769, lng: -0.0005 },
      radius: 500,
    },
    {
      id: "hyde-park",
      type: "polygon",
      title: "Hyde Park",
      path: [
        { lat: 51.5115, lng: -0.1755 },
        { lat: 51.511, lng: -0.16 },
        { lat: 51.503, lng: -0.16 },
        { lat: 51.5035, lng: -0.1755 },
      ],
    },
    {
      id: "thames",
      type: "polyline",
      title: "Along the Thames",
      path: [
        { lat: 51.5009, lng: -0.1222 },
        { lat: 51.5085, lng: -0.1166 },
        { lat: 51.5098, lng: -0.1043 },
        { lat: 51.5085, lng: -0.0943 },
        { lat: 51.5079, lng: -0.0877 },
      ],
    },
  ];
  Maplace.createGoogleMap("#mixed-script-map", {
    apiKey: "YOUR_KEY",
    locations,
    list: { container: "#mixed-script-list" },
  });
</script>
```

### Bundler on MapLibre

`packages/maplace/examples/mixed/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>
  #mixed-maplibre-vanilla-map-and-list { display: flex; height: 24rem; }
  #mixed-maplibre-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #mixed-maplibre-vanilla-list { display: contents; }
  #mixed-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) {
    #mixed-maplibre-vanilla-map-and-list { flex-direction: column; }
    #mixed-maplibre-vanilla-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="mixed-maplibre-vanilla-map-and-list">
  <div id="mixed-maplibre-vanilla-map"></div>
  <div id="mixed-maplibre-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

const locations: Location[] = [
  { id: "tower-of-london", type: "marker", title: "Tower of London", lat: 51.5081, lng: -0.0759 },
  {
    id: "greenwich",
    type: "circle",
    title: "Greenwich",
    center: { lat: 51.4769, lng: -0.0005 },
    radius: 500,
  },
  {
    id: "hyde-park",
    type: "polygon",
    title: "Hyde Park",
    path: [
      { lat: 51.5115, lng: -0.1755 },
      { lat: 51.511, lng: -0.16 },
      { lat: 51.503, lng: -0.16 },
      { lat: 51.5035, lng: -0.1755 },
    ],
  },
  {
    id: "thames",
    type: "polyline",
    title: "Along the Thames",
    path: [
      { lat: 51.5009, lng: -0.1222 },
      { lat: 51.5085, lng: -0.1166 },
      { lat: 51.5098, lng: -0.1043 },
      { lat: 51.5085, lng: -0.0943 },
      { lat: 51.5079, lng: -0.0877 },
    ],
  },
];
createMapLibreMap("#mixed-maplibre-vanilla-map", {
  locations,
  list: { container: "#mixed-maplibre-vanilla-list" },
});
```

### Bundler on Google

`packages/maplace/examples/mixed/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>
  #mixed-vanilla-map-and-list { display: flex; height: 24rem; }
  #mixed-vanilla-map { flex: 1 1 auto; min-width: 0; }
  #mixed-vanilla-list { display: contents; }
  #mixed-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) {
    #mixed-vanilla-map-and-list { flex-direction: column; }
    #mixed-vanilla-list [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="mixed-vanilla-map-and-list">
  <div id="mixed-vanilla-map"></div>
  <div id="mixed-vanilla-list"></div>
</div>
<script type="module" src="./vanilla.ts"></script>
```

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

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

const locations: Location[] = [
  { id: "tower-of-london", type: "marker", title: "Tower of London", lat: 51.5081, lng: -0.0759 },
  {
    id: "greenwich",
    type: "circle",
    title: "Greenwich",
    center: { lat: 51.4769, lng: -0.0005 },
    radius: 500,
  },
  {
    id: "hyde-park",
    type: "polygon",
    title: "Hyde Park",
    path: [
      { lat: 51.5115, lng: -0.1755 },
      { lat: 51.511, lng: -0.16 },
      { lat: 51.503, lng: -0.16 },
      { lat: 51.5035, lng: -0.1755 },
    ],
  },
  {
    id: "thames",
    type: "polyline",
    title: "Along the Thames",
    path: [
      { lat: 51.5009, lng: -0.1222 },
      { lat: 51.5085, lng: -0.1166 },
      { lat: 51.5098, lng: -0.1043 },
      { lat: 51.5085, lng: -0.0943 },
      { lat: 51.5079, lng: -0.0877 },
    ],
  },
];
createGoogleMap("#mixed-vanilla-map", {
  locations,
  list: { container: "#mixed-vanilla-list" },
});
```

### React on MapLibre

`packages/maplace/examples/mixed/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>
  #mixed-maplibre-react-root .map-and-list { display: flex; height: 24rem; }
  #mixed-maplibre-react-root .map { flex: 1 1 auto; min-width: 0; }
  #mixed-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) {
    #mixed-maplibre-react-root .map-and-list { flex-direction: column; }
    #mixed-maplibre-react-root [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="mixed-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/mixed/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 places: Location[] = [
  { id: "tower-of-london", type: "marker", title: "Tower of London", lat: 51.5081, lng: -0.0759 },
  {
    id: "greenwich",
    type: "circle",
    title: "Greenwich",
    center: { lat: 51.4769, lng: -0.0005 },
    radius: 500,
  },
  {
    id: "hyde-park",
    type: "polygon",
    title: "Hyde Park",
    path: [
      { lat: 51.5115, lng: -0.1755 },
      { lat: 51.511, lng: -0.16 },
      { lat: 51.503, lng: -0.16 },
      { lat: 51.5035, lng: -0.1755 },
    ],
  },
  {
    id: "thames",
    type: "polyline",
    title: "Along the Thames",
    path: [
      { lat: 51.5009, lng: -0.1222 },
      { lat: 51.5085, lng: -0.1166 },
      { lat: 51.5098, lng: -0.1043 },
      { lat: 51.5085, lng: -0.0943 },
      { lat: 51.5079, lng: -0.0877 },
    ],
  },
];

function Mixed() {
  return (
    <MaplaceProvider locations={places}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createMapLibreAdapter} className="map" />
        <LocationList />
      </div>
    </MaplaceProvider>
  );
}

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

### React on Google

`packages/maplace/examples/mixed/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>
  #mixed-react-root .map-and-list { display: flex; height: 24rem; }
  #mixed-react-root .map { flex: 1 1 auto; min-width: 0; }
  #mixed-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) {
    #mixed-react-root .map-and-list { flex-direction: column; }
    #mixed-react-root [role="listbox"] { flex: none; max-height: 40%; }
  }
</style>
<div id="mixed-react-root"></div>
<script type="module" src="./react.tsx"></script>
```

`packages/maplace/examples/mixed/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 places: Location[] = [
  { id: "tower-of-london", type: "marker", title: "Tower of London", lat: 51.5081, lng: -0.0759 },
  {
    id: "greenwich",
    type: "circle",
    title: "Greenwich",
    center: { lat: 51.4769, lng: -0.0005 },
    radius: 500,
  },
  {
    id: "hyde-park",
    type: "polygon",
    title: "Hyde Park",
    path: [
      { lat: 51.5115, lng: -0.1755 },
      { lat: 51.511, lng: -0.16 },
      { lat: 51.503, lng: -0.16 },
      { lat: 51.5035, lng: -0.1755 },
    ],
  },
  {
    id: "thames",
    type: "polyline",
    title: "Along the Thames",
    path: [
      { lat: 51.5009, lng: -0.1222 },
      { lat: 51.5085, lng: -0.1166 },
      { lat: 51.5098, lng: -0.1043 },
      { lat: 51.5085, lng: -0.0943 },
      { lat: 51.5079, lng: -0.0877 },
    ],
  },
];

function Mixed() {
  return (
    <MaplaceProvider locations={places}>
      <div className="map-and-list">
        <MaplaceMap createAdapter={createGoogleAdapter} className="map" />
        <LocationList />
      </div>
    </MaplaceProvider>
  );
}

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