Trade routes
Air and sea trade lanes by colour; hover one, pick one for its volume.
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>
<!-- 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>,
);How it works
Sea and air lanes between ports and airports, each a bowed line in its mode’s colour, listed under Sea and Air.
- 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>).