By default, links are drawn as straight lines between nodes, but it is also possible to show them as geodesic links or routes.
Use the checkboxes to explore how geodesic links and routes are displayed when the geodesic and showRoutes options are enabled.
NetworkLayerOptionsAPI- Geodesic Links docs
- Routes docs
import { MapWeave } from "mapweave/mapbox";
import { NetworkLayer } from "mapweave/layers";
import { networkData } from "./data";
const mapweave = new MapWeave({ container: "mw", options: { accessToken: VITE_MAPBOX_API_KEY } });
const networkLayer = new NetworkLayer({
data: networkData,
options: { links: { geodesic: true } },
});
mapweave.addLayer(networkLayer);
mapweave.fitBounds(); export const networkData = {
"Buenos Aires": {
type: "node",
color: "#2471a3",
latitude: -34.6,
longitude: -58.38,
},
Johannesburg: {
type: "node",
color: "#2471a3",
latitude: -26.2,
longitude: 28.03,
},
Delhi: {
type: "node",
color: "#2471a3",
latitude: 28.7,
longitude: 77.1,
},
Canberra: {
type: "node",
color: "#2471a3",
latitude: -35.3,
longitude: 149.1,
},
Tokyo: {
type: "node",
color: "#2471a3",
latitude: 35.68,
longitude: 139.65,
},
Berlin: {
type: "node",
color: "#2471a3",
latitude: 52.52,
longitude: 13.4,
},
"Los Angeles": {
type: "node",
color: "#2471a3",
latitude: 34.05,
longitude: -118.24,
},
"Buenos Aires-Johannesburg": {
type: "link",
id1: "Buenos Aires",
id2: "Johannesburg",
color: "#2471a3",
},
"Johannesburg-Delhi": {
type: "link",
id1: "Johannesburg",
id2: "Delhi",
color: "#2471a3",
},
"Delhi-Canberra": {
type: "link",
id1: "Delhi",
id2: "Canberra",
color: "#2471a3",
},
"Canberra-Tokyo": {
type: "link",
id1: "Canberra",
id2: "Tokyo",
color: "#2471a3",
},
"Tokyo-Berlin": {
type: "link",
id1: "Tokyo",
id2: "Berlin",
color: "#2471a3",
},
"Berlin-Los Angeles": {
type: "link",
id1: "Berlin",
id2: "Los Angeles",
color: "#2471a3",
},
"Los Angeles-Buenos Aires": {
type: "link",
id1: "Los Angeles",
id2: "Buenos Aires",
color: "#2471a3",
},
}; <!doctype html>
<html>
<head>
<link rel="stylesheet" href="@ci/theme/mw/css/examples.css" />
</head>
<body>
<div id="mw"></div>
<script type="module" src="./code.js"></script>
</body>
</html> import React, { useState } from "react";
import { createRoot } from "react-dom/client";
import { MapWeave } from "mapweave/react/mapbox";
import { NetworkLayer } from "mapweave/react/layers";
import { networkData } from "./data";
const mapWeaveOptions = { accessToken: VITE_MAPBOX_API_KEY };
const networkLayerOptions = { links: { geodesic: true } };
function Demo() {
return (
<MapWeave options={mapWeaveOptions}>
<NetworkLayer data={networkData} options={networkLayerOptions} />
</MapWeave>
);
}
const root = createRoot(document.getElementById("mw"));
root.render(<Demo />); export const networkData = {
"Buenos Aires": {
type: "node",
color: "#2471a3",
latitude: -34.6,
longitude: -58.38,
},
Johannesburg: {
type: "node",
color: "#2471a3",
latitude: -26.2,
longitude: 28.03,
},
Delhi: {
type: "node",
color: "#2471a3",
latitude: 28.7,
longitude: 77.1,
},
Canberra: {
type: "node",
color: "#2471a3",
latitude: -35.3,
longitude: 149.1,
},
Tokyo: {
type: "node",
color: "#2471a3",
latitude: 35.68,
longitude: 139.65,
},
Berlin: {
type: "node",
color: "#2471a3",
latitude: 52.52,
longitude: 13.4,
},
"Los Angeles": {
type: "node",
color: "#2471a3",
latitude: 34.05,
longitude: -118.24,
},
"Buenos Aires-Johannesburg": {
type: "link",
id1: "Buenos Aires",
id2: "Johannesburg",
color: "#2471a3",
},
"Johannesburg-Delhi": {
type: "link",
id1: "Johannesburg",
id2: "Delhi",
color: "#2471a3",
},
"Delhi-Canberra": {
type: "link",
id1: "Delhi",
id2: "Canberra",
color: "#2471a3",
},
"Canberra-Tokyo": {
type: "link",
id1: "Canberra",
id2: "Tokyo",
color: "#2471a3",
},
"Tokyo-Berlin": {
type: "link",
id1: "Tokyo",
id2: "Berlin",
color: "#2471a3",
},
"Berlin-Los Angeles": {
type: "link",
id1: "Berlin",
id2: "Los Angeles",
color: "#2471a3",
},
"Los Angeles-Buenos Aires": {
type: "link",
id1: "Los Angeles",
id2: "Buenos Aires",
color: "#2471a3",
},
}; <!doctype html>
<html>
<head>
<link rel="stylesheet" href="@ci/theme/mw/css/examples.css" />
</head>
<body>
<div id="mw"></div>
<script type="module" src="./code.jsx"></script>
</body>
</html>