Editable polyline
A polyline to edit: a trail, with places along it.
Map and code
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>,
);How it works
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.
- 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>).