mirror of https://gitee.com/antv-l7/antv-l7
136 lines
3.4 KiB
TypeScript
136 lines
3.4 KiB
TypeScript
import { LineLayer, Scene, PointLayer, PolygonLayer } from '@antv/l7';
|
|
import { GaodeMap } from '@antv/l7-maps';
|
|
import * as React from 'react';
|
|
|
|
export default class Amap2demo_road2 extends React.Component {
|
|
// @ts-ignore
|
|
private scene: Scene;
|
|
|
|
public componentWillUnmount() {
|
|
this.scene.destroy();
|
|
}
|
|
|
|
public async componentDidMount() {
|
|
const scene = new Scene({
|
|
id: 'map',
|
|
map: new GaodeMap({
|
|
center: [120.165, 30.26],
|
|
pitch: 0,
|
|
zoom: 15,
|
|
viewMode: '3D',
|
|
style: 'dark',
|
|
}),
|
|
});
|
|
this.scene = scene;
|
|
const data = {
|
|
type: 'FeatureCollection',
|
|
features: [
|
|
{
|
|
type: 'Feature',
|
|
geometry: {
|
|
type: 'MultiPolygon',
|
|
coordinates: [
|
|
[
|
|
[
|
|
[120.16021728515624, 30.259660295442085],
|
|
[120.15987396240234, 30.25313608393673],
|
|
[120.16605377197266, 30.253729211980726],
|
|
[120.1658821105957, 30.258474107402265],
|
|
],
|
|
],
|
|
[
|
|
[
|
|
[120.1703453063965, 30.258474107402265],
|
|
[120.17086029052733, 30.254174055663515],
|
|
[120.17583847045898, 30.254915457324778],
|
|
[120.17446517944336, 30.258474107402265],
|
|
],
|
|
],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
const data2 = {
|
|
type: 'FeatureCollection',
|
|
features: [
|
|
{
|
|
type: 'Feature',
|
|
geometry: {
|
|
type: 'MultiPolygon',
|
|
coordinates: [
|
|
[
|
|
[
|
|
[120.16536712646484, 30.26336704072365],
|
|
[120.16777038574219, 30.2657392842738],
|
|
[120.17086029052733, 30.26232916614846],
|
|
],
|
|
],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
scene.on('loaded', () => {
|
|
const polygonlayer = new PolygonLayer({})
|
|
.source(data)
|
|
.shape('fill')
|
|
.color('red');
|
|
scene.addLayer(polygonlayer);
|
|
|
|
const polygonlayer2 = new PolygonLayer({})
|
|
.source(data2)
|
|
.shape('fill')
|
|
.color('#ff0');
|
|
scene.addLayer(polygonlayer2);
|
|
|
|
fetch(
|
|
'https://gw.alipayobjects.com/os/basement_prod/40ef2173-df66-4154-a8c0-785e93a5f18e.json',
|
|
)
|
|
.then((res) => res.json())
|
|
.then((data) => {
|
|
const layer = new LineLayer({})
|
|
.source(data)
|
|
.size(5)
|
|
.shape('line')
|
|
// .texture('02')
|
|
// .color('#ccc')
|
|
.color('rgb(20, 180, 90)')
|
|
// .animate({
|
|
// interval: 1, // 间隔
|
|
// duration: 1, // 持续时间,延时
|
|
// trailLength: 2, // 流线长度
|
|
// })
|
|
.style({
|
|
borderWidth: 0.35,
|
|
borderColor: '#fff',
|
|
// opacity: 0.5,
|
|
// lineTexture: true, // 开启线的贴图功能
|
|
// iconStep: 80, // 设置贴图纹理的间距
|
|
})
|
|
.active(true);
|
|
scene.addLayer(layer);
|
|
});
|
|
});
|
|
}
|
|
|
|
public render() {
|
|
return (
|
|
<>
|
|
<div
|
|
id="map"
|
|
style={{
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
}
|