<div id="sigma-container"></div>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
import bindLeafletLayer, { graphToLatlng } from "@sigma/layer-leaflet";
import type { FeatureCollection } from "geojson";
import Graph from "graphology";
import Sigma from "sigma";
import { DEFAULT_STYLES } from "sigma/types";
const container = document.getElementById("sigma-container") as HTMLElement;
const graph = new Graph();
graph.addNode("paris", { x: 0, y: 0, lat: 48.8566, lng: 2.3522, label: "Paris" });
graph.addNode("london", { x: 0, y: 0, lat: 51.5074, lng: -0.1278, label: "London" });
graph.addEdge("paris", "london");
const renderer = new Sigma(graph, container, {
labelRenderedSizeThreshold: 0,
nodes: [DEFAULT_STYLES.nodes, { color: "black", size: 0.004 }],
edges: [DEFAULT_STYLES.edges, { color: "black", size: 0.001 }],
const { map } = bindLeafletLayer(renderer);
// Approximate Channel Tunnel route as inline GeoJSON
const channelTunnelGeoJSON: FeatureCollection = {
type: "FeatureCollection",
properties: { name: "Channel Tunnel (approximate)" },
// Add GeoJSON layer to the map
L.geoJSON(channelTunnelGeoJSON).addTo(map);
// Click on the stage to place a marker
let markerOnClick: null | L.Marker = null;
renderer.on("clickStage", (e) => {
const graphCoords = renderer.viewportToGraph({ x: e.event.x, y: e.event.y });
const geoCoords = graphToLatlng(graphCoords);
if (markerOnClick) markerOnClick.remove();
markerOnClick = L.marker(geoCoords);
markerOnClick.addTo(map);