antv-l7/stories/Map/components/amap2demo_heatmap.tsx

78 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-04-26 15:23:42 +08:00
import {
ILngLat,
PointLayer,
PolygonLayer,
Scene,
HeatmapLayer,
} from '@antv/l7';
import { GaodeMap, GaodeMap2 } from '@antv/l7-maps';
import * as React from 'react';
export default class Amap2demo_heatmap extends React.Component {
// @ts-ignore
private scene: Scene;
public componentWillUnmount() {
this.scene.destroy();
}
public async componentDidMount() {
const scene = new Scene({
id: 'map',
map: new GaodeMap2({
pitch: 0,
2021-04-26 15:23:42 +08:00
center: [127.5671666579043, 7.445038892195569],
zoom: 2.632456779444394,
}),
});
this.scene = scene;
scene.on('loaded', () => {
fetch(
2021-04-26 15:23:42 +08:00
'https://gw.alipayobjects.com/os/basement_prod/d3564b06-670f-46ea-8edb-842f7010a7c6.json',
)
2021-04-26 15:23:42 +08:00
.then((res) => res.json())
.then((data) => {
const layer = new HeatmapLayer({})
.source(data)
.shape('heatmap')
2021-04-26 15:23:42 +08:00
.size('mag', [0, 1.0]) // weight映射通道
.style({
intensity: 2,
radius: 20,
opacity: 1.0,
rampColors: {
colors: [
'#FF4818',
'#F7B74A',
'#FFF598',
'#91EABC',
'#2EA9A1',
2021-04-26 15:23:42 +08:00
'#206C7C',
].reverse(),
2021-04-26 15:23:42 +08:00
positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
},
});
scene.addLayer(layer);
2021-04-26 15:23:42 +08:00
});
});
}
public render() {
return (
<>
<div
id="map"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
</>
);
}
}