riku
2024-02-27 7578c3ff65329b2269f099475eb687e963efac1c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
 * 监测因子类
 * 存储某一类型的监测因子数据,提供3d地图绘制高度换算,绘图范围设定等功能
 * 用于3d地图绘制
 */
;
// (function($, DataUtil) {
    function Factor(options) {
        /**
         * {factorData: 43.209
            factorId: "1"
            factorName: "NO2"
            physicalQuantity: 211.1
            sensorId: null
            statusList: null}
         */
        this.datas = [] // 原始数据
        // this.lnglats = [] //3d地图当前展示坐标点数组
        this.factorName
        this.factorId
        this.heights = [] //3d地图当前展示坐标点对应的高度数组
        this.colors = [] // 3d地图当前展示坐标点对应的颜色数组
        this.bottomColor//最小值对应的图例色
        this.min = -1 // 当前显示的最小值
        this.max = -1 // 当前显示的最大值
        this.originMin = -1 // 原始数据中的最小值
        this.originMax = -1 // 原始数据中的最大值
        this.standardMin = -1//监测因子类型对应的标准最小值
        this.standardMax = -1//监测因子类型对应的标准最大值
 
        this.legendType = Legend.S_TYPE//图例模式
 
        if (options != undefined) {
            this.datas = options.datas
            this.heights = options.heights
            this.min = options.min
            this.max = options.max
            this.originMin = options.originMin
            this.originMax = options.originMax
            
            this.factorName = options.factorName
            this.factorId = options.factorId
            this.colors = options.colors
            this.bottomColor = options.bottomColor
            this.standardMin = options.standardMin
            this.standardMax = options.standardMax
        }
    }
 
    Factor.prototype = {
        // drawMode: 绘制模式,0:自动模式,自动计算当前数据的范围,绘制合适的比例;1:手动模式,根据页面设置的绘图范围进行绘制
        pushData: function(data, drawMode) {
            if (this.factorName == undefined) {
                this.factorName = data.factorName
                this.factorId = data.factorId
            } else {
                if (this.factorName != data.factorName) {
                    console.log("错误: Factor中插入的数据前后名称不一致,原因子:" + this.factorName + ",新因子:" + data.factorName);
                }
            }
            this.datas.push(data)
            this.getRange(data, drawMode)
 
            if (this.standardMin == -1) {
                var range = Legend.getStandardRange(this.factorName)
                this.standardMin = range[0]
                this.standardMax = range[1]
            }
        },
        getRange: function(data, drawMode) {
            if (this.min == -1) {
                this.min = data.factorData
                this.max = data.factorData
            }
            if (this.originMin == -1) {
                this.originMin = data.factorData
                this.originMax = data.factorData
            }
            if (drawMode == 0) {
                this.min = Math.min(this.min, data.factorData)
                this.max = Math.max(this.max, data.factorData)
                // this.min = this.standardMin
                // this.max = this.standardMax
            }
            this.originMin = Math.min(this.originMin, data.factorData)
            this.originMax = Math.max(this.originMax, data.factorData)
        },
        getHeight: function() {
            this.heights = []
            this.colors = []
            this.datas.forEach(d => {
                var h = DataUtil.getFactorHeight(d.factorId, d.factorData, [this.min, this.max])
                if (d.factorData == -1) {
                    h = -1
                }
                this.heights.push(h)
                var c = Legend.getColor(this.factorName, this.legendType, d.factorData, this.min, this.max)
                this.colors.push(c)
                // this.heights.push(d.factorData)
            });
            this.bottomColor = Legend.getColor(this.factorName, this.legendType, this.standardMin, this.min, this.max)
            // console.log(this.factorName + ':' + this.bottomColor);
        },
        setRange: function(range) {
            this.min = range[0]
            this.max = range[1]
            this.legendType = Legend.C_TYPE
            this.getHeight()
        },
        clearRange: function() {
            this.min = this.originMin
            this.max = this.originMax
            this.legendType = Legend.D_TYPE
            this.getHeight()
        },
        standardRange: function() {
            this.min = this.originMin
            this.max = this.originMax
            // this.min = this.standardMin
            // this.max = this.standardMax
            this.legendType = Legend.S_TYPE
            this.getHeight()
        },
        // 根据开始和结束下标获取对应位置数据集
        getByIndex: function(s, e) {
            var d = this.datas.slice(s, e)
            var h = this.heights.slice(s, e)
            return new Factor({
                datas: d,
                heights: h,
                min: this.min,
                max: this.max,
                originMin: this.originMin,
                originMax: this.originMax,
                factorName: this.factorName,
                colors: this.colors,
                bottomColor: this.bottomColor,
                standardMin: this.standardMin,
                standardMax: this.standardMax,
            })
        },
        // 新增数据同时插帧
        insertFrame: function(factor, count, isDraw) {
            var d1 = this.datas[this.datas.length - 1]
            var d2 = factor.datas[0]
            if (d1 == undefined || d2 == undefined) {
                return
            }
            // 单帧数据值的差值
            var dValue = {
                factorData: (d2.factorData - d1.factorData) / count,
                physicalQuantity: (d2.physicalQuantity - d2.physicalQuantity) / count
            }
            for (let i = 0; i < count - 1; i++) {
                var _data = {
                    factorData: d1.factorData + dValue.factorData * (i + 1),
                    factorId: d1.factorId,
                    factorName: d1.factorName,
                    physicalQuantity: d1.physicalQuantity + dValue.physicalQuantity * (i + 1),
                    sensorId: d1.sensorId,
                    statusList: d1.statusList,
                }
                if (!isDraw) {
                    _data.factorData = -1
                    _data.physicalQuantity = -1
                }
                this.datas.push(_data)
            }
            // this.datas.push(d2)
        }
    }
// })(jQuery, DataUtil);