2021-07-02 17:35:33 +08:00
|
|
|
import { PointLayer, Scene } from '@antv/l7';
|
2021-05-27 19:53:22 +08:00
|
|
|
import { GaodeMap } from '@antv/l7-maps';
|
2021-04-22 15:08:41 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
export default class Amap2demo_text extends React.Component {
|
|
|
|
// @ts-ignore
|
|
|
|
private scene: Scene;
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
this.scene.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async componentDidMount() {
|
2021-05-27 19:53:22 +08:00
|
|
|
let fontFamily = 'iconfont';
|
|
|
|
let fontPath =
|
|
|
|
'//at.alicdn.com/t/font_2534097_99x8u6zpili.woff2?t=1621842922496';
|
|
|
|
|
|
|
|
// let style = document.createElement('style')
|
|
|
|
// style.type = "text/css"
|
|
|
|
// style.innerText = `
|
|
|
|
// @font-face{
|
|
|
|
// font-family: '${fontname}';
|
|
|
|
// src: url('${fontpath}') format('woff2')
|
|
|
|
// }`
|
|
|
|
// document.getElementsByTagName('head')[0].appendChild(style)
|
|
|
|
var mask = [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[110, 40],
|
|
|
|
[130, 40],
|
|
|
|
[130, 20],
|
|
|
|
[110, 20],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2021-04-22 15:08:41 +08:00
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
2021-05-27 19:53:22 +08:00
|
|
|
map: new GaodeMap({
|
|
|
|
center: [120, 30.258134],
|
2021-04-22 15:08:41 +08:00
|
|
|
pitch: 0,
|
|
|
|
style: 'light',
|
|
|
|
zoom: 3,
|
2021-05-27 19:53:22 +08:00
|
|
|
// viewMode: "3D",
|
|
|
|
// mask
|
2021-04-22 15:08:41 +08:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
this.scene = scene;
|
2021-05-27 19:55:06 +08:00
|
|
|
scene.addIconFont('icon1', '');
|
2021-05-27 19:53:22 +08:00
|
|
|
// scene.addIconFont("icon2", "")
|
2021-04-22 15:08:41 +08:00
|
|
|
|
2021-05-27 19:53:22 +08:00
|
|
|
// scene.addIconFonts([
|
|
|
|
// ['icon1', ''],
|
|
|
|
// ['icon2', ''],
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
scene.addFontFace(fontFamily, fontPath);
|
2021-04-22 15:08:41 +08:00
|
|
|
scene.on('loaded', () => {
|
2021-05-27 19:53:22 +08:00
|
|
|
fetch(
|
|
|
|
'https://gw.alipayobjects.com/os/bmw-prod/70408903-80db-4278-a318-461604acb2df.json',
|
|
|
|
)
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
const pointLayer = new PointLayer({})
|
|
|
|
.source(data.list, {
|
|
|
|
parser: {
|
|
|
|
type: 'json',
|
|
|
|
x: 'j',
|
|
|
|
y: 'w',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.shape('icon', 'text')
|
|
|
|
.size(12)
|
|
|
|
.color('w', ['#f00', '#f00', '#0f0'])
|
|
|
|
.style({
|
|
|
|
textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left
|
|
|
|
textOffset: [-10, 0], // 文本相对锚点的偏移量 [水平, 垂直]
|
|
|
|
spacing: 2, // 字符间距
|
|
|
|
padding: [1, 1], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
|
|
|
|
stroke: '#ffffff', // 描边颜色
|
|
|
|
strokeWidth: 0.3, // 描边宽度
|
|
|
|
strokeOpacity: 1.0,
|
|
|
|
fontFamily,
|
|
|
|
// fontFamily: "Times New Roman",
|
|
|
|
iconfont: true,
|
|
|
|
// textAllowOverlap: true,
|
|
|
|
});
|
|
|
|
scene.addLayer(pointLayer);
|
2021-05-27 19:55:06 +08:00
|
|
|
});
|
2021-05-27 19:53:22 +08:00
|
|
|
|
2021-04-22 15:08:41 +08:00
|
|
|
fetch(
|
|
|
|
'https://gw.alipayobjects.com/os/rmsportal/oVTMqfzuuRFKiDwhPSFL.json',
|
|
|
|
)
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
const pointLayer = new PointLayer({})
|
|
|
|
.source(data.list, {
|
|
|
|
parser: {
|
|
|
|
type: 'json',
|
|
|
|
x: 'j',
|
|
|
|
y: 'w',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.shape('m', 'text')
|
|
|
|
.size(12)
|
|
|
|
.color('w', ['#0e0030', '#0e0030', '#0e0030'])
|
|
|
|
.style({
|
|
|
|
textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left
|
|
|
|
textOffset: [0, 0], // 文本相对锚点的偏移量 [水平, 垂直]
|
|
|
|
spacing: 2, // 字符间距
|
|
|
|
padding: [1, 1], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
|
|
|
|
stroke: '#ffffff', // 描边颜色
|
|
|
|
strokeWidth: 0.3, // 描边宽度
|
|
|
|
strokeOpacity: 1.0,
|
|
|
|
// textAllowOverlap: true
|
|
|
|
});
|
|
|
|
scene.addLayer(pointLayer);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
id="map"
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|