如何在 ngx-leaflet 中放置热图?

Car*_*zón 2 heatmap leaflet typescript angular ngx-leaflet

我想在 ngx-leaflet 地图上放置一个热图(使用 angular),如下图所示。

我怎样才能做到这一点?

这是示例的演示

kbo*_*oul 7

安装传单、ngx-leaflet、@types/leaflet

npm install leaflet
npm install leaflet.heat
npm install @asymmetrik/ngx-leaflet
npm install --save-dev @types/leaflet
Run Code Online (Sandbox Code Playgroud)

在 angular.json 中导入 Leaflet.css

  "styles": ["../node_modules/leaflet/dist/leaflet.css", "styles.css"]
Run Code Online (Sandbox Code Playgroud)

安装 Leaflet.heat 并将其导入 comp.ts,从资产中导入要使用的地理数据

import 'leaflet.heat/dist/leaflet-heat.js'
import { addressPoints } from '../assets/realworld.10000'
Run Code Online (Sandbox Code Playgroud)

侦听 onMapReady 事件获取对地图的引用并将热图添加到地图

onMapReady(map) {
    let newAddressPoints = addressPoints.map(function (p) { return [p[0], p[1]]; });
    const heat = L.heatLayer(newAddressPoints).addTo(map);
}
Run Code Online (Sandbox Code Playgroud)

演示