前面两篇其实都是为了写一下leaflet-heatmap.js
最后搜了一下github https://github.com/Leaflet/Leaflet.heat
加载了leaflet.js和heatmap.js,就可以用leaflet-heatmap.js来绘制热力地图了。
首先,这是要展示的数据,有max代表所有数据的最大值,lat和Ing代表经纬度的值,count是要展示的数据,后面配置会有讲到,所以max应该是count中的最大值。
// don't forget to include leaflet-heatmap.js
var testData = {
max: 8,
data: [{lat: 24.6408, lng:46.7728, count: 3},{lat: 50.75, lng:-1.55, count: 1}, ...]
};
很熟悉,就是我们讲leaflet的基础层的初始化。
var baseLayer = L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
attribution: '...',
maxZoom: 18
}
);
cfg中所有heatmapjs的参数都可以用。另外加了额外的参数,都有说明
var cfg = {
// radius should be small ONLY if scaleRadius is true (or small radius is intended)
// if scal