mirror of https://gitee.com/antv-l7/antv-l7
75 lines
1.5 KiB
TypeScript
75 lines
1.5 KiB
TypeScript
|
import { LineLayer, 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 MultiLine extends React.Component {
|
||
|
private scene: Scene;
|
||
|
|
||
|
public componentWillUnmount() {
|
||
|
this.scene.destroy();
|
||
|
}
|
||
|
|
||
|
public async componentDidMount() {
|
||
|
const scene = new Scene({
|
||
|
id: 'map',
|
||
|
map: new GaodeMap({
|
||
|
pitch: 0,
|
||
|
style: 'dark',
|
||
|
center: [101.775374, 3],
|
||
|
zoom: 14.1,
|
||
|
}),
|
||
|
});
|
||
|
|
||
|
const layer = new LineLayer({})
|
||
|
.source({
|
||
|
type: 'FeatureCollection',
|
||
|
features: [
|
||
|
{
|
||
|
type: 'Feature',
|
||
|
properties: {},
|
||
|
geometry: {
|
||
|
type: 'MultiLineString',
|
||
|
coordinates: [
|
||
|
[
|
||
|
[100, 0],
|
||
|
[101, 1],
|
||
|
],
|
||
|
[
|
||
|
[102, 2],
|
||
|
[103, 3],
|
||
|
],
|
||
|
],
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
})
|
||
|
.shape('line')
|
||
|
.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,
|
||
|
}}
|
||
|
/>
|
||
|
);
|
||
|
}
|
||
|
}
|