前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >高德地图不同层级是否显示文字记录

高德地图不同层级是否显示文字记录

作者头像
tianyawhl
发布2023-01-15 09:43:42
4640
发布2023-01-15 09:43:42
举报
文章被收录于专栏:前端之攻略前端之攻略

data中设置变量 isShowLabel? ??isShowLabel:"none", ?// "none":不显示 ?"block":显示

代码语言:javascript
复制
mounted中执行handleMoveEnd事件,一般地图展示后执行使用setTimeout
    handleMoveEnd(){
      console.log(this.GDMap.getZoom())
      this.GDMap.on("zoomend",()=>{
        console.log("zoomend")
        let zoom = this.GDMap.getZoom()
        if(zoom>11){
          if(this.isShowLabel=="none"){
             this.showMarkerLabel()
          }
        }else{
          if(this.isShowLabel=="block"){
            this.hideMarkerLabel()
          }
        }        
      })
    },
代码语言:javascript
复制
    showMarkerLabel(){
      this.isShowLabel = "block"
      this.showSiteMarker()
      return  // 下面层级放大时候标签不在视线区域的会偏移,未找到原因,所以改成重新画点
      for(let i=0;i<this.siteMarkers.length;i++){
        let label = this.siteMarkers[i].getLabel()
        console.log(label)
        console.log(label.direction)
        let labelContent = label.content.replace("none","block")
        this.isShowLabel = "block"
        // setTimeout(() => {
          this.siteMarkers[i].setLabel({
            // direction:label.direction,
            direction:"right",
            content:labelContent
          })
          this.siteMarkers[i].on("mouseout", () => {
              console.log("moveout")
              this.siteMarkers[i].setLabel({
                direction:label.direction,
                content: labelContent
              });
          });          
        // }, 1000);


      }
    },

为Marker设置Label

代码语言:javascript
复制
          let labelContentTitle = `
              <div class="mapLabel" style="display:${this.isShowLabel}">
                 <div class="labelTitle controlShow">${resultList[j].title}</div>
              </div>
            `;
本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-01-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com