高德地图信息窗体设置

  1. 添加默认信息窗体

    //构建信息窗体中显示的内容
    var info = [];
    info.push(
    <div style="height: 36px; line-height: 45px; padding: 0px 20px; white-space:nowrap;">位置:北京</div>
    );
    info.push(
    <div style="height: 36px; line-height: 20px; padding: 0px 20px; white-space:nowrap;"> 联系人:袁磊 </div>
    );
    this.infoWindow = new AMap.InfoWindow({
    content: info.join("") //使用默认信息窗体框样式,显示信息内容
    });
    // // getCenter() 获取地图中心点(数组)
    // this.infoWindow.open(this.aMap, this.aMap.getCenter());
    // 设置点坐标为窗体坐标;例:[123.40340954550922, 41.7334550336356]
    this.infoWindow.open(this.aMap, e.data.lnglat);

  2. 使用自定义窗体(添加窗体)

    //构建信息窗体中显示的内容
    var info = [];
    info.push(
    <div style="height: 36px; line-height: 45px; padding: 0px 20px; white-space:nowrap;">位置:北京</div>
    );
    info.push(
    <div style="height: 36px; line-height: 20px; padding: 0px 20px; white-space:nowrap;"> 联系人:袁磊 </div>
    );
    that.infoWindow = new AMap.InfoWindow({
    isCustom: true, //使用自定义窗体
    content: <div style="background: #f00;">jdfghjdfihg</div> <div class="close-btn" style="float: right;margin-top: 3px; margin-right: 5px;" onclick="closeInfoWindow()">X</div> ,
    offset: new AMap.Pixel(16, -45)
    });
    // // getCenter() 获取地图中心点(数组)
    // this.infoWindow.open(this.aMap, this.aMap.getCenter());
    // 设置点坐标为窗体坐标;例:[123.40340954550922, 41.7334550336356]
    that.infoWindow.open(that.aMap, e.data.lnglat);

3关闭自定义窗体(closeInfoWindow方法也要挂在window)

复制代码
mounted() {
    window.closeInfoWindow = () => {
      this.aMap.clearInfoWindow();
    };
  },
相关推荐
_dindong2 分钟前
Linux网络编程:Socket编程TCP
linux·服务器·网络·笔记·学习·tcp/ip
七宝大爷3 分钟前
深度解析英伟达DGX与HGX服务器——从架构差异到场景选择
运维·服务器·架构
wanhengidc7 分钟前
服务器的安全性如何?
运维·服务器·安全·游戏·智能手机
訾博ZiBo15 分钟前
【Vibe Coding】001-前端界面常用布局
前端
IT_陈寒18 分钟前
《Redis性能翻倍的7个冷门技巧,90%开发者都不知道!》
前端·人工智能·后端
tianyuanwo20 分钟前
tar打包过滤指定目录指南
linux·tar·过滤式打包
DARLING Zero two♡23 分钟前
【Linux操作系统】简学深悟启示录:进程间通信
linux·运维·服务器
半梦半醒*23 分钟前
gitlab部署
linux·运维·centos·ssh·gitlab·jenkins
歪歪10028 分钟前
React Native开发Android&IOS流程完整指南
android·开发语言·前端·react native·ios·前端框架
知识分享小能手30 分钟前
uni-app 入门学习教程,从入门到精通,uni-app组件 —— 知识点详解与实战案例(4)
前端·javascript·学习·微信小程序·小程序·前端框架·uni-app