//设置文本样式
const fontStyle = {
'margin-bottom': '20rem',
'border-radius': '.25rem',
'background-color': 'rgba(0,0,0,0)',
'border-width': 0,
'text-align': 'center',
'font-size': '14px',
color: '#fff',
};
//定义Text类
const text1 = new AMap.Text({
text: '太原市',
//position的坐标可以在高德地图API文档的地理编码中查到
//https://lbs.amap.com/api/webservice/guide/api/georegeo
position: new AMap.LngLat(112.486691, 37.940387),
style: fontStyle,
});
const text2 = new AMap.Text({
text: '大同市',
position: new AMap.LngLat(113.340174, 40.078809),
//adcode同position一样查position的时候会有adcode
adcode: '140213',
//设置文本样式
style: fontStyle,
});
map.add([text1, text2]);

话说高德地图的Polygon里到底有没有setLabel方法,有个人告诉我有但是我一用就报错not a funtion 本来是想用这个方法来实现上面的效果的,到最后无意间翻文档的时候感觉text类也可以就用了。但是我真的很想知道Polygon里到底有没有setLabel方法