百度地图标记点 鼠标移入加名称

            var timer = setTimeout(() => {
              this.MP('密钥').then((BMap) => {
                const map = new BMap.Map('map');
                map.enableScrollWheelZoom(true);
                map.centerAndZoom(new BMap.Point(108.948, 34.263), 11); // 初始化地图,设置中心点坐标和地图级别
                //定义this指向
                let that = this
                //循环添加小图标
                for (var obj in this.UserInfoPark) {
                  //定义参数
                  let point = new BMap.Point(this.UserInfoPark[obj]['Longitude'],this.UserInfoPark[obj]['Latitude'])
                  //生成地图
                  var marker = new BMap.Marker(point);
                  map.addOverlay(marker);

                  //给小图标加参数并加点击事件
                  (()=>{
                    //给每一个小图标加点击事件
                    var Id = this.UserInfoPark[obj].ParkinglotID;
                    var Name = this.UserInfoPark[obj].ParkinglotName;
                    marker.addEventListener("click",
                      function() {
                        that.dialogVisible = true
                        that.getBerth(Id)
                      });
                    var steelContent = `<div>${Name}</div>`
                    var steelOpts = {
                      width : 200,     //信息窗口宽度
                      height: 100,     //信息窗口高度
                      title : "<b>停车场名称</b>" , //信息窗口标题
                      enableMessage:true	//设置允许信息窗发送短息
                    };

                    // new BMap.InfoWindow(steelContent, steelOpts);
                    marker.addEventListener("mouseover",
                        function() {
                          this.openInfoWindow(new BMap.InfoWindow(steelContent, steelOpts))
                        });
                    //添加鼠标离开时关闭自定义信息窗口事件
                    marker.addEventListener("mouseout",function () {
                          this.closeInfoWindow();
                        }
                    );
                  })()
                }
              });
            }, 500);
上一篇:DeBruijin HDU - 2894


下一篇:HDU LCIS 题解(线段树合并)