Open the data tab to explore the node designs created in this example.
The NetworkNode API supports a number of node styling properties.
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(); const red = "#FF1764";
const redWithAlpha = "rgba(255,0,0,0.3)";
const yellow = "#FFB92E";
const green = "#0FAB7C";
const darkGreen = "#407767";
const blue = "#2471A3";
const lightBlue = "#64C1DD";
const transparent = "rgba(0,0,0,0)";
export const networkData = {
largeRedNode: {
type: "node",
color: red,
size: 20,
latitude: -34.6,
longitude: -58.38,
label: {
text: "Serif label at left",
position: "w",
color: "black",
backgroundColor: red,
fontFamily: "serif",
fontSize: 12,
},
},
mediumYellowNode: {
type: "node",
color: yellow,
size: 12,
latitude: -26.2,
longitude: 28.03,
label: [
{
text: "Label below",
radius: 18,
position: "s",
color: "black",
backgroundColor: yellow,
},
{
text: "Square corners",
radius: 18,
border: { radius: 0 },
position: "e",
color: "black",
backgroundColor: yellow,
},
{
text: "Asymmetric corner radii",
radius: 18,
border: { radius: [10, 2, 10, 2] },
position: "w",
color: "black",
backgroundColor: yellow,
},
{
text: "Multiple\nlines\nlarge\nradius",
border: { radius: 40 },
position: "n",
color: "black",
backgroundColor: yellow,
},
],
},
smallGreenNode: {
type: "node",
color: green,
size: 4,
latitude: 28.7,
longitude: 77.1,
label: {
text: "Label above",
position: "n",
radius: 10,
color: "black",
backgroundColor: green,
},
},
borderOnlyNode: {
type: "node",
color: transparent,
size: 14,
border: {
color: lightBlue,
width: 4,
},
latitude: -35.3,
longitude: 149.1,
label: {
text: "Label without background",
position: "s",
color: lightBlue,
fontSize: 12,
radius: 16,
backgroundColor: transparent,
},
},
translucentRedNode: {
type: "node",
color: redWithAlpha,
size: 12,
latitude: 35.68,
longitude: 139.65,
label: [
{
text: "One",
position: "n",
color: "white",
backgroundColor: redWithAlpha,
},
{
text: "Two",
position: "w",
color: "white",
backgroundColor: redWithAlpha,
},
{
text: "Three",
position: "e",
color: "white",
backgroundColor: redWithAlpha,
},
{
text: "Four labels",
position: "s",
color: "white",
backgroundColor: redWithAlpha,
},
],
},
greenNodeWithThickBorder: {
type: "node",
color: green,
size: 12,
border: {
color: darkGreen,
width: 16,
},
latitude: 52.52,
longitude: 13.4,
label: {
text: "Label at top right",
position: 45,
color: "white",
fontSize: 12,
radius: 24,
backgroundColor: darkGreen,
},
},
blueNodeWithBorder: {
type: "node",
color: lightBlue,
size: 14,
border: {
color: blue,
width: 4,
},
latitude: 34.05,
longitude: -118.24,
label: {
text: "Label with border",
position: "n",
color: "black",
backgroundColor: lightBlue,
border: {
color: blue,
width: 4,
},
},
},
link1: {
type: "link",
id1: "largeRedNode",
id2: "mediumYellowNode",
},
link2: {
type: "link",
id1: "mediumYellowNode",
id2: "smallGreenNode",
},
link3: {
type: "link",
id1: "smallGreenNode",
id2: "borderOnlyNode",
},
link4: {
type: "link",
id1: "borderOnlyNode",
id2: "translucentRedNode",
},
link5: {
type: "link",
id1: "translucentRedNode",
id2: "greenNodeWithThickBorder",
},
link6: {
type: "link",
id1: "greenNodeWithThickBorder",
id2: "blueNodeWithBorder",
},
link7: {
type: "link",
id1: "blueNodeWithBorder",
id2: "largeRedNode",
},
}; <!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 />); const red = "#FF1764";
const redWithAlpha = "rgba(255,0,0,0.3)";
const yellow = "#FFB92E";
const green = "#0FAB7C";
const darkGreen = "#407767";
const blue = "#2471A3";
const lightBlue = "#64C1DD";
const transparent = "rgba(0,0,0,0)";
export const networkData = {
largeRedNode: {
type: "node",
color: red,
size: 20,
latitude: -34.6,
longitude: -58.38,
label: {
text: "Serif label at left",
position: "w",
color: "black",
backgroundColor: red,
fontFamily: "serif",
fontSize: 12,
},
},
mediumYellowNode: {
type: "node",
color: yellow,
size: 12,
latitude: -26.2,
longitude: 28.03,
label: [
{
text: "Label below",
radius: 18,
position: "s",
color: "black",
backgroundColor: yellow,
},
{
text: "Square corners",
radius: 18,
border: { radius: 0 },
position: "e",
color: "black",
backgroundColor: yellow,
},
{
text: "Asymmetric corner radii",
radius: 18,
border: { radius: [10, 2, 10, 2] },
position: "w",
color: "black",
backgroundColor: yellow,
},
{
text: "Multiple\nlines\nlarge\nradius",
border: { radius: 40 },
position: "n",
color: "black",
backgroundColor: yellow,
},
],
},
smallGreenNode: {
type: "node",
color: green,
size: 4,
latitude: 28.7,
longitude: 77.1,
label: {
text: "Label above",
position: "n",
radius: 10,
color: "black",
backgroundColor: green,
},
},
borderOnlyNode: {
type: "node",
color: transparent,
size: 14,
border: {
color: lightBlue,
width: 4,
},
latitude: -35.3,
longitude: 149.1,
label: {
text: "Label without background",
position: "s",
color: lightBlue,
fontSize: 12,
radius: 16,
backgroundColor: transparent,
},
},
translucentRedNode: {
type: "node",
color: redWithAlpha,
size: 12,
latitude: 35.68,
longitude: 139.65,
label: [
{
text: "One",
position: "n",
color: "white",
backgroundColor: redWithAlpha,
},
{
text: "Two",
position: "w",
color: "white",
backgroundColor: redWithAlpha,
},
{
text: "Three",
position: "e",
color: "white",
backgroundColor: redWithAlpha,
},
{
text: "Four labels",
position: "s",
color: "white",
backgroundColor: redWithAlpha,
},
],
},
greenNodeWithThickBorder: {
type: "node",
color: green,
size: 12,
border: {
color: darkGreen,
width: 16,
},
latitude: 52.52,
longitude: 13.4,
label: {
text: "Label at top right",
position: 45,
color: "white",
fontSize: 12,
radius: 24,
backgroundColor: darkGreen,
},
},
blueNodeWithBorder: {
type: "node",
color: lightBlue,
size: 14,
border: {
color: blue,
width: 4,
},
latitude: 34.05,
longitude: -118.24,
label: {
text: "Label with border",
position: "n",
color: "black",
backgroundColor: lightBlue,
border: {
color: blue,
width: 4,
},
},
},
link1: {
type: "link",
id1: "largeRedNode",
id2: "mediumYellowNode",
},
link2: {
type: "link",
id1: "mediumYellowNode",
id2: "smallGreenNode",
},
link3: {
type: "link",
id1: "smallGreenNode",
id2: "borderOnlyNode",
},
link4: {
type: "link",
id1: "borderOnlyNode",
id2: "translucentRedNode",
},
link5: {
type: "link",
id1: "translucentRedNode",
id2: "greenNodeWithThickBorder",
},
link6: {
type: "link",
id1: "greenNodeWithThickBorder",
id2: "blueNodeWithBorder",
},
link7: {
type: "link",
id1: "blueNodeWithBorder",
id2: "largeRedNode",
},
}; <!doctype html>
<html>
<body>
<div id="mw"></div>
<script type="module" src="./code.jsx"></script>
</body>
</html>