vuecli使用高德地图,实现自定义信息框,并点击跳转页面

1.public文件夹中index.html引入搞得地图

​
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.5&key=‘自己的key’"></script>

​

2.html

<div class="col">
 <div id="container" style="height: 600px"></div>
</div>

js

 //获取需要渲染的地图列表
this.http.getDealer(obj).then((res) => {
        this.demoList = res.data.list.list;
        this.init(this.demoList[0].coordinate.split(","));
 });
//地图

    init(center) {
      const self = this;

      let map = new AMap.Map("container", {
        center: center,
        resizeEnable: true,
        zoom: 12,
      });
      // map.clearMap();
      // var markers = [];
      var infoWindow;
      let resData = this.demoList;
      var marker;
      for (var i = 0; i < resData.length; i++) {
        marker = new AMap.Marker({
          position: resData[i].coordinate.split(","),
          zIndex: 101,
          map: map,
        });
        marker.setMap(map);
        // marker.id = resData[i].id;
        marker.name = resData[i].carDealerName;
        marker.address = resData[i].carDealerAddress;
        marker.tel = resData[i].carDealerPhone;
        marker.on("click", (e) => {
          this.currentId = e.target.id;
          var info = [];
          info.push(
            "<div class='Box' style=''><div class='myTitle'>" + e.target.name + "</div>"
          );
          info.push(
            "<div><div class='MyAdress'><img  class='iico' src='https://kairui-ali.oss-cn-zhangjiakou.aliyuncs.com/864765731977430213.png'>" +
              e.target.address +
              "</div>"
          );
          info.push(
            "<div><div class='myTel'><img class='iico' src='https://kairui-ali.oss-cn-zhangjiakou.aliyuncs.com/917757616662382652.png'>" +
              e.target.tel +
              "</div>"
          );
          info.push(
            '<div><div class="myBtn border btnHov" onclick="getLen()">预约试驾</div></div>'
          );
          infoWindow = new AMap.InfoWindow({
            content: info.join("<br/>"),
          });
          infoWindow.open(map, e.lnglat);
          infoWindow.close();
        });
      }
      //地图内的事件
      window.getLen = () => {
        let that = this;
        window.location.href =
          "http://localhost:8080/#/Appointment?id=" + that.currentId;
      };
      // map.setFitView();
    },

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值