# Circles

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

## How it works

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.

- **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)).

## Code

### 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>,
);
```
