2021-04-06 18:00:53 +08:00
|
|
|
// @ts-ignore
|
|
|
|
import { ILngLat, PointLayer, PolygonLayer, Scene } from '@antv/l7';
|
2021-06-09 13:23:48 +08:00
|
|
|
import { GaodeMap } from '@antv/l7-maps';
|
2021-04-06 18:00:53 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
export default class GaodeMapComponent extends React.Component {
|
|
|
|
// @ts-ignore
|
|
|
|
private scene: Scene;
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
this.scene.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async componentDidMount() {
|
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
2021-06-09 13:23:48 +08:00
|
|
|
map: new GaodeMap({
|
2021-04-06 18:00:53 +08:00
|
|
|
center: [121.107846, 30.267069],
|
|
|
|
pitch: 0,
|
|
|
|
style: 'normal',
|
2021-06-01 11:02:15 +08:00
|
|
|
zoom: 20,
|
2021-04-06 18:00:53 +08:00
|
|
|
animateEnable: false,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
const layer = new PointLayer()
|
|
|
|
.source(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
lng: 121.107846,
|
|
|
|
lat: 30.267069,
|
|
|
|
},
|
2021-04-22 15:08:41 +08:00
|
|
|
{
|
2021-06-01 11:02:15 +08:00
|
|
|
lng: 121.107,
|
2021-04-22 15:08:41 +08:00
|
|
|
lat: 30.267069,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lng: 120.107846,
|
|
|
|
lat: 30.267069,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lng: 38.54,
|
|
|
|
lat: 77.02,
|
|
|
|
},
|
2021-04-06 18:00:53 +08:00
|
|
|
],
|
|
|
|
{
|
|
|
|
parser: {
|
|
|
|
type: 'json',
|
|
|
|
x: 'lng',
|
|
|
|
y: 'lat',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.shape('circle')
|
2021-04-22 15:08:41 +08:00
|
|
|
// .shape('normal')
|
2021-04-06 18:00:53 +08:00
|
|
|
.color('blue')
|
|
|
|
.size(10)
|
|
|
|
.style({
|
|
|
|
stroke: '#fff',
|
|
|
|
storkeWidth: 2,
|
2021-06-09 13:23:48 +08:00
|
|
|
offsets: [100, 100],
|
2021-04-06 18:00:53 +08:00
|
|
|
});
|
|
|
|
scene.addLayer(layer);
|
|
|
|
scene.render();
|
|
|
|
this.scene = scene;
|
|
|
|
|
|
|
|
scene.on('loaded', () => {
|
2021-04-22 15:08:41 +08:00
|
|
|
// const padding = {
|
|
|
|
// top: 50,
|
|
|
|
// right: 0,
|
|
|
|
// bottom: 200,
|
|
|
|
// left: 800,
|
|
|
|
// };
|
2021-04-06 18:00:53 +08:00
|
|
|
// const px = scene.lngLatToPixel([center.lng, center.lat]);
|
|
|
|
// const offsetPx = [
|
|
|
|
// (padding.right - padding.left) / 2,
|
|
|
|
// (padding.bottom - padding.top) / 2,
|
|
|
|
// ];
|
2021-04-22 15:08:41 +08:00
|
|
|
// scene.setCenter([121.107846, 30.267069], { padding });
|
2021-04-06 18:00:53 +08:00
|
|
|
// const newCenter = scene.pixelToLngLat([
|
|
|
|
// px.x + offsetPx[0],
|
|
|
|
// px.y + offsetPx[1],
|
|
|
|
// ]);
|
|
|
|
// @ts-ignore
|
|
|
|
// scene.setCenter();
|
|
|
|
// get originCenter
|
|
|
|
// const originCenter = scene.getCenter();
|
|
|
|
// const originPx = scene.lngLatToPixel([
|
|
|
|
// originCenter.lng,
|
|
|
|
// originCenter.lat,
|
|
|
|
// ]);
|
|
|
|
// const offsetPx2 = [
|
|
|
|
// (-padding.right + padding.left) / 2,
|
|
|
|
// (-padding.bottom + padding.top) / 2,
|
|
|
|
// ];
|
|
|
|
// const newCenter2 = scene.pixelToLngLat([
|
|
|
|
// originPx.x - offsetPx[0],
|
|
|
|
// originPx.y - offsetPx[1],
|
|
|
|
// ]);
|
|
|
|
// lngLatToContainer
|
|
|
|
// 获取当前地图像素坐标
|
|
|
|
// console.log(originCenter, center, newCenter2);
|
|
|
|
// console.log(w,h);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
id="map"
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
/>
|
2021-04-22 15:08:41 +08:00
|
|
|
{/* <div
|
2021-04-06 18:00:53 +08:00
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
bottom: '0px',
|
|
|
|
zIndex: 10,
|
|
|
|
background: '#fff',
|
|
|
|
height: '200px',
|
|
|
|
width: '100%',
|
|
|
|
}}
|
2021-04-22 15:08:41 +08:00
|
|
|
/> */}
|
|
|
|
{/* <div
|
2021-04-06 18:00:53 +08:00
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: '0px',
|
|
|
|
zIndex: 10,
|
|
|
|
background: '#f00',
|
|
|
|
height: '50px',
|
|
|
|
width: '100%',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
left: '0px',
|
|
|
|
zIndex: 10,
|
|
|
|
background: '#ff0',
|
|
|
|
height: '100%',
|
|
|
|
width: '800px',
|
|
|
|
}}
|
2021-04-22 15:08:41 +08:00
|
|
|
/> */}
|
2021-04-06 18:00:53 +08:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|