2019-11-25 15:27:56 +08:00
|
|
|
import { HeatmapLayer, Scene } from '@antv/l7';
|
2019-11-26 17:51:29 +08:00
|
|
|
import { Mapbox } from '@antv/l7-maps';
|
2019-11-21 13:44:32 +08:00
|
|
|
// @ts-ignore
|
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
export default class HeatMapLayerDemo extends React.Component {
|
2019-11-25 15:27:56 +08:00
|
|
|
// @ts-ignore
|
2019-11-21 13:44:32 +08:00
|
|
|
private scene: Scene;
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
this.scene.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async componentDidMount() {
|
|
|
|
const response = await fetch(
|
|
|
|
'https://gw.alipayobjects.com/os/basement_prod/d3564b06-670f-46ea-8edb-842f7010a7c6.json',
|
|
|
|
);
|
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
2019-11-26 17:51:29 +08:00
|
|
|
map: new Mapbox({
|
|
|
|
center: [121.268, 30.3628],
|
|
|
|
pitch: 0,
|
2020-01-18 23:16:56 +08:00
|
|
|
style: 'dark',
|
2019-11-26 17:51:29 +08:00
|
|
|
zoom: 2,
|
|
|
|
}),
|
2019-11-21 13:44:32 +08:00
|
|
|
});
|
2020-01-18 23:16:56 +08:00
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
const layer = new HeatmapLayer();
|
2019-11-21 13:44:32 +08:00
|
|
|
layer
|
2020-01-27 11:27:29 +08:00
|
|
|
.source(data)
|
2020-01-18 23:16:56 +08:00
|
|
|
.shape('heatmap')
|
|
|
|
.size('mag', [0, 1.0]) // weight映射通道
|
2019-11-21 13:44:32 +08:00
|
|
|
.style({
|
|
|
|
intensity: 2,
|
|
|
|
radius: 20,
|
2020-01-18 23:16:56 +08:00
|
|
|
opacity: 1.0,
|
2019-11-21 13:44:32 +08:00
|
|
|
rampColors: {
|
|
|
|
colors: [
|
2020-01-18 23:16:56 +08:00
|
|
|
'#FF4818',
|
|
|
|
'#F7B74A',
|
|
|
|
'#FFF598',
|
|
|
|
'#91EABC',
|
|
|
|
'#2EA9A1',
|
|
|
|
'#206C7C',
|
|
|
|
].reverse(),
|
2019-11-25 15:27:56 +08:00
|
|
|
positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
|
2019-11-21 13:44:32 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
scene.addLayer(layer);
|
2020-01-27 11:27:29 +08:00
|
|
|
scene.on('loaded', () => {
|
|
|
|
console.log('scene loaded');
|
2020-01-18 23:16:56 +08:00
|
|
|
});
|
2019-11-21 13:44:32 +08:00
|
|
|
this.scene = scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
id="map"
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|