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

72 lines
1.6 KiB
TypeScript
Raw Normal View History

import { PointLayer, Scene } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps';
import * as React from 'react';
// @ts-ignore
import data from '../data/data.json';
export default class Column extends React.Component {
// @ts-ignore
private scene: Scene;
public componentWillUnmount() {
this.scene.destroy();
}
public componentDidMount() {
const scene = new Scene({
id: 'map',
map: new GaodeMap({
pitch: 66.02383,
style: 'dark',
2019-12-02 15:16:45 +08:00
center: [121.400257, 31.25287],
zoom: 14.55,
2019-12-02 15:16:45 +08:00
rotation: 134.9507,
}),
});
this.scene = scene;
fetch(
2019-12-02 15:16:45 +08:00
'https://gw.alipayobjects.com/os/basement_prod/893d1d5f-11d9-45f3-8322-ee9140d288ae.json',
)
2019-12-02 15:16:45 +08:00
.then((res) => res.json())
.then((data) => {
const pointLayer = new PointLayer({})
.source(data, {
parser: {
type: 'json',
x: 'longitude',
2019-12-02 15:16:45 +08:00
y: 'latitude',
},
})
.shape('name', [
'cylinder',
'triangleColumn',
'hexagonColumn',
2019-12-02 15:16:45 +08:00
'squareColumn',
])
2019-12-02 15:16:45 +08:00
.size('unit_price', (h) => {
return [6, 6, 100];
})
2019-12-02 15:16:45 +08:00
.color('name', ['#739DFF', '#61FCBF', '#FFDE74', '#FF896F'])
.style({
2019-12-02 15:16:45 +08:00
opacity: 1.0,
});
scene.addLayer(pointLayer);
2019-12-02 15:16:45 +08:00
});
}
public render() {
return (
<div
id="map"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
);
}
}