The network layer is used to add graph visualizations to your map. This graph shows cities as fixed nodes with links between them.
NetworkLayerAPI- Network Layer 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 });
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>
<body>
<div id="mw"></div>
<script type="module" src="./code.js"></script>
</body>
</html> import React 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 };
function Demo() {
return (
<MapWeave options={mapWeaveOptions}>
<NetworkLayer data={networkData} />
</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>
<body>
<div id="mw"></div>
<script type="module" src="./code.jsx"></script>
</body>
</html>