heatmap-libs
v1.0.0
Published
Heatmap libraries including heatmap.js and Leaflet heatmap plugin
Downloads
18
Maintainers
Readme
heatmap-libs
A collection of heatmap libraries including heatmap.js and Leaflet heatmap plugin for creating beautiful heatmap visualizations.
Installation
npm install heatmap-libsUsage
Basic Heatmap
const { heatmap } = require('heatmap-libs');
// Create a heatmap instance
const heatmapInstance = heatmap.create({
container: document.getElementById('heatmap-container'),
radius: 40,
maxOpacity: 0.8,
minOpacity: 0,
blur: 0.85
});
// Add data points
heatmapInstance.addData({
x: 10,
y: 15,
value: 100
});Leaflet Heatmap
const L = require('leaflet');
const { HeatmapOverlay } = require('heatmap-libs');
// Create a map
const map = L.map('map').setView([51.505, -0.09], 13);
// Add tile layer
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Create heatmap overlay
const heatmapLayer = new HeatmapOverlay({
radius: 2,
maxOpacity: 0.8,
scaleRadius: true,
useLocalExtrema: true,
latField: 'lat',
lngField: 'lng',
valueField: 'count'
});
// Add heatmap data
const heatmapData = {
max: 100,
data: [
{lat: 51.505, lng: -0.09, count: 100},
{lat: 51.51, lng: -0.1, count: 80},
{lat: 51.49, lng: -0.08, count: 60}
]
};
heatmapLayer.setData(heatmapData);
map.addLayer(heatmapLayer);API Reference
Heatmap.js
The main heatmap library provides:
heatmap.create(config)- Create a new heatmap instanceheatmapInstance.addData(data)- Add data points to the heatmapheatmapInstance.setData(data)- Set all data at onceheatmapInstance.configure(config)- Update configurationheatmapInstance.getDataURL()- Get heatmap as data URL
Leaflet Heatmap Plugin
The Leaflet plugin provides:
HeatmapOverlay- Leaflet layer for displaying heatmaps on maps- Supports automatic scaling with zoom levels
- Integrates seamlessly with Leaflet maps
Configuration Options
Heatmap.js Configuration
container- DOM element to render the heatmapradius- Default radius for data pointsmaxOpacity- Maximum opacity (0-1)minOpacity- Minimum opacity (0-1)blur- Blur factor (0-1)gradient- Custom color gradient
Leaflet Heatmap Configuration
radius- Point radiusmaxOpacity- Maximum opacityscaleRadius- Scale radius with zoomuseLocalExtrema- Use local min/max valueslatField- Latitude field namelngField- Longitude field namevalueField- Value field name
License
MIT
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
