mirror of https://gitee.com/antv-l7/antv-l7
63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
import { LineLayer, PolygonLayer, Scene } from '@antv/l7';
|
|
import { GaodeMap } from '@antv/l7-maps';
|
|
import * as React from 'react';
|
|
|
|
function convertRGB2Hex(rgb: number[]) {
|
|
return (
|
|
'#' + rgb.map((r) => ('0' + Math.floor(r).toString(16)).slice(-2)).join('')
|
|
);
|
|
}
|
|
|
|
export default class MultiPolygon extends React.Component {
|
|
private gui: dat.GUI;
|
|
private $stats: Node;
|
|
private scene: Scene;
|
|
|
|
public componentWillUnmount() {
|
|
this.scene.destroy();
|
|
}
|
|
|
|
public async componentDidMount() {
|
|
const response = await fetch(
|
|
// 'https://gw.alipayobjects.com/os/basement_prod/f79485d8-d86f-4bb3-856d-537b586be06e.json',
|
|
'https://gw.alipayobjects.com/os/basement_prod/619a6f16-ecb0-4fca-9f9a-b06b67f6f02b.json',
|
|
);
|
|
const scene = new Scene({
|
|
id: 'map',
|
|
map: new GaodeMap({
|
|
pitch: 0,
|
|
style: 'dark',
|
|
center: [121.775374, 31.31067],
|
|
zoom: 5,
|
|
}),
|
|
});
|
|
const data = await response.json();
|
|
// console.log(data.features[5]);
|
|
// data.features = data.features.slice(6);
|
|
const layer = new LineLayer()
|
|
.source(data)
|
|
.shape('line')
|
|
.size(1)
|
|
.color('red')
|
|
.style({
|
|
opacity: 1.0,
|
|
});
|
|
scene.addLayer(layer);
|
|
}
|
|
|
|
public render() {
|
|
return (
|
|
<div
|
|
id="map"
|
|
style={{
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
}
|