效果圖,數據需自己模擬;
val = {
name: 'xxx城市',
position: [123.34534566,41.423443]
}
let marker = new AMap.Marker({
icon:new AMap.Icon({
image:'https://a.amap.com/jsapi_demos/static/resource/img/pin.png',
size:new AMap.Size(32,32),
imageSize:new AMap.Size(32,32)
}),
offset:new AMap.Pixel(-16,-32),
position: val.position,
map: map,
title: val.name,
});
marker.setLabel({
offset: new AMap.Pixel(30, 1),
content: val.name, //設置文本標註內容
direction: 'right', //設置文本標註方位
style: labelStyle // 自定義文本樣式
});
marker.setMap(map);
/**
* labelStyle 自定義樣式如下:
* backgroundColor: "#0c64dee3"
* fillColor: "white"
*/
}