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

84 lines
1.7 KiB
TypeScript
Raw Normal View History

import { LineLayer, Scene } from '@antv/l7';
2020-04-13 16:58:09 +08:00
import { GaodeMap, Mapbox } from '@antv/l7-maps';
2019-11-21 13:44:32 +08:00
import * as React from 'react';
export default class Arc2DLineDemo extends React.Component {
// @ts-ignore
2019-11-21 13:44:32 +08:00
private scene: Scene;
public componentWillUnmount() {
this.scene.destroy();
}
public async componentDidMount() {
const response = await fetch(
'https://gw.alipayobjects.com/os/rmsportal/UEXQMifxtkQlYfChpPwT.txt',
);
const scene = new Scene({
id: 'map',
map: new GaodeMap({
center: [116.2825, 39.9],
pitch: 0,
style: 'dark',
zoom: 2,
}),
2019-11-21 13:44:32 +08:00
});
2020-02-12 00:06:08 +08:00
const lineLayer = new LineLayer({
blend: 'normal',
pickingBuffer: 10,
2020-02-12 00:06:08 +08:00
})
2020-04-13 16:58:09 +08:00
.source(
[
{
lng1: 84.375,
lat1: 47.517200697839414,
lng2: 117.94921874999999,
lat2: 22.268764039073968,
},
],
{
parser: {
type: 'json',
x1: 'lng1',
y1: 'lat1',
x: 'lng2',
y: 'lat2',
},
2019-11-21 13:44:32 +08:00
},
2020-04-13 16:58:09 +08:00
)
.size(2)
2020-02-12 00:06:08 +08:00
.shape('arc')
2020-04-13 16:58:09 +08:00
.animate({
enable: false,
2020-04-13 16:58:09 +08:00
interval: 0.1,
trailLength: 0.5,
duration: 0.5,
})
2020-02-12 00:06:08 +08:00
.color('#8C1EB2')
.style({
2020-02-12 00:06:08 +08:00
opacity: 1,
});
2019-11-21 13:44:32 +08:00
scene.addLayer(lineLayer);
2020-02-12 00:06:08 +08:00
lineLayer.on('click', (e) => {
console.log(e);
});
2019-11-21 13:44:32 +08:00
scene.render();
this.scene = scene;
}
public render() {
return (
<div
id="map"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
);
}
}