Markers and shapes together
A marker, a circle, an area and a line on one map and in one list.
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 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>,
);How it works
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.
- 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>).