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

73 lines
1.5 KiB
TypeScript
Raw Normal View History

import { LineLayer, Scene } from '@antv/l7';
import { Mapbox } from '@antv/l7-maps';
import * as React from 'react';
2019-10-30 14:53:18 +08:00
export default class LineDemo extends React.Component {
// @ts-ignore
private scene: Scene;
public componentWillUnmount() {
this.scene.destroy();
}
public async componentDidMount() {
const response = await fetch(
2019-12-26 22:36:50 +08:00
'https://arcgis.github.io/arcgis-samples-javascript/sample-data/custom-gl-animated-lines/lines.json',
);
const scene = new Scene({
id: 'map',
map: new Mapbox({
2019-12-26 22:36:50 +08:00
center: [-74.006, 40.7128],
zoom: 11.5,
2019-12-26 22:36:50 +08:00
style: 'dark',
}),
});
const lineLayer = new LineLayer({
minZoom: 12,
maxZoom: 15,
})
2019-12-26 22:36:50 +08:00
.source(await response.json(), {
parser: {
type: 'json',
coordinates: 'path',
},
})
.size(3)
.shape('line')
.active(true)
2019-12-27 11:35:19 +08:00
.color('color', (v) => {
return `rgb(${v})`;
2020-01-08 17:54:23 +08:00
})
.animate({
enable: true,
interval: 0.5,
trailLength: 0.4,
duration: 4,
})
.style({
opacity: 1.0,
});
2020-02-07 22:58:38 +08:00
lineLayer.on('click', (e) => {
2020-02-07 22:12:56 +08:00
console.log(e);
2020-02-07 22:58:38 +08:00
});
scene.addLayer(lineLayer);
this.scene = scene;
}
public render() {
return (
<div
id="map"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
);
}
}