2022-05-25 18:50:54 +08:00
|
|
|
import { PointLayer, Scene, LineLayer } from '@antv/l7';
|
2021-06-15 18:19:51 +08:00
|
|
|
import { GaodeMapV2 } from '@antv/l7-maps';
|
2021-04-22 15:08:41 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
export default class Amap2demo extends React.Component {
|
|
|
|
// @ts-ignore
|
|
|
|
private scene: Scene;
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
this.scene.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async componentDidMount() {
|
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
2021-06-15 18:19:51 +08:00
|
|
|
map: new GaodeMapV2({
|
2022-05-25 18:50:54 +08:00
|
|
|
// center: [121.107846, 30.267069],
|
|
|
|
center: [120.692587367181758, 30.377451929339649],
|
2021-04-22 15:08:41 +08:00
|
|
|
pitch: 0,
|
|
|
|
style: 'normal',
|
2021-06-22 20:58:12 +08:00
|
|
|
zoom: 20,
|
2021-04-22 15:08:41 +08:00
|
|
|
animateEnable: false,
|
2022-05-25 18:50:54 +08:00
|
|
|
zooms: [0, 23],
|
2021-04-22 15:08:41 +08:00
|
|
|
}),
|
|
|
|
});
|
2022-05-25 18:50:54 +08:00
|
|
|
let data = {
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
|
|
|
properties: {},
|
|
|
|
geometry: {
|
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [
|
|
|
|
[
|
|
|
|
[122.692587367181758, 43.377451929339649],
|
|
|
|
[122.692587367181758, 43.377465856847415],
|
|
|
|
[122.692574277855613, 43.377465856847415],
|
|
|
|
[122.692574277855613, 43.377451929339649],
|
|
|
|
[122.692587367181758, 43.377451929339649],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
// let cut = 0.0002;
|
|
|
|
let data2 = {
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: [
|
|
|
|
{
|
|
|
|
type: 'Feature',
|
|
|
|
properties: {},
|
|
|
|
geometry: {
|
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [
|
|
|
|
[
|
|
|
|
[120.692587367181758, 30.377451929339649],
|
|
|
|
[120.692587367181758, 30.377465856847415],
|
|
|
|
[120.692574277855613, 30.377465856847415],
|
|
|
|
[120.692574277855613, 30.377451929339649],
|
|
|
|
[120.692587367181758, 30.377451929339649],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2021-04-22 15:08:41 +08:00
|
|
|
scene.on('loaded', () => {
|
2022-05-25 18:50:54 +08:00
|
|
|
let rect = new LineLayer()
|
|
|
|
.source(data)
|
|
|
|
.shape('line')
|
|
|
|
.size(2)
|
|
|
|
.color('#f00');
|
|
|
|
scene.addLayer(rect);
|
|
|
|
let rect2 = new LineLayer()
|
|
|
|
.source(data2)
|
|
|
|
.shape('line')
|
|
|
|
.size(2)
|
|
|
|
.color('#f00');
|
|
|
|
scene.addLayer(rect2);
|
|
|
|
const mapService = scene.getMapService();
|
|
|
|
// setTimeout(() => {
|
|
|
|
// scene.setCenter([122.692587367181758, 43.377451929339649]);
|
|
|
|
// // // @ts-ignore
|
|
|
|
// // mapService.map.customCoords?.setCenter([
|
|
|
|
// // 122.692587367181758,
|
|
|
|
// // 43.377451929339649,
|
|
|
|
// // ]);
|
|
|
|
// // // @ts-ignore
|
|
|
|
// // mapService.setCustomCoordCenter([
|
|
|
|
// // 122.692587367181758,
|
|
|
|
// // 43.377451929339649,
|
|
|
|
// // ]);
|
|
|
|
// // rect.dataState.dataSourceNeedUpdate = true;
|
|
|
|
// }, 2000);
|
2021-04-22 15:08:41 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
id="map"
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|