leaflet-network
ALPHA leaflet plugin to visualise (weighted) network connectivity between spatial data points.
It uses d3.js v4 to visualise the network connections on a L.SVG
layer.
There is an interactive notebook example here: https://beta.observablehq.com/@danwild/network-connectivity-template
Node connectivity weights can be represented:
- GLOBAL: node connection weights are scaled against all other connections in the matrix
(only
SOURCE
/ downstreamdisplayMode
supported). - LOCAL: node connection weights are scaled to only the connections of the selected target.
- NONE: connection weights are ignored, simplified display.
This plugin only supports Leaflet ^v1.0.0.
install, build
- install:
npm install leaflet-network
- build:
gulp
usage
Init plugin with map and data (see gh-pages branch for full demo):
// create a basemapvar canvas = L; // setup our leaflet mapvar map = L; // create a layer control so we can show/hide network layervar layerControl = Lcontrollayers;layerControl; // init the network layervar networkLayer = L; // add layer as an overlaylayerControl;
public methods
method | params | description |
---|---|---|
update |
trigger a redraw of all elements using current target | |
setData |
data: {Object} |
update the layer with new data |
setOptions |
options: {Object} |
update the layer with new options |
setTarget |
id: {String} |
Set the active target node by id |
getTargetId |
Get ID of the active target node | |
setDisplayMode |
mode: {String} |
one of: SOURCE , SINK , ANY , BOTH |
getPointById |
id: {String} |
Get a node by id |
isActive |
Check if layer is active on the map | |
getLatLngBounds |
Returns leaflet LatLngBounds of the layer | |
getConnectionsDomain |
clipped: {Boolean} , Optional: data: {Object} |
Get the domain (min/max) of values in the data array (defaults to current) |
data format
var data = "properties": "lat": "" "lon": "" "id": "uid1" "connections": "uid1": 233 // connection score to self, ignored "uid2": 0 // null connection, could be omited "uid2": 37 // defines a connection score of 37 with point uid2 ...
shout outs
- Mike Bostock for d3.js
- d3noob for d3/leaflet/svg demo