Skip to content

Repository files navigation

react-leaflet-d3

versionreact-leaflet compatibilitytravis builddependenciespeer dependenciesissuesdownloadsMIT License

React wrapper of @asymmetrik/leaflet-d3 for react-leaflet.

Leaflet D3 Provides a collection of D3.js based visualization plugins for Leaflet.

Demo

VisualizationDemo react-leaflet v1Demo react-leaflet v2
HexbinsCodePenCodePen
PingsCodePenCodePen

Tested with Leaflet 1.3.4 and React-Leaflet 1.9.1, React-Leaflet 2.1.4

Installation

Install via NPM

npm install --save react-leaflet-d3

react-leaflet-d3 requires d3 and d3-hexbin as peerDependency

(React, PropTypes, Leaflet, react-leaflet also should be installed)

npm install --save d3 d3-hexbin

Customize css

Usage example

HexbinLayer (with react-leaflet v1)

import{Map,TileLayer}from'react-leaflet';import{HexbinLayer}from'react-leaflet-d3';constoptions={colorScaleExtent: [1,undefined],radiusScaleExtent: [1,undefined],colorRange: ['#f7fbff','#ff0000'],radiusRange: [5,12],};<Mapcenter={[2.935403,101.448205]}zoom={10}><TileLayerurl="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'/><HexbinLayerdata={geoJsonData}{...options}/></Map>

HexbinLayer (with react-leaflet v2)

import{Map,TileLayer,withLeaflet}from'react-leaflet';import{HexbinLayer}from'react-leaflet-d3';constWrappedHexbinLayer=withLeaflet(HexbinLayer);constoptions={colorScaleExtent: [1,undefined],radiusScaleExtent: [1,undefined],colorRange: ['#f7fbff','#ff0000'],radiusRange: [5,12],};<Mapcenter={[2.935403,101.448205]}zoom={10}><TileLayerurl="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'/>{/* Use <WrappedHexbinLayer> where you would have used <HexbinLayer>. */}<WrappedHexbinLayerdata={geoJsonData}{...options}/></Map>
OptionTypeDefaultDescription
dataobject{}Required. A valid GeoJSON FeatureCollection object. Currently only supports Point geometry type.
radiusint12Sets the radius on the hexbin layer.
opacityfloat0.6Sets the opacity on the hexbin layer.
durationint200Sets the transition duration for the hexbin layer.
colorScaleExtentarray[ 1, undefined ]Sets the extent of the color scale for the hexbin layer.
radiusScaleExtentarray[ 1, undefined ]This is the same exact configuration option as colorScaleExtent, only applied to the radius extent.
colorRangearray[ '#f7fbff', '#08306b' ]Sets the range of the color scale used to fill the hexbins on the layer.
radiusRangearray[ 4, 12 ]Sets the range of the radius scale used to size the hexbins on the layer.
pointerEventsstringallThis value is passed directly to an element-level css style for pointer-events. You should only modify this config option if you want to change the mouse event behavior on hexbins. This will modify when the events are propagated based on the visibility state and/or part of the hexbin being hovered.

PingLayer (with react-leaflet v1)

import{Map,TileLayer}from'react-leaflet';import{PingLayer}from'react-leaflet-d3';ping(){this.pingLayer.ping([101.448205,2.935403],'myCustomCssClass');}<Mapcenter={[2.935403,101.448205]}zoom={10}><TileLayerurl="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'/><PingLayerref={(ref)=>{this.pingLayer=ref;}}radiusRange={[3,50]}/></Map>

PingLayer (with react-leaflet v2)

import{Map,TileLayer,withLeaflet}from'react-leaflet';import{PingLayer}from'react-leaflet-d3';constWrappedPingLayer=withLeaflet(PingLayer);ping(){this.pingLayer.ping([101.448205,2.935403],'myCustomCssClass');}<Mapcenter={[2.935403,101.448205]}zoom={10}><TileLayerurl="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'/>{/* Use <WrappedPingLayer> where you would have used <PingLayer>. */}<WrappedPingLayerref={(ref)=>{this.pingLayer=ref;}}radiusRange={[3,50]}/></Map>

Options Ping options

OptionTypeDefaultDescription
durationint800 Sets the transition duration for the ping layer.
fpsint32Sets the target framerate for the ping animation.
opacityRangearray[ 1, 0 ]Sets the range of the opacity scale used to fade out the pings as they age.
radiusRangearray[ 3, 15 ]Sets the range of the radius scale used to size the pings as they age.

API

Ping API

pingLayer.ping(coordinates, cssClassName) - doc

Submit a ping to the layer. The default data schema for the ping layer is:

[ [ lng1, lat1 ], [ lng2, lat2 ], [ lng3, lat3 ]... [ lngN, latN ] ]

Where the ping radius scale factor is fixed at 1.

Credits

Credits goes to all the contributors for the original work.

License

MIT License

About

React wrapper of @asymmetrik/leaflet-d3. Leaflet D3 Provides a collection of D3.js based visualization plugins for Leaflet.

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages