/** * 监测因子图例 */ const Legend = { S_TYPE: 0, //标准图例 D_TYPE: 1, //动态图例 C_TYPE: 2, //自定义范围图例 //各监测因子数据分级(标准) _legend_r: { NO: [0, 100, 200, 700, 1200, 2340], NO2: [0, 100, 200, 700, 1200, 2340], CO: [0, 5, 10, 35, 60, 90], H2S: [0, 150, 500, 650, 800, 1600], SO2: [0, 150, 500, 650, 800, 1600], O3: [0, 160, 200, 300, 400, 800], PM25: [0, 35, 75, 115, 150, 250], PM10: [0, 50, 150, 250, 350, 420], VOC: [0, 200, 400, 600, 1000, 2000, 4000], TMP: [-10, 0, 10, 20, 30, 40], spC: [0, 200, 400, 600, 800, 1000], tur: [0, 50, 100, 150, 200, 250], DO: [0, 3, 5, 7, 9, 11], PH: [1, 3, 5, 7, 9, 11, 13] }, //各监测因子数据分级(标准)对应颜色 _legend_c: { NO: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], NO2: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], CO: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], H2S: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], SO2: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], O3: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], PM25: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], PM10: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], VOC: [ [0, 0.89, 0, 0.75], [0, 0.7, 0, 0.75], [0.8, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.4, 0, 0.3, 0.75], [0.6, 0, 0.3, 0.75] ], TMP: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], spC: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], tur: [ [0, 0.89, 0, 0.75], [1, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.6, 0, 0.3, 0.75], [0.49, 0, 0.14, 0.75] ], DO: [ [0.49, 0, 0.14, 0.75], [0.6, 0, 0.3, 0.75], [1, 0, 0, 0.75], [1, 0.49, 0, 0.75], [1, 1, 0, 0.75], [0, 0.89, 0, 0.75] ], PH: [ [0, 0.89, 0, 0.75], [0, 0.7, 0, 0.75], [0.8, 1, 0, 0.75], [1, 0.49, 0, 0.75], [1, 0, 0, 0.75], [0.4, 0, 0.3, 0.75], [0.6, 0, 0.3, 0.75] ] }, _custom: [ [0.05, 0.9, 0.03, 0.75], [0.3, 0.65, 0.02, 0.75], [0.87, 0.92, 0.03, 0.75], [0.8, 0.67, 0.04, 0.75], [0.92, 0.28, 0.07, 0.75], [0.6, 0.05, 0.05, 0.75] ], getStandardRange: function (name) { var range = this._legend_r[name]; if (range == undefined) { range = this._legend_r['PM25']; } var min = range[0]; var max = range[range.length - 1]; // for (const key in range) { // if (min == undefined) { // min = parseInt(key) // } // max = parseInt(key) // } if (name == 'CO') { min *= 1000; max *= 1000; } return [min, max]; }, getColor: function (name, type, data, min, max) { if (!data) { return [0, 0, 0, 0]; } if (type == this.S_TYPE) { return this.getStandardColor(name, data); } else { return this.getCustomColor(data, min, max); } }, /** * 获取当前颜色上一个等级的颜色 * @param {*} name * @param {*} type * @param {*} color */ getPreviousColor(name, type, color) { let colors; if (type == this.S_TYPE) { colors = this._legend_c[name]; } else { colors = this._custom; } if (colors == undefined) { colors = this._legend_c['PM25']; } let index = colors.indexOf(color); index--; if (index < 0) index = 0; return colors[index]; }, /** * 获取监测因子当前浓度对应的颜色 * @param name 监测因子名称 * @param data 监测因子浓度 */ getStandardColor: function (name, data) { let range = this._legend_r[name]; let colors = this._legend_c[name]; if (range == undefined) { range = this._legend_r['PM25']; colors = this._legend_c['PM25']; } // return colors[0] let selected = undefined; for (let i = 0; i < range.length; i++) { const d = range[i]; let d1 = d; if (name == 'CO') { d1 *= 1000; } if (data >= d1) { selected = i; } else { break; } } // 避免下标越界 if (selected >= colors.length) { selected = colors.length - 1; } // console.log(name + ': ' + selected); return colors[selected]; }, getStandardColorAndNext: function (name, data) { if (!data) { return { color: [0, 0, 0, 0], nextColor: [0, 0, 0, 0], range: 0, nextRange: 0 }; } let range = this._legend_r[name]; let colors = this._legend_c[name]; if (range == undefined) { range = this._legend_r['PM25']; colors = this._legend_c['PM25']; } let selected = undefined; for (let i = 0; i < range.length; i++) { const d = range[i]; let d1 = d; if (name == 'CO') { d1 *= 1000; } if (data >= d1) { selected = i; } else { break; } } // 避免下标越界 if (selected >= colors.length) { selected = colors.length - 1; } let nextIndex = selected + 1; if (nextIndex >= colors.length) { nextIndex = colors.length - 1; } return { color: colors[selected], nextColor: colors[nextIndex], range: range[selected], nextRange: range[nextIndex] }; }, getCustomColor: function (data, min, max) { var per = (max - min) / this._custom.length; var i = parseInt(data / per); if (i >= this._custom.length) { i = this._custom.length - 1; } return this._custom[i]; } }; export { Legend };