Search

Style Links and Labels

Styling

Explore different styling options for links.

Style Links and Labels
View live example →

Open the data tab to explore the link designs created in this example.

The NetworkLink API supports a number of link 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 orange = "#FFC177";
const transparent = "rgba(0,0,0,0)";

export const networkData = {
  node1: { type: "node", latitude: -34.6, longitude: -58.38 },
  node2: { type: "node", latitude: -26.2, longitude: 28.03 },
  node3: {
    type: "node",
    latitude: 28.7,
    longitude: 77.1,
  },
  node4: {
    type: "node",
    latitude: -35.3,
    longitude: 149.1,
  },
  node5: {
    type: "node",
    latitude: 35.68,
    longitude: 139.65,
  },
  node6: {
    type: "node",
    latitude: 52.52,
    longitude: 60,
  },
  node7: {
    type: "node",
    latitude: 52.52,
    longitude: 0,
  },
  node8: {
    type: "node",
    latitude: 34.05,
    longitude: -118.24,
  },
  yellowLink: {
    type: "link",
    id1: "node1",
    id2: "node2",
    color: yellow,
    width: 4,
    end2: { arrow: true },
    label: {
      text: "16pt label\nwith one arrow",
      color: "black",
      backgroundColor: yellow,
      fontSize: 16,
    },
  },
  thinGreenLink: {
    type: "link",
    id1: "node2",
    id2: "node3",
    color: green,
    width: 1,
    label: {
      text: "8pt label",
      color: "black",
      backgroundColor: green,
      fontSize: 8,
    },
  },
  defaultWidthLightBlueLink: {
    type: "link",
    id1: "node3",
    id2: "node4",
    color: lightBlue,
    label: {
      text: "No background",
      color: lightBlue,
      fontSize: 12,
      backgroundColor: transparent,
    },
  },
  translucentRedLink: {
    type: "link",
    id1: "node4",
    id2: "node5",
    color: redWithAlpha,
    width: 6,
    label: {
      text: "Translucent link",
      color: "white",
      backgroundColor: redWithAlpha,
    },
  },
  wideDarkGreenLink: {
    type: "link",
    id1: "node5",
    id2: "node6",
    color: darkGreen,
    width: 18,
    flow: {
      velocity: 20,
      color: "rgba(200, 220, 200, 1.0)",
    },
    label: {
      text: "Wide link\nwith flow",
      color: "white",
      fontSize: 12,
      backgroundColor: green,
    },
  },
  lightBlueLink: {
    type: "link",
    id1: "node6",
    id2: "node7",
    color: lightBlue,
    width: 4,
    label: {
      text: "Label with border",
      color: "black",
      backgroundColor: lightBlue,
      border: {
        color: blue,
        width: 4,
      },
    },
  },
  orangeLink: {
    type: "link",
    id1: "node7",
    id2: "node8",
    color: orange,
    width: 7,
    end1: { arrow: true },
    end2: { arrow: true },
    label: {
      text: "Square corners\nand two arrows",
      border: { radius: 0 },
      color: "black",
      fontSize: 14,
      backgroundColor: orange,
    },
  },
  thickRedLink: {
    type: "link",
    id1: "node8",
    id2: "node1",
    color: red,
    width: 7,
    label: {
      text: "Serif label",
      color: "white",
      fontFamily: "serif",
      fontSize: 14,
      backgroundColor: red,
    },
  },
};
<!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 orange = "#FFC177";
const transparent = "rgba(0,0,0,0)";

export const networkData = {
  node1: { type: "node", latitude: -34.6, longitude: -58.38 },
  node2: { type: "node", latitude: -26.2, longitude: 28.03 },
  node3: {
    type: "node",
    latitude: 28.7,
    longitude: 77.1,
  },
  node4: {
    type: "node",
    latitude: -35.3,
    longitude: 149.1,
  },
  node5: {
    type: "node",
    latitude: 35.68,
    longitude: 139.65,
  },
  node6: {
    type: "node",
    latitude: 52.52,
    longitude: 60,
  },
  node7: {
    type: "node",
    latitude: 52.52,
    longitude: 0,
  },
  node8: {
    type: "node",
    latitude: 34.05,
    longitude: -118.24,
  },
  yellowLink: {
    type: "link",
    id1: "node1",
    id2: "node2",
    color: yellow,
    width: 4,
    end2: { arrow: true },
    label: {
      text: "16pt label\nwith one arrow",
      color: "black",
      backgroundColor: yellow,
      fontSize: 16,
    },
  },
  thinGreenLink: {
    type: "link",
    id1: "node2",
    id2: "node3",
    color: green,
    width: 1,
    label: {
      text: "8pt label",
      color: "black",
      backgroundColor: green,
      fontSize: 8,
    },
  },
  defaultWidthLightBlueLink: {
    type: "link",
    id1: "node3",
    id2: "node4",
    color: lightBlue,
    label: {
      text: "No background",
      color: lightBlue,
      fontSize: 12,
      backgroundColor: transparent,
    },
  },
  translucentRedLink: {
    type: "link",
    id1: "node4",
    id2: "node5",
    color: redWithAlpha,
    width: 6,
    label: {
      text: "Translucent link",
      color: "white",
      backgroundColor: redWithAlpha,
    },
  },
  wideDarkGreenLink: {
    type: "link",
    id1: "node5",
    id2: "node6",
    color: darkGreen,
    width: 18,
    flow: {
      velocity: 20,
      color: "rgba(200, 220, 200, 1.0)",
    },
    label: {
      text: "Wide link\nwith flow",
      color: "white",
      fontSize: 12,
      backgroundColor: green,
    },
  },
  lightBlueLink: {
    type: "link",
    id1: "node6",
    id2: "node7",
    color: lightBlue,
    width: 4,
    label: {
      text: "Label with border",
      color: "black",
      backgroundColor: lightBlue,
      border: {
        color: blue,
        width: 4,
      },
    },
  },
  orangeLink: {
    type: "link",
    id1: "node7",
    id2: "node8",
    color: orange,
    width: 7,
    end1: { arrow: true },
    end2: { arrow: true },
    label: {
      text: "Square corners\nand two arrows",
      border: { radius: 0 },
      color: "black",
      fontSize: 14,
      backgroundColor: orange,
    },
  },
  thickRedLink: {
    type: "link",
    id1: "node8",
    id2: "node1",
    color: red,
    width: 7,
    label: {
      text: "Serif label",
      color: "white",
      fontFamily: "serif",
      fontSize: 14,
      backgroundColor: red,
    },
  },
};
<!doctype html>
<html>
  <body>
    <div id="mw"></div>
    <script type="module" src="./code.jsx"></script>
  </body>
</html>

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.