Fixed nodes are fixed to their coordinates on the map. If your data contains nodes without coordinates, MapWeave positions them in appropriate locations and allows you to drag 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 },
});
mapweave.addLayer(
new NetworkLayer({
data: networkData,
})
);
mapweave.fitBounds(); export const networkData = {
node1: {
type: "node",
latitude: 42.6334,
longitude: -71.3162,
color: "#2471a3",
},
node2: {
type: "node",
latitude: 52.1951,
longitude: 0.1313,
color: "#2471a3",
},
link1: {
type: "link",
id1: "node1",
id2: "node2",
color: "#34495e",
},
"floating-node1": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link2: {
type: "link",
id1: "floating-node1",
color: "#34495e",
id2: "node2",
},
"floating-node7": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link7: {
type: "link",
id1: "floating-node7",
color: "#34495e",
id2: "node1",
},
"floating-node2": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link3: {
type: "link",
id1: "floating-node2",
color: "#34495e",
id2: "node2",
},
"floating-node8": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link8: {
type: "link",
id1: "floating-node8",
color: "#34495e",
id2: "node1",
},
"floating-node3": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link4: {
type: "link",
id1: "floating-node3",
color: "#34495e",
id2: "node2",
},
"floating-node9": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link9: {
type: "link",
id1: "floating-node9",
color: "#34495e",
id2: "node1",
},
"floating-node4": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link5: {
type: "link",
id1: "floating-node4",
color: "#34495e",
id2: "node2",
},
"floating-node10": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link10: {
type: "link",
id1: "floating-node10",
color: "#34495e",
id2: "node1",
},
"floating-node5": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link6: {
type: "link",
id1: "floating-node5",
color: "#34495e",
id2: "node2",
},
"floating-node11": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link11: {
type: "link",
id1: "floating-node11",
color: "#34495e",
id2: "node1",
},
}; <!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 = {
node1: {
type: "node",
latitude: 42.6334,
longitude: -71.3162,
color: "#2471a3",
},
node2: {
type: "node",
latitude: 52.1951,
longitude: 0.1313,
color: "#2471a3",
},
link1: {
type: "link",
id1: "node1",
id2: "node2",
color: "#34495e",
},
"floating-node1": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link2: {
type: "link",
id1: "floating-node1",
color: "#34495e",
id2: "node2",
},
"floating-node7": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link7: {
type: "link",
id1: "floating-node7",
color: "#34495e",
id2: "node1",
},
"floating-node2": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link3: {
type: "link",
id1: "floating-node2",
color: "#34495e",
id2: "node2",
},
"floating-node8": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link8: {
type: "link",
id1: "floating-node8",
color: "#34495e",
id2: "node1",
},
"floating-node3": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link4: {
type: "link",
id1: "floating-node3",
color: "#34495e",
id2: "node2",
},
"floating-node9": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link9: {
type: "link",
id1: "floating-node9",
color: "#34495e",
id2: "node1",
},
"floating-node4": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link5: {
type: "link",
id1: "floating-node4",
color: "#34495e",
id2: "node2",
},
"floating-node10": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link10: {
type: "link",
id1: "floating-node10",
color: "#34495e",
id2: "node1",
},
"floating-node5": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link6: {
type: "link",
id1: "floating-node5",
color: "#34495e",
id2: "node2",
},
"floating-node11": {
color: "#27ae60",
scale: 0.75,
type: "node",
},
link11: {
type: "link",
id1: "floating-node11",
color: "#34495e",
id2: "node1",
},
}; <!doctype html>
<html>
<body>
<div id="mw"></div>
<script type="module" src="./code.jsx"></script>
</body>
</html>