百度地图循环添加标注,并循环为鼠标悬停标注时信息窗口问题解决

 //设备在地图上进行标注
    function GetGateInfo(vSID, vMap) {

        var icon = "../Content/easyui/themes/icons/gate.png";
        var myIcon = new BMap.Icon(icon, new BMap.Size(32, 32), {
            offset: new BMap.Size(32, 32)
        });

        $.ajax({
            type: "post",
            url: "/MonitorManage/GetStationGate?SID=" + vSID,
            success: function (obj) {
              
                    for (var i = 0; i < obj.length; i++) {
                        //var vGateID = obj[i].GateID;
                        //var vGateName = obj[i].GateName;
                        //var vlongitude = obj[i].Longitude;
                        //var vlatitude = obj[i].Latitude;

                        //var point = new BMap.Point(obj[i].Longitude, obj[i].Latitude);     //POI点坐标
                        //var marker = new BMap.Marker(point, { icon: myIcon });
                        //vMap.addOverlay(marker);

                       
                        (function (x) {
                            var point = new BMap.Point(obj[x].Longitude, obj[x].Latitude);    // 创建点坐标  
                            alert(point);
                            var marker = new BMap.Marker(point,{icon:myIcon});
                            // 创建信息窗口对象,引号里可以书写任意的html语句。
                            var infoWindow = new BMap.InfoWindow
                                ("<table class='mytable'  border='0' cellspacing='0' cellpadding='0'>"
                                + "<tr><td>站点名称:" + obj[x].GateName
                                + "</td></tr><tr><td>经度:" + obj[x].Longitude
                                + "</td></tr><tr><td>纬度:" + obj[x].Latitude
                                + "</td></tr></table>");

                            // 鼠标移上标注点要发生的事
                            marker.addEventListener("mouseover", function () {
                                this.openInfoWindow(infoWindow);
                            });

                            // 鼠标移开标注点要发生的事
                            marker.addEventListener("mouseout", function () {
                                this.closeInfoWindow(infoWindow);
                            });
                            vMap.addOverlay(marker);
                        })(i);
                        创建信息窗口对象,引号里可以书写任意的html语句。
                        //var infoWindow = new BMap.InfoWindow
                        //    ("<table class='mytable'  border='0' cellspacing='0' cellpadding='0'>"
                        //    + "<tr><td>站点名称:" + vGateName
                        //    + "</td></tr><tr><td>经度:" + vlongitude
                        //    + "</td></tr><tr><td>纬度:" + vlatitude
                        //    + "</td></tr></table>");

                        鼠标移上标注点要发生的事
                        //marker.addEventListener("mouseover", function () {
                        //    this.openInfoWindow(infoWindow,point);
                        //});

                        鼠标移开标注点要发生的事
                        //marker.addEventListener("mouseout", function () {
                        //    this.closeInfoWindow(infoWindow, point);
                        //});
                    }
                }
            
        })
    }

 

转载于:https://www.cnblogs.com/yiran123456/p/5556073.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值