1、
<a-button class="btn3" @click="ontimeNumbers">xxx文字描述</a-button>
2、 marknewFlag: false,
mounted() {
this.addMarker()
},
3、
//实例化marker
addMarker() {
let me = this
var position1 = new AMap.LngLat(116.013811, 31.756869)
var position2 = new AMap.LngLat(116.013317, 31.754032)
// 点标记显示内容,HTML要素字符串
var markerContent1 =
'' +
'<div class="custom-content-marker">' +
' <div class="cuntom-span-marker" ><span>No.3</span>xxx文字描述' +
'</div>' +
' <div class="cuntom-span-marker" >xxx文字描述' +
'</div>'
'</div>'
var markerContent2 =
'' +
'<div class="custom-content-marker">' +
' <div class="cuntom-span-marker" ><span >No.2</span>xxx文字描述' +
'</div>' +
' <div class="cuntom-span-marker" >xxx文字描述' +
'</div>'
'</div>'
var marker1 = new AMap.Marker({
position: position1,
// 将 html 传给 content
content: markerContent1,
// 以 icon 的 [center bottom] 为原点
offset: new AMap.Pixel(-13, -30)
})
var marker2 = new AMap.Marker({
position: position2,
// 将 html 传给 content
content: markerContent2,
// 以 icon 的 [center bottom] 为原点
offset: new AMap.Pixel(-18, -30)
})
me.mapmarker1 = marker1
me.mapmarker2 = marker2
// 将 markers 添加到地图
me.map.add(me.mapmarker1)
me.map.add(me.mapmarker2)
},
ontimeNumbers() {
let me = this
if (me.marknewFlag) {
me.marknewFlag = false
me.map.add(me.mapmarker1)
me.map.add(me.mapmarker2)
} else {
me.marknewFlag = true
me.map.remove(me.mapmarker1)
me.map.remove(me.mapmarker2)
}
}```