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.
Google Maps
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<maplace-map api-key="YOUR_KEY" list>
<maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome"></maplace-location>
<maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan"></maplace-location>
</maplace-map>MapLibre, no key
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<maplace-map list>
<maplace-location location-id="rome" lat="41.9028" lng="12.4964" title="Rome"></maplace-location>
<maplace-location location-id="milan" lat="45.4642" lng="9.19" title="Milan"></maplace-location>
</maplace-map>Install
npm and CDN script
Google Maps
npm install @maplacejs/maplaceMapLibre
npm install @maplacejs/maplace maplibre-glCDN script
Google Maps
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1.2.0/dist/maplace-element.iife.js"
integrity="sha384-OgwZw1NQ78VKxQUXntJyiiRILF/Ck2chxPi2kbY+gNOcSqZIIsBVXI1BAPbqs6LV" crossorigin="anonymous"></script>MapLibre
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1.2.0/dist/maplace-element-maplibre.iife.js"
integrity="sha384-NTx1K+93ZQC7ezi/smTAvSpiQCrdWid6IfMLQuIS6oT/63JARr9b+gD1devKzZqV" crossorigin="anonymous"></script>Maplace.js 1.2.0, checked by the browser against its hash.
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.
13 Circles
Areas in their own colours, with popups; resize the third and see its radius.
The historic centre, on foot.
Inside the ring road, by bike.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
The historic centre, on foot.
Inside the ring road, by bike.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!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><!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><!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><!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><!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>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;
}<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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;
}<!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>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>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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>,
);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-styleandeditableon<maplace-location>, a<template>inside each of the first two for its popup (Location attributes),selected-idon the map, andmaplace-locationeditandmaplace-locationchangelisteners (Events). - Script and Bundler:
type: "circle",radius,style,selectedStyle,contentandeditableon a location (Circles, Styles), andlocationEditwhile dragging andlocationChangeonce dropped (Events). - React: the same circles, their text in
dataforpopupContenton<MaplaceMap>, withonLocationEditandonLocationChangeon<MaplaceProvider>(Event props).
14 Editable polyline
A trail to edit, with places along it.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!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><!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><!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><!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><!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>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" },
});<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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" },
});<!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>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>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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>,
);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);listandlist-headingon the map (Map attributes). - Script and Bundler:
type: "polyline",pathandeditableon a location (Polylines), andlist: { container, heading }(List view options). - React: the same locations on
<MaplaceProvider>, and<LocationList heading="Along the trail" />beside the<MaplaceMap>(<LocationList>).
15 Flights
Great circles from one city to eight, the scheduled ones dashed; slide the flight to New York along its way.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!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><!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><!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><!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><!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>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)));<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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)));<!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>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>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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>,
);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);listandlist-headingon the map (Map attributes); and a few lines of script for the slider, once the map is ready (maplace.whenReady()), setting the flight’sprogressand the plane atMaplace.pointAlongthrough the element’slocationsproperty (Properties and methods). - The looks:
strokeDash: "dashed"in a flight’sstyle(Styles);active: trueandprogresson the flight in the air, its travelled part faded unlesstravelledStylesays otherwise (Polylines); the plane a marker atpointAlong(flight, progress)(A point along a line), moved with every new set of locations. - Script and Bundler:
type: "polyline",pathandgeodesicon each flight (Curves and great circles),listed: falseon each city (Common fields), andlist: { container, heading }(List view options). - React: the same locations on
<MaplaceProvider>, and<LocationList heading="Flights from London" />beside the<MaplaceMap>(<LocationList>). - On MapLibre, a globe:
globeon the map (globe: truein the options; in React,createAdapter={() => createMapLibreAdapter({ globe: true })}) opens it as the earth, with a “Globe” toggle that flattens it (Globe). The globe shows London’s half: turn it, or flatten it, to see every flight. Google’s map has no globe.
16 Trade lanes
Air and sea lanes by colour; hover one, pick one for its volume.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!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><!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><!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><!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><!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>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" },
});<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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" },
});<!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>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>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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>,
);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), andlistandlist-headingon the map (Map attributes). - Script and Bundler:
curveon each lane (Curves and great circles), itsgroup, itsstyle,hoveredStyleandselectedStyle(Styles), its volume ascontent, andlist: { container, heading }(List view options). - React: the same locations on
<MaplaceProvider>, and<LocationList heading="Trade lanes" />beside the<MaplaceMap>(<LocationList>).
17 Editable polygon
An area to edit: drag a corner, and the edit is written back.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!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><!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><!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><!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><!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>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));<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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));<!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>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>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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>,
);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), and amaplace-locationchangelistener (Events). - Script and Bundler:
type: "polygon",pathandeditableon a location (Polygons), and alocationChangelistener (Events). - React: the same location, with
onLocationChangeon<MaplaceProvider>(Event props).
18 Markers and shapes together
A marker, a circle, an area and a line on one map and in one list.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!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><!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><!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><!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><!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>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" },
});<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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" },
});<!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>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>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<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>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>,
);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:
liston the map, and a<script type="application/json">inside<maplace-map>holding all four, as a path takes more than an attribute (Data). - Script and Bundler:
typeon each location (Markers, Circles, Polylines, Polygons), andlist: { container }(List view options). - React: the same locations on
<MaplaceProvider>, and<LocationList />beside the<MaplaceMap>(<LocationList>).