高德地图只能删除一个label信息窗

现在是随便点哪个marker都是删除科技园2 我想点哪个marker就删除哪个marker的label 这个应该怎么改?
image.png

lnglats: [{
            name: '科技园1',
            position: [113.28, 23.15],
            label: '纳米科技1',
            desc: '商务办公',
            avail: 1000,
            rate: '70%',
            companyNum: 241,
            zj: '3%'
        }, {
            name: '科技园2',
            position: [113.29, 23.16],
            label: '纳米科技2',
            desc: '商务办公',
            avail: 3000,
            rate: '40%',
            companyNum: 991,
            zj: '3%'
}]
methods:{
      init: function() {
        var that = this
        var infoWindow
        map = new AMap.Map('container', {
          center: [113.28, 23.15],
          resizeEnable: true,
          zoom: 13
        })

        for(let i=0;i<that.lnglats.length;i++){
            marker = new AMap.Marker({
              name: that.lnglats[i].name,
              position: that.lnglats[i].position,
              map,
              icon: new AMap.Icon({
                  size: new AMap.Size(30,30),
                  image: 'https://sqt-1259302042.cos.ap-guangzhou.myqcloud.com/5d05d218da1b4213a01052f4a0b405d5.png',
                  imageSize: new AMap.Size(30, 30)
              })
            })
            var content = `
                <div style="padding: 5px;overflow:hidden;display:flex;justify-content:center;border-radius:5px;border: 1px solid white !important;">
                    <div onclick="test(${i})">${this.lnglats[i].name}</div>
                    <div style="width: 0px;height: 0px;border: 10px solid #000;border-top-color: white;border-bottom-color: transparent;border-left-color: transparent;border-right-color: transparent;position:absolute;bottom:-20px"></div>
                </div>
            `
            marker.setLabel({
                    offset: new AMap.Pixel(0, -10),
                    direction: 'top',content,
                    border: 'none'
            })
        }
      }
},
created(){
        window.test=(i)=>{
           console.log(i)
           marker.setLabel(null);
        }
},
阅读 1.8k
1 个回答

因为你marker指向的都是最后一个marker,你不把i传进去了吗,那你就要想想怎么用这个i去找到对应的marker,比如你可以把所有的marker都存放在一个数组markers里,然后用marker[i]去寻找对应的marker

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题