ZhuDongming
2019-08-08 90a6386cda8e3356c23f283656bf94e21e94b46a
src/main/webapp/js/moralmap.js
@@ -48,7 +48,6 @@
            minZoom: 12,
            maxZoom: 20
        };
       debugger;
       if(!!arguments[1]) {
         $.extend(defaultParam,arguments[1]);
        }
@@ -59,7 +58,9 @@
         style: "normal" //设置地图风格为高端黑 
      }
      map.setMapStyle(mapStyle);
      var showZoom = 12;
        var showZoom = !!arguments[2]
        && arguments[2] <=defaultParam.maxZoom
        && arguments[2] >= defaultParam.minZoom?arguments[2]:12;
        var address = arguments[0];
        var regoinNames = address.split(" ");
        var cityName = regoinNames.length>1?regoinNames[1]:regoinNames[0];
@@ -121,7 +122,7 @@
      var startZoom = moralMap.startZoom();
      //刷新key防止延迟加载
      //      var key = moralMap.lazyKeyer();
      var confine = moralMap.getZooMConfine();
      var confine = moralMap.getZoomConfine();
      if(endZoom > startZoom) {
         //放大超过边界
         if(endZoom >= confine && startZoom <= confine) {
@@ -158,13 +159,13 @@
       if(!!baiduBounds){
            this.northeastLng = baiduBounds.xl.lng;//东北角经度,大一点
            this.northeastLat = baiduBounds.xl.lat;//东北角纬度,大一点
            this.southwestLng = baiduBounds.Ol.lng;//西北角经度坐标,小一点
            this.southwestLat = baiduBounds.Ol.lat;//西北角纬度坐标,小一点
            this.southwestLng = baiduBounds.Ol.lng;//西南角经度坐标,小一点
            this.southwestLat = baiduBounds.Ol.lat;//西南角经度坐标,小一点
      }else{
            this.northeastLng = null;//东北角经度,大一点
            this.northeastLat = null;//东北角纬度,大一点
            this.southwestLng = null;//西北角经度坐标,小一点
            this.southwestLat = null;//西北角纬度坐标,小一点
            this.southwestLng = null;//西南角经度坐标,小一点
            this.southwestLat = null;//西南角经度坐标,小一点
      }
    }
   moralMap.getBounds = function() {
@@ -209,9 +210,10 @@
   }
   moralMap.addOverlay = function(overlay) {
      if(overlay.getMap() != baiduMap) {
         setTimeout(function(){
         // setTimeout(function(){
            baiduMap.addOverlay.call(baiduMap, overlay);
         },10);
         // },10);
            baiduMap.addOverlay.call(baiduMap, overlay);
      }
   }
   moralMap.addOverlays = function(overlays) {
@@ -222,8 +224,16 @@
      }
   }
   moralMap.removeOverlay = function() {
   moralMap.removeOverlay = function(overlay) {
        // baiduMap.removeOverlay(overlay);
      baiduMap.removeOverlay.apply(baiduMap, arguments);
   }
   moralMap.removeOverlays = function(overlays) {
        if(overlays != null && typeof overlays == 'object') {
            for (var i in overlays) {
                moralMap.removeOverlay(overlays[i]);
            }
        }
   }
   moralMap.getOverlays = function() {
      var overLays = baiduMap.getOverlays.apply(baiduMap, arguments)
@@ -313,12 +323,12 @@
        if(window["console"]!=undefined){
            console.log(equStr);
        }
        if(!!window['external']&&window['external']['callWin']){
        if(!!window['external']&&!!window['external']['callWin']){
            window['external'].callWin(equStr);
        }else{
             if(!!select&&select==='chart'&&!!window['external']&&window['external']['showChartInfo']){
             if(!!select&&select==='chart'&&!!window['external']&&!!window['external']['showChartInfo']){
                    window['external'].showChartInfo(equStr);
                }else if(!!window['external']&&window['external']['showMonitorInfo']){
                }else if(!!window['external']&&!!window['external']['showMonitorInfo']){
                    window['external'].showMonitorInfo(equStr);
                }else{
                    alert(equStr);
@@ -498,7 +508,8 @@
      function _getMapIcon(state) {
         state = state == null ? 0 : state;
         var icon = _option["icon"];
         var url = icon["stateIcons"][state];
         //var url = icon["stateIcons"][state];
         var url = icon["url"] + state + ".png";
         return new BMap.Icon(url, new BMap.Size(icon["width"], icon["height"]), {
            imageSize: new BMap.Size(icon["width"], icon["height"])
         });
@@ -541,12 +552,21 @@
   moralMap.MoralMarker.prototype = new BMap.Marker();
   //监控点对象 包装Mark对象
   moralMap.Monitorpoint = function(option) {
      if(monitorPointStates){
         for(var i in monitorPointStates){
             var state = monitorPointStates[i];
             if(state.id == option.id){
                option.state = state.state;
             }
         }
      }
      var icon = {};
      icon["stateIcons"] = ["/img/ico00.png", "/img/ico01.png", "/img/ico02.png", "/img/ico03.png", "/img/ico04.png"];
      icon["url"] = "/img/ico0";
      icon["width"] = 50;
      icon["height"] = 50;
      option["icon"] = icon;
      var moralMask = new moralMap.MoralMarker(option);
      var moralMarker = new moralMap.MoralMarker(option);
      //       var mark =new BMap.Marker(pointObj,{icon:iconObj});
      //==================infoWindow-start============================
      var infoWindow = (function() {
@@ -583,26 +603,26 @@
            adressOutHtml += "<tbody><tr><td style='vertical-align:top;width:38px;white-space:nowrap;word-break:keep-all'>地址:&nbsp;</td><td style='line-height:16px'>";
            adressOutHtml += address + "&nbsp;";
            adressOutHtml += "</td></tr>";
                adressOutHtml += "<tr><td style='width:98%;padding-top:10px;'colspan='2'><a href='javascript:void(0);' style='display:block;position: relative;float: right;' onclick='moralMap.showPointMonitor("+option.id+")'>实时数据>></a></td></tr>";
                //adressOutHtml += "<tr><td style='width:98%;padding-top:10px;'colspan='2'><a href='javascript:void(0);' style='display:block;position: relative;float: right;' onclick='moralMap.showPointMonitor("+option.id+")'>实时数据>></a></td></tr>";
                adressOutHtml += "</tbody></table></div>";
            return adressOutHtml;
         }
         return new BMap.InfoWindow(getAdressOutHtml(), winOpts);
      })();
      if(moralMask["infoWindow"] == undefined) {
         moralMask["infoWindow"] = infoWindow;
      if(moralMarker["infoWindow"] == undefined) {
         moralMarker["infoWindow"] = infoWindow;
      }
      //弹窗打开和关闭
      moralMask.addEventListener("mouseover", function() {
      moralMarker.addEventListener("mouseover", function() {
         moralMap.openInfoWindow(infoWindow, this._point); //开启信息窗口
      });
      moralMask.addEventListener("mouseout", function() {
      moralMarker.addEventListener("mouseout", function() {
            moralMap.closeInfoWindow();
      });
      //==================infoWindow-end============================
      //储存监控点
      moralMap.putMpoint(option['id'], moralMask);
      return moralMask;
      moralMap.putMpoint(option['id'], moralMarker);
      return moralMarker;
   }
   //储存MonitorPoint对象
   moralMap.putMpoint = function(key, obj) {
@@ -629,8 +649,17 @@
   //设备以mac为key储存
   //监控点对象 包装MoralMark对象
   moralMap.Equipment = function(option) {
      if(deviceStates){
         for(var i in deviceStates){
             var state = deviceStates[i];
             if(state.id == option.id){
                option.state = state.state;
             }
         }
      }
      var icon = {};
      icon["stateIcons"] = ["/img/ico_coo00.png", "/img/ico_coo01.png", "/img/ico_coo02.png", "/img/ico_coo03.png", "/img/ico_coo04.png"];
      icon["url"] = "/img/ico_coo0";
      icon["width"] = 50;
      icon["height"] = 60;
      option["icon"] = icon;
@@ -638,10 +667,52 @@
      option["offline_height"] = 80;
      option["online_width"] = 355;
      option["online_height"] = 385;
      var moralMask = new moralMap.MoralMarker(option);
      var moralMarker = new moralMap.MoralMarker(option);
      //       var mark =new BMap.Marker(pointObj,{icon:iconObj});
      //==================infoWindow-start============================
      var infoWindow = (function() {
         //生成信息框
         var winOpts = {
            width: 110, // 信息窗口宽度
            height: 80, // 信息窗口高度
            title: getTitleOutHtml(), // 信息窗口标题
            offset: new BMap.Size(-8,-5) //设置信息窗偏移
         }
         function getTitleOutHtml() {
            //title太长用引号...
            var title = (option["name"] == null) ? "" : option["name"];
            if(title.length > 13) {
               title = title.slice(0, 13) + "...";
            }
            var titleOutHtml = "";
            titleOutHtml += "<p style='width:210px;font:bold 14px/16px arial,sans-serif;margin:0;color:#cc5522;white-space:nowrap;overflow:hidden'"
            titleOutHtml += "title='" + option["name"] + "'>";
            titleOutHtml += title + "</p>";
            return titleOutHtml;
         }
         function getAdressOutHtml() {
            var address = (option["address"] == null) ? "" : option["address"];
            if(address.length > 18) {
               address = address.slice(0, 18) + "...";
            }
            var adressOutHtml = "";
            adressOutHtml += "<div onmouseover='moralMap.clearCloseInfoWindow()'";
                adressOutHtml +=   "onmouseout='moralMap.closeInfoWindow()'";
                adressOutHtml   +=" style='font:12px arial,sans-serif;margin-top:12px'><table cellspacing='0' style='overflow:hidden;table-layout:fixed;width:100%;font:12px arial,sans-serif'>";
            adressOutHtml += "<tbody><tr><td style='vertical-align:top;width:38px;white-space:nowrap;word-break:keep-all'>地址:&nbsp;</td><td style='line-height:16px'>";
            adressOutHtml += address + "&nbsp;";
            adressOutHtml += "</td></tr>";
                adressOutHtml += "</tbody></table></div>";
                //$("#searchParam").val(address);
            return adressOutHtml;
         }
         return new BMap.InfoWindow(getAdressOutHtml(), winOpts);
      })();
      /*var infoWindow = (function() {
         //生成信息框
         var winOpts = {
            width: option["online_width"], // 信息窗口宽度
@@ -715,14 +786,14 @@
            }
            return grade+"00";
         }
      };
      };*/
      if(moralMask["infoWindow"] == undefined) {
         moralMask["infoWindow"] = infoWindow;
      if(moralMarker["infoWindow"] == undefined) {
         moralMarker["infoWindow"] = infoWindow;
      }
        var  mouseOverHandle = option['mouseover'];
      //弹窗打开和关闭
      moralMask.addEventListener("mouseover", function() {
      /*moralMarker.addEventListener("mouseover", function() {
         if(mouseOverHandle!=null&&mouseOverHandle instanceof  Function){
                //将arguments转换成数组
                var args = Array.prototype.slice.call(arguments);
@@ -744,23 +815,32 @@
            infoWindow.redraw();
         }
      });
      moralMask.addEventListener("mouseout", function() {
      moralMarker.addEventListener("mouseout", function() {
         baiduMap.closeInfoWindow();
         infoWindow.setContent("");
         moralMap.openSearchBox();
      });*/
      moralMarker.addEventListener("mouseover", function() {
         moralMap.openInfoWindow(infoWindow, this._point); //开启信息窗口
      });
      moralMarker.addEventListener("mouseout", function() {
            moralMap.closeInfoWindow();
      });
      //==================infoWindow-end============================
      //储存监控点
      moralMap.putEquipment(option['mac'], moralMask);
      var _super_refreshState = moralMask.refreshState;
      return $.extend(moralMask, {
      moralMap.putEquipment(option['mac'], moralMarker);
      var _super_refreshState = moralMarker.refreshState;
      //$("#searchParam").val(option['mac']);
      return $.extend(moralMarker, {
         refreshState: function(data) {
            if(data != null && data!="") {
                   var state = this.getOption()["state"];
                   this.setData(data); //更新数据
                  _super_refreshState.call(this, data["state"]);
                  //如果当前窗体时打开的,刷新窗体里的数据
                        if(infoWindow.isOpen()) {
                        /*if(infoWindow.isOpen()) {
                           if(data["state"]==4){
                              if(state!=4){
                                     infoWindow.setHeight(option["offline_height"]);
@@ -789,7 +869,7 @@
                                 $(itme_data_mac_key).text(dataValue);
                              }
                           }
                     }
                     }*/
            }
         },
         setData:function(data){
@@ -829,8 +909,11 @@
         delete moralMap['_equipments'];
      }
   }
   moralMap.getZooMConfine = function() {
   moralMap.getZoomConfine = function() {
      return 18;
   }
   moralMap.getZoom = function() {
      return baiduMap.getZoom();
   }
   moralMap.getHorizonMarkers = function(isShow) {
      var bounds = moralMap.getBounds();
@@ -889,6 +972,59 @@
            }
      }
    }
   }
    moralMap.callJS = function(condition) {
       var new_point = new BMap.Point(condition.longitude, condition.latitude);
       baiduMap.panTo(new_point);
       baiduMap.setCenter(new_point);
      baiduMap.setZoom(condition.type == "mpoint" ? 17 : 18);
       var interval = setInterval(function(){
          var marker;
          if (condition.type == "mpoint") {
             marker = moralMap.getMpoint(condition.id);
          } else if (condition.type == "device") {
             marker = moralMap.getEquipment(condition.mac);
          }
         if(marker){
            clearInterval(interval);
            moralMap.openInfoWindow(marker["infoWindow"], new_point);
         }
      }, 50);
   }
    var deviceStates ;
    var monitorPointStates;
   moralMap.refreshState = function(states) {
      if (!monitorPointStates) {
         monitorPointStates = states;
         deviceStates = [];
         for (var i in states) {
            var state = states[i];
            for (var j in state.devices) {
               var device = state.devices[j];
               deviceStates.push(device);
            }
         }
      }
      for (var i in states) {
         var state = states[i];
         var mpoint = moralMap.getMpoint(state.id);
         if (mpoint) {
            mpoint.refreshState(state.state);
         }
         for (var j in state.devices) {
            var marker = state.devices[j];
            var marker_mac = marker["mac"];
            var equipment = moralMap.getEquipment(marker_mac);
            if (equipment) {
               equipment.refreshState(marker);
            }
         }
      }
   }
   window.moralMap = moralMap;
})(jQuery, BMap, window);