WebGL Heatmap Leaflet Plugin
A Leaflet plugin for @pyalot's webgl heatmap library.
As @pyalot explains in his post, High Performance JS heatmaps, sometimes there is a need to be able to draw hundreds of thousands of data points to a map (and not have your browser crash due to lag).
We used his library to create a WebGL alternative to Leaflet's existing heatmap plugins.
It uses the following existing options in the library:
- gradientTexture (use a PNG instead of default green to red)
- alphaRange (show transparency)
See the example
Installation
via npm:
npm install leaflet-webgl-heatmap --save
Usage
Set up your map
var base = L;var map = L;
Initialize Heatmap
var heatmap = size: diameter-in-meters;
OR in pixels (doesn't scale with zoom levels):
var heatmap = size: diameter-in-pixels units: 'px';
Add Data
You should have an array of arrays in format: [[lat, lng]...]
or be explicit with the point intensities: [[lat, lng, intensity]...]
var dataPoints = 446674 -635703 37 446826 -637552 34 446325 -635852 41 446467 -634696 67 446804 -63487 64 446622 -635364 40 44603 - 63743 52;
With this you can add the whole dataset with heatmap.setData(dataPoints)
.
Add heatmap to map
map;
Options
- size (in meters or pixels)
- units (m or px)
- opacity (for the canvas element)
- gradientTexture (image url or image)
- alphaRange (adjust transparency by changing to value between 0 and 1)
Methods
- multiply (alter the intensity values of all points by a given number)
License
- MIT: see mit-license