ALPHA plugin for heatmap.js to add heatmaps to leaflet.
This is an enhanced version of leaflet-heatmap that provides greater control over how data points are grouped to create a heatmap.
Most heatmaps provide little control over how data is grouped beyond a pixel radius.
For many use-cases that is not enough - we often need to know exactly what data is in each cluster.
This plugin provides two ways of doing this better, you can either:
- Define the radius in meters instead of pixels; and/or
- Define a grid of cells which are used for value binning.
// define options
const options = {
heatBin: {
enabled: true,
cellSizeKm: 0.25, // e.g. bin values into 250m grid cells
maxFactor: 0.8, // heatmap max value will be multiplied by maxFactor
showBinGrid: false // a debugging option, plots the binning grid on the map*
},
// plus any options from heatmap.js core
radius: 20,
useLocalExtrema: true,
onExtremaChange: function(data) {
console.log(data);
}
};
const layer = L.heatBin(options);
layer.setData(myData);
// define options
const options = {
fixedRadius: true,
radiusMeters: 100
};
const layer = L.heatBin(options);
layer.setData(myData);
Essentially the same as vanilla
heatmap.js, with the addition of an optional param: uid
.
When uid
is specified and heatBin is enabled, a data point is only counted once per cell, per uid
.
const points = [
{
lat: '<lat>',
lng: '<lng>'',
value: 10,
uid: '<uid>' // optional
}
]
npm install leaflet-heatbin --save
This plugin has external dependencies:
To use this plugin, you either need to:
- load these dependencies yourself (prior to loading
leaflet-heatbin
); or - use the standalone version with dependencies bundled, in
dist/leaflet-heatbin-standalone.js
method | params | description |
---|---|---|
isActive |
check if the particle layer is currently active on the map | |
setData |
data: {Object} |
update the layer with new data object |
update |
update the layer/trigger redraw | |
getLatLngBounds |
data: {Object} , optional |
Returns leaflet LatLngBounds of supplied, or layer data |
getGridInfo |
Get information about the grid used for binning |
When binning is enabled, a grid of cells is generated using turf, which is then used to cluster data points by grid cell indices.
If you're interested to see how your data is being gridded, you can set the showBinGrid
to true to see the grid at work:
MIT License (MIT)