首先下载包
npm install leaflet
npm install heatmap.js
引入
import * as L from 'leaflet'
import 'leaflet/dist/leaflet.css'
import 'heatmap.js'
import HeatmapOverlay from 'heatmap.js/plugins/leaflet-heatmap'
创建地图
全局变量
window.heatmaplayer = null; //定义全局图层变量
html部分:
<div id="map"></div>
data部分
cfg: {
// radius should be small ONLY if scaleRadius is true (or small radius is intended)
// if scaleRadius is false it will be the constant radius used in pixels
"radius": 0.1,
"maxOpacity": .8,
// scales the radius based on map zoom
"scaleRadius": true,
// if set to false the heatmap uses the global maximum for colorization
// if activated: uses the data maximum within the current map boundaries
// (there will always be a red spot with useLocalExtremas true)
"useLocalExtrema": true,
// which field name in your data represents the latitude - default "lat"
latField: 'lat',
// which field name in your data represents the longitude - default "lng"
lngField: 'lng',
// which field name in your data represents the data value - default "value"
valueField: 'count'
}
模拟数据
data: {
max: 15,
data: [
{
lat: '',//经纬度
lng: '',
count: 0.1 //值
},
...
]
}
js部分
let map = L.map('map', {
center: [51.505, -0.09],
zoom: 13
});
window.map = map; //全局
heatmaplayer = new HeatmapOverlay(cfg) //创建heatmap图层
heatmaplayer.addTo(map)//加到地图上
//设置数据
heatmaplayer.setData(this.data)
参考文章链接
https://leafletjs.com/reference-1.6.0.html#map-example
https://www.patrick-wied.at/static/heatmapjs/example-heatmap-leaflet.html
https://www.patrick-wied.at/static/heatmapjs/docs.html
https://www.cnblogs.com/webbest/p/6380751.html
https://blog.youkuaiyun.com/seelingzheng/article/details/105963953
https://www.patrick-wied.at/static/heatmapjs/
https://www.jianshu.com/p/1a160f9aefb2