const point = [
{ lnglat: ['121.473701', '31.230416'], city: '上海', number: 10 },
{ lnglat: ['113.264434', '23.129162'], city: '广州', number: 10 },
{ lnglat: ['104.065735', '30.659462'], city: '成都', number: 10 }
]
const map = new AMap.Map('container', {
zoom: 5,
animateEnable: true
})
let markers = []
function markInfoWindow(position) {
var content = `
<div>
<p> 电话 : 010-84107000 </p>
<p> 邮编 : 100102 </p>
<p> 地址 : 北京市望京阜通东大街方恒国际中心A座16层 </p>
</div>`
var infoWindow = new AMap.InfoWindow({
content: content,
offset: [16, -50]
})
infoWindow.open(map, position)
}
function makeMarker({ lnglat, city, number }) {
const marker = new AMap.Marker({
position: lnglat
})
const content = `
<div class="amap-info-container">
<div class="amap-info-window">${city}仓 ${number}</div>
<div class="amap-info-sharp"></div>
</div>`
const labelConfig = {
offset: [0, 0],
content,
direction: 'top'
}
marker.on('click', (e) => {
markInfoWindow(lnglat)
})
marker.setLabel(labelConfig)
return marker
}
point.forEach((item) => {
const itemMarker = makeMarker(item)
markers.push(itemMarker)
})
map.add(markers)
.amap-marker-label {
border: none;
}
.amap-info-container {
position: relative;
.amap-info-window {
background: #fff;
border-radius: 3px;
padding: 3px 7px;
box-shadow: 0 2px 6px 0 rgba(114, 124, 245, 0.5);
position: relative;
}
.amap-info-sharp {
position: absolute;
top: 16px;
bottom: 0;
left: 50%;
margin-left: -8px;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: 8px solid #fff;
}
}