var RD_SALT_COLOR = [ [30, [10, 25, 68]], [32, [10, 25, 250]], [33.5, [255, 233, 102]], [34.5, [255, 155, 15]], [38, [255, 0, 0]], ]; function colorInterpolator(start, end) { var r = start[0], g = start[1], b = start[2]; var Δr = end[0] - r, Δg = end[1] - g, Δb = end[2] - b; return function(i, a) { return [ Math.floor(r + i * Δr), Math.floor(g + i * Δg), Math.floor(b + i * Δb), a, ]; }; } /** * Creates a color scale composed of the specified segments. Segments is an array of two-element arrays of the * form [value, color], where value is the point along the scale and color is the [r, g, b] color at that point. * For example, the following creates a scale that smoothly transitions from red to green to blue along the * points 0.5, 1.0, and 3.5: * * [ [ 0.5, [255, 0, 0] ], * [ 1.0, [0, 255, 0] ], * [ 3.5, [0, 0, 255] ] ] * * @param segments array of color segments * @returns {Function} a function(point, alpha) that returns the color [r, g, b, alpha] for the given point. */ function segmentedColorScale(segments) { var points = [], interpolators = [], ranges = []; for (var i = 0; i < segments.length - 1; i++) { points.push(segments[i + 1][0]); interpolators.push( colorInterpolator(segments[i][1], segments[i + 1][1]) ); ranges.push([segments[i][0], segments[i + 1][0]]); } return function(point, alpha) { var i; for (i = 0; i < points.length - 1; i++) { if (point <= points[i]) { break; } } var range = ranges[i]; return interpolators[i](proportion(point, range[0], range[1]), alpha); }; } /** * @returns {Number} the value x clamped to the range [low, high]. */ function clamp(x, low, high) { return Math.max(low, Math.min(x, high)); } /** * @returns {number} the fraction of the bounds [low, high] covered by the value x, after clamping x to the * bounds. For example, given bounds=[10, 20], this method returns 1 for x>=20, 0.5 for x=15 and 0 * for x<=10. */ function proportion(x, low, high) { return (clamp(x, low, high) - low) / (high - low); } var RD_OVERLAY_ALPHA = Math.floor(0.8 * 255); // 默认覆盖透明度 ([0, 255]) const Color = function (option){ let colorBar = RD_SALT_COLOR; let valMax = option.max; let valMin = option.min; let delta = valMax - valMin; delta = delta / (colorBar.length - 1); for (let i = 0; i < colorBar.length; i++) { colorBar[i][0] = valMin + i * delta; } this._colorgradient = segmentedColorScale(colorBar); }; Color.prototype.getColor = function (value){ let color = this._colorgradient(value); let nColor; nColor = Cesium.Color.fromBytes(color[0], color[1], color[2], 255, nColor); return nColor; }