2019-10-30 10:07:17 +08:00
|
|
|
// @ts-ignore
|
2019-11-25 15:27:56 +08:00
|
|
|
import { Marker, PolygonLayer, Scene } from '@antv/l7';
|
2019-11-28 17:25:56 +08:00
|
|
|
import { Mapbox, GaodeMap } from '@antv/l7-maps';
|
2019-10-30 10:07:17 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
|
2019-11-25 15:27:56 +08:00
|
|
|
export default class MarkerComponent extends React.Component {
|
2019-10-30 10:07:17 +08:00
|
|
|
private scene: Scene;
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
this.scene.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async componentDidMount() {
|
|
|
|
const response = await fetch(
|
|
|
|
'https://gw.alipayobjects.com/os/basement_prod/d2e0e930-fd44-4fca-8872-c1037b0fee7b.json',
|
|
|
|
);
|
2019-11-25 15:27:56 +08:00
|
|
|
const data = await response.json();
|
2019-10-30 10:07:17 +08:00
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
2020-01-03 14:43:51 +08:00
|
|
|
map: new GaodeMap({
|
2019-11-28 17:25:56 +08:00
|
|
|
style: 'dark',
|
2019-11-26 17:51:29 +08:00
|
|
|
center: [110.19382669582967, 30.258134],
|
|
|
|
pitch: 0,
|
|
|
|
zoom: 3,
|
|
|
|
}),
|
2019-10-30 10:07:17 +08:00
|
|
|
});
|
|
|
|
this.scene = scene;
|
2019-11-25 15:27:56 +08:00
|
|
|
const layer = new PolygonLayer({});
|
|
|
|
|
2019-10-30 10:07:17 +08:00
|
|
|
layer
|
2019-11-25 15:27:56 +08:00
|
|
|
.source(data)
|
2019-10-30 10:07:17 +08:00
|
|
|
.size('name', [0, 10000, 50000, 30000, 100000])
|
2020-01-03 14:43:51 +08:00
|
|
|
.active(true)
|
2019-10-30 10:07:17 +08:00
|
|
|
.color('name', [
|
|
|
|
'#2E8AE6',
|
|
|
|
'#69D1AB',
|
|
|
|
'#DAF291',
|
|
|
|
'#FFD591',
|
|
|
|
'#FF7A45',
|
|
|
|
'#CF1D49',
|
|
|
|
])
|
|
|
|
.shape('fill')
|
|
|
|
.style({
|
2020-01-03 14:43:51 +08:00
|
|
|
opacity: 0.8,
|
2019-10-30 10:07:17 +08:00
|
|
|
});
|
|
|
|
scene.addLayer(layer);
|
2019-11-28 17:25:56 +08:00
|
|
|
const marker = new Marker().setLnglat({
|
|
|
|
lng: 120.19382669582967,
|
|
|
|
lat: 30.258134,
|
2019-11-25 15:27:56 +08:00
|
|
|
});
|
2020-01-03 14:43:51 +08:00
|
|
|
marker.on('click', (e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
2019-11-28 17:25:56 +08:00
|
|
|
|
|
|
|
scene.addMarker(marker);
|
2020-01-03 14:43:51 +08:00
|
|
|
scene.on('loaded', () => {
|
|
|
|
// @ts-ignore
|
|
|
|
const marker1 = new AMap.Marker({
|
|
|
|
map: scene.map,
|
|
|
|
position: [113.800646, 34.796227],
|
|
|
|
shadow: '#000',
|
|
|
|
label: {
|
|
|
|
content: '站点',
|
|
|
|
direction: 'top',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
marker1.on('click', () => {
|
|
|
|
alert(1111);
|
|
|
|
console.log('选中的点', 1111);
|
|
|
|
});
|
|
|
|
});
|
2019-10-30 10:07:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
id="map"
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|