mirror of https://gitee.com/antv-l7/antv-l7
80 lines
1.7 KiB
TypeScript
80 lines
1.7 KiB
TypeScript
import { PolygonLayer, Scene } from '@antv/l7';
|
|
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 Polygon3D extends React.Component {
|
|
private gui: dat.GUI;
|
|
private $stats: Node;
|
|
private scene: Scene;
|
|
|
|
public componentWillUnmount() {
|
|
if (this.gui) {
|
|
this.gui.destroy();
|
|
}
|
|
if (this.$stats) {
|
|
document.body.removeChild(this.$stats);
|
|
}
|
|
this.scene.destroy();
|
|
}
|
|
|
|
public async componentDidMount() {
|
|
const response = await fetch(
|
|
'https://gw.alipayobjects.com/os/basement_prod/d2e0e930-fd44-4fca-8872-c1037b0fee7b.json',
|
|
);
|
|
const scene = new Scene({
|
|
id: 'map',
|
|
type: 'mapbox',
|
|
style: 'mapbox://styles/mapbox/streets-v9',
|
|
center: [110.19382669582967, 50.258134],
|
|
pitch: 0,
|
|
zoom: 3,
|
|
});
|
|
this.scene = scene;
|
|
const layer = new PolygonLayer({
|
|
enableMultiPassRenderer: true,
|
|
enableLighting: true,
|
|
enablePicking: true,
|
|
enableHighlight: true,
|
|
// enableTAA: true,
|
|
});
|
|
layer
|
|
.source(await response.json())
|
|
.size('name', [0, 10000, 50000, 30000, 100000])
|
|
.color('name', [
|
|
'#2E8AE6',
|
|
'#69D1AB',
|
|
'#DAF291',
|
|
'#FFD591',
|
|
'#FF7A45',
|
|
'#CF1D49',
|
|
])
|
|
.shape('extrude')
|
|
.style({
|
|
opacity: 1.0,
|
|
});
|
|
scene.addLayer(layer);
|
|
scene.render();
|
|
this.scene = scene;
|
|
}
|
|
|
|
public render() {
|
|
return (
|
|
<div
|
|
id="map"
|
|
style={{
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
}
|