于紫祥_1901
2020-09-10 9a3d7f190717a6e3af608ffa0d78c66b6bcc0e8a
src/main/webapp/js/newmoralmap.js
@@ -644,6 +644,7 @@
        return listView;
    }
    moralMap.MoralMarker = function (option) {
        var _option = option;
        var _pointObj = new BMap.Point(_option['longitude'], _option['latitude']);
@@ -695,8 +696,76 @@
            }
        })
    }
    moralMap.WindMarker = function (option, moralMap) {
        var _option = option;
        var _pointObj = new BMap.Point(_option['longitude'], _option['latitude']);
        var _iconObj = _getWindIcon(1);
        this._point = _pointObj;
        function _getWindIcon(speedLevel) {
            speedLevel = speedLevel == null ? 0 : speedLevel;
            var windIcon = _option["windIcon"];
            var windUrl = windIcon["url"] + speedLevel + ".png";
            return new BMap.Icon(windUrl, new BMap.Size(windIcon["width"], windIcon["height"]), {
                imageSize: new BMap.Size(windIcon["width"], windIcon["height"])
            });
        }
        this.constructor.call(this, _pointObj, {
            icon: _iconObj,
            offset: new BMap.Size(0, -11),
            enableMassClear: true
        })
        return $.extend(this, {
            refreshWindDir: function (windDir, windSpeed) {
                //状态发生变化的时候设置图标风向
                if (windDir == undefined || windSpeed == undefined) {
                    moralMap.removeOverlay(this);
                } else {
                    var speedLevel;
                    if (windSpeed >= 0 && windSpeed <= 0.2) {
                        speedLevel = 0;
                    } else if (windSpeed > 0.2 && windSpeed <= 1.5) {
                        speedLevel = 1;
                    } else if (windSpeed > 1.5 && windSpeed <= 3.3) {
                        speedLevel = 2;
                    } else if (windSpeed > 3.3 && windSpeed <= 5.4) {
                        speedLevel = 3;
                    } else if (windSpeed > 5.4 && windSpeed <= 7.9) {
                        speedLevel = 4;
                    } else if (windSpeed > 7.9 && windSpeed <= 10.7) {
                        speedLevel = 5;
                    } else if (windSpeed > 10.7 && windSpeed <= 13.8) {
                        speedLevel = 6;
                    } else if (windSpeed > 13.8 && windSpeed <= 17.1) {
                        speedLevel = 7;
                    } else if (windSpeed > 17.1) {
                        speedLevel = 8;
                    }
                    if (speedLevel == 0) {
                        moralMap.removeOverlay(this);
                    } else {
                        moralMap.addOverlay(this);
                        var iconObj = _getWindIcon(speedLevel);
                        this.setIcon(iconObj);
                        this.setRotation(windDir);
                    }
                }
            },
            getOption: function () {
                return _option;
            },
            setOption: function (option) {
                _option = option;
            }
        })
    }
    //new BMap.Marker()这种写法IE7会报错,很奇葩
    moralMap.MoralMarker.prototype = new BMap.Marker();
    moralMap.WindMarker.prototype = new BMap.Marker();
    //监控点对象 包装Mark对象
    moralMap.Monitorpoint = function (option) {
        if (monitorPointStates) {
@@ -777,7 +846,7 @@
    var sensorsDescriptionMap;
    var sensorsUnitMap;
    $.ajax({
        url: "getSensorsMap",
        url: "getSensorsAllMap",
        type: "get",
        dataType: "json",
        success: function (data) {
@@ -785,6 +854,41 @@
            sensorsUnitMap = data[1];
        }
    });
    moralMap.Device = function (option) {
        if (deviceStates) {
            for (var i in deviceStates) {
                var state = deviceStates[i];
                if (state.id == option.id) {
                    option.state = state.state;
                }
            }
        }
        var windIcon = {};
        windIcon["url"] = "/img/icoWind0";
        windIcon["width"] = 25;
        windIcon["height"] = 25;
        option["windIcon"] = windIcon;
        var windMarker = new moralMap.WindMarker(option, moralMap);
        moralMap.putDevice(option['mac'], windMarker);
        var refreshWindMarker = windMarker.refreshWindDir;
        return $.extend(windMarker, {
            refreshWindDir: function (data) {
                if (data != null && data != "") {
                    this.setData(data); //更新数据
                    refreshWindMarker.call(this, data["e23"], data["e18"]);
                }
            },
            setData: function (data) {
                var option = this.getOption();
                option["data"] = data;
                this.setOption(option);
            },
            getData: function () {
                return this.getOption()["data"];
            }
        });
    }
    //设备以mac为key储存
    //监控点对象 包装MoralMark对象
@@ -851,13 +955,16 @@
            }
            moralMap.showSensors = function (jsonData) {
                /* var deviceSensors = jsonData;
                 var mac = deviceSensors["mac"];
                 if (mac == option['mac']) {*/
                if (!jsonData.hasOwnProperty('mac')) {
                    infoWindow.setContent("");
                    infoWindow.redraw();
                } else {
                    var adressOutHtml = '<div style="min-height:20px;overflow:auto;max-height:400px;font-size: 12px;" onmouseover="moralMap.clearCloseInfoWindow()" onmouseout="moralMap.closeInfoWindow()">';
                    var adressOutHtml = '<div style="min-height:20px;overflow:auto;max-height:480px;font-size: 12px;" onmouseover="moralMap.clearCloseInfoWindow()" onmouseout="moralMap.closeInfoWindow()">';
                    var y, m, d, h, mm, s;
                    var date = new Date(jsonData['time']);
                    var date = new Date($.now());
                    y = 1900 + date.getYear();
                    m = "0" + (date.getMonth() + 1);
                    d = "0" + date.getDate();
@@ -889,6 +996,7 @@
                    infoWindow.redraw();
                }
            }
            // }
            /*   if (!$.isEmptyObject(sensorInfo)) {
                   moralMap.openInfoWindow(infoWindow, this._point); //开启信息窗口
               }*/
@@ -952,6 +1060,31 @@
    moralMap.getEquipments = function (key) {
        return moralMap['_equipments'];
    }
    moralMap.putDevice = function (key, obj) {
        if (key != null && key != "") {
            key = String.prototype.toLowerCase.call(key);
            if (moralMap['_devices'] == undefined) {
                moralMap['_devices'] = {};
            }
            moralMap['_devices'][key] = obj;
        }
    }
    moralMap.getDevice = function (key) {
        if (key == null) {
            return null;
        }
        key = String.prototype.toLowerCase.call(key);
        if (typeof moralMap['_devices'] === 'object') {
            return moralMap['_devices'][key];
        }
    }
    moralMap.getDevices = function (key) {
        return moralMap['_devices'];
    }
    moralMap.clearEquipments = function () {
        if (moralMap['_equipments'] != undefined) {
            delete moralMap['_equipments'];
@@ -985,12 +1118,53 @@
                        if (longitude < bounds.northeastLng && longitude > bounds.southwestLng && latitude < bounds.northeastLat && latitude > bounds.southwestLat) {
                            markers.push(oldmarker);
                        }
                        if("国控站"===option["monitorPoint"]["description"]){
                            var icon05 = new BMap.Icon("/img/ico05.png", new BMap.Size(50, 50));
                            var mark05 = new BMap.Marker(new BMap.Point(option["monitorPoint"]["longitude"], option["monitorPoint"]["latitude"]), {icon: icon05});
                            markers.push(mark05);
                        }else if("省控站"===option["monitorPoint"]["description"]){
                            var icon06 = new BMap.Icon("/img/ico06.png", new BMap.Size(50, 50));
                            var mark06 = new BMap.Marker(new BMap.Point(option["monitorPoint"]["longitude"], option["monitorPoint"]["latitude"]), {icon: icon06});
                            markers.push(mark06);
                        }else if("县控站"===option["monitorPoint"]["description"]){
                            var icon08 = new BMap.Icon("/img/ico08.png", new BMap.Size(50, 50));
                            var mark08 = new BMap.Marker(new BMap.Point(option["monitorPoint"]["longitude"], option["monitorPoint"]["latitude"]), {icon: icon08});
                            markers.push(mark08);
                        }
                    }
                }
            }
        }
        return markers;
    }
    moralMap.getHorizonWindMarkers = function (isShow) {
        var bounds = moralMap.getBounds();
        var oldWindMarkerList;
        var isShow = (isShow) ? baiduMap : null;
        if (moralMap.layer() == "equipments") {
            oldWindMarkerList = moralMap.getDevices();
        }
        var markers = [];
        if (oldWindMarkerList != null && typeof oldWindMarkerList == "object") {
            for (var i in oldWindMarkerList) {
                var oldWindMarker = oldWindMarkerList[i];
                if (oldWindMarker != null && oldWindMarker instanceof BMap.Overlay && oldWindMarker.getMap() == isShow) {
                    var option = oldWindMarker.getOption();
                    if (typeof option == 'object') {
                        var longitude = option['longitude'];
                        var latitude = option['latitude'];
                        // 检索当前坐标范围内的组件
                        if (longitude < bounds.northeastLng && longitude > bounds.southwestLng && latitude < bounds.northeastLat && latitude > bounds.southwestLat) {
                            markers.push(oldWindMarker);
                        }
                    }
                }
            }
        }
        return markers;
    }
    moralMap.showPointMonitor = function (id) {
        var mpointMarker = moralMap.getMpoint(id);
        var mpoint = mpointMarker.getOption();
@@ -1072,5 +1246,14 @@
        }
    }
    moralMap.refreshWindDir = function (devicesInfo) {
        var deviceInfo = devicesInfo;
        var mac = deviceInfo["mac"];
        var device = moralMap.getDevice(mac);
        if (device) {
            device.refreshWindDir(deviceInfo);
        }
    }
    window.moralMap = moralMap;
})(jQuery, BMap, window);