高德地图鼠标经过点标记显示信息窗体

本文介绍如何在地图上创建标记并实现鼠标移入/移出事件触发信息窗体显示的功能。通过实例化信息窗体组件,并利用JavaScript进行事件绑定,能够动态展示每个站点的相关信息,包括设备总数、在线数等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

  1. 创建点标记:
    在这里插入图片描述

  2. 实例化信息窗体
    在这里插入图片描述

  3. 放入鼠标移入/移出事件
    在这里插入图片描述


源码:

// 获取站点
getData() {
  api.stationMap(this.params).then((res) => {
    console.log(res);
    if (res.code === 0) {
      console.log("电站覆盖:", res.data);
      const that = this;
      const infoWindow = new AMap.InfoWindow({
        offset: new AMap.Pixel(0, -30),
      });
      this.markers = res.data.map((item) => {
        let marker = new AMap.Marker({
          position: item.location,
          offset: new AMap.Pixel(-10, -30),
        });
        marker.on("click", function (e) {
          console.log(e);
          that.equipmentModel = true;
          that.equipmentModelData = item;
        });
        marker.on("mouseover", function (e) {
          console.log(e);
          infoWindow.setContent(
            `<div class="description">
              <h5 class="title">${item.name}</h5>
              <div class="mt-3 detail">
                设备:${item.total}个<br />
                在线:${item.onLine}个<br />
                离线:${item.offLine}个<br />
                使用中:${item.inUse}个<br />
              </div>
            </div>`
          );
          infoWindow.open(that.map, item.location);
        });
        marker.on("mouseout", function (e) {
          console.log(e);
          infoWindow.close(that.map, item.location);
        });
        return marker;
      });
      this.map.add(this.markers);
    }
  });
},
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钱厚端

谢谢看官

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值