Flight paths
Great circles from one city to eight, the scheduled ones dashed; slide the flight to New York along its way.
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>
<!-- 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>,
);How it works
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.
- 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.