antv-l7/stories/Layers/components/Point.tsx

84 lines
1.9 KiB
TypeScript
Raw Normal View History

import { PointLayer, Scene } from '@antv/l7';
import { GaodeMap, Mapbox } from '@antv/l7-maps';
2019-10-29 17:33:37 +08:00
import * as React from 'react';
// @ts-ignore
2019-10-29 17:33:37 +08:00
import data from '../data/data.json';
export default class Point3D extends React.Component {
// @ts-ignore
2019-10-29 17:33:37 +08:00
private scene: Scene;
public componentWillUnmount() {
this.scene.destroy();
}
public async componentDidMount() {
2019-10-29 17:33:37 +08:00
const scene = new Scene({
2020-03-16 23:31:15 +08:00
id: 'map',
2021-01-12 19:46:04 +08:00
pickBufferScale: 1.0,
map: new GaodeMap({
2020-03-16 23:31:15 +08:00
style: 'light',
center: [-121.24357, 37.58264],
pitch: 0,
2021-04-01 21:05:33 +08:00
zoom: 6.45,
}),
2019-10-29 17:33:37 +08:00
});
2020-01-16 18:22:38 +08:00
scene.on('loaded', () => {
2020-03-16 23:31:15 +08:00
fetch(
'https://gw.alipayobjects.com/os/basement_prod/6c4bb5f2-850b-419d-afc4-e46032fc9f94.csv',
)
.then((res) => res.text())
.then((data) => {
const pointLayer = new PointLayer({})
2021-04-06 18:00:53 +08:00
.source(data.slice(0, 1000), {
2020-03-16 23:31:15 +08:00
parser: {
type: 'csv',
x: 'Longitude',
y: 'Latitude',
},
})
.shape('circle')
2021-04-01 21:05:33 +08:00
.size(16)
.active(true)
2021-04-01 21:05:33 +08:00
.select({
2020-04-03 19:36:17 +08:00
color: 'red',
})
2020-03-16 23:31:15 +08:00
.color('Magnitude', [
'#0A3663',
'#1558AC',
'#3771D9',
'#4D89E5',
'#64A5D3',
'#72BED6',
'#83CED6',
'#A6E1E0',
'#B8EFE2',
'#D7F9F0',
])
.style({
opacity: 1,
strokeWidth: 0,
2020-04-02 19:53:36 +08:00
stroke: '#fff',
2020-03-16 23:31:15 +08:00
});
2021-01-12 19:46:04 +08:00
scene.addLayer(pointLayer);
this.scene = scene;
});
2020-01-16 18:22:38 +08:00
});
2019-10-29 17:33:37 +08:00
}
public render() {
return (
<div
id="map"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
);
}
}