Interactive interface for browsing global, full-resolution satellite imagery
Multiple colormaps
Mike McGann5c59c3168dd8
diff --git a/bin/wv-options-build b/bin/wv-options-buildindex 2c9db6c22..b46f99f47 100755--- a/bin/wv-options-build+++ b/bin/wv-options-build@@ -59,7 +59,8 @@ if [ -e "$BUILD_DIR/colormaps" ] ; thenif [ -d "$BUILD_DIR"/gc/colormaps ] ; thencp -r "$BUILD_DIR"/gc/colormaps "$BUILD_DIR"/colormaps/gcfi- "$BIN_DIR/wv-options-colormap" "$BUILD_DIR/colormaps" \+ "$BIN_DIR/wv-options-colormap" "$OPT_DIR/$ENV/config.json" \+ "$BUILD_DIR/colormaps" \"$BUILD_DIR/config/palettes"fidiff --git a/bin/wv-options-colormap b/bin/wv-options-colormapindex 01cf23b44..ba7ad1f30 100755--- a/bin/wv-options-colormap+++ b/bin/wv-options-colormap@@ -19,108 +19,114 @@ import xmltodictprog = os.path.basename(__file__)base_dir = os.path.join(os.path.dirname(__file__), "..")-version = "1.0.0"+version = "3.0.0"help_description = """\Converts colormaps to JSON files"""-parser = OptionParser(usage="Usage: %s <input_dir> <output_dir>" % prog,+parser = OptionParser(usage="Usage: %s <config_file> <input_dir> <output_dir>" % prog,version="%s version %s" % (prog, version),epilog=help_description)(options, args) = parser.parse_args()-if len(args) != 2:+if len(args) != 3:parser.error("Invalid number of arguments")-input_dir = args[0]-output_dir = args[1]+config_file = args[0]+input_dir = args[1]+output_dir = args[2]-def to_list(items):- if not isinstance(items, list):- items = [items]- return items+with open(config_file) as fp:+ config = json.load(fp)+skips = config.get("skipPalettes", [])-def process_file(file):- input_file = os.path.join(root, file)- with open(input_file) as fp:- xml = fp.read()- document = xmltodict.parse(xml)+def to_list(v):+ return v if isinstance(v, list) else [v]- scaleColors = []- scaleLabels = []- scaleValues = []- classColors = []- classLabels = []- specialColors = []- specialLabels = []- units = None- minValue = float("inf")- maxValue = float("-inf")-- # Find the colormap with the Legend- entries = None- colormaps = to_list(document["ColorMaps"]["ColorMap"])- for colormap in colormaps:- items = to_list(colormap["Entries"]["ColorMapEntry"])- for item in items:- if item.get("@transparent", "false") == "false":- entries = items- break- if entries:- break+def get_map_type(entries):+ for entry in entries:+ if entry.get("@transparent", "false") == "true":+ pass+ elif "@value" in entry:+ return "scale"+ else:+ return "class"+ return "special"++def process_entries(entries):+ entries = to_list(entries)+ map_type = get_map_type(entries)++ colors = []+ labels = []+ values = []- if not entries:- raise ValueError("No valid ColorMap found")+ color_format = "{0:02x}{1:02x}{2:02x}{3:02x}"for entry in entries:r,g,b = entry["@rgb"].split(",")- a = 255- if "@transparent" in entry and entry["@transparent"] == "true":- a = 0- color = "{0:02x}{1:02x}{2:02x}{3:02x}".format(int(r), int(g), int(b), a)- label = entry["@label"]+ a = 0 if entry.get("@transparent", "false") == "true" else 255if a == 0:- specialColors += [color]- specialLabels += [label]- elif "@value" in entry:+ continue+ colors += [color_format.format(int(r), int(g), int(b), a)]+ labels += [entry["@label"]]+ if map_type == "scale":items = re.sub(r"[\(\)\[\]]", "", entry["@value"]).split(",")try:- for scaleValue in items:- v = float(scaleValue)+ values += [map(lambda v: float(v), items)]+ for item in items:+ v = float(item)if v == float("inf"):v = sys.float_info.maxif v == float("-inf"):v = sys.float_info.min- scaleValues += [v]+ values += [v]except ValueError as e:raise ValueError("Invalid value: %s" % entry["@value"])- scaleColors += [color]- scaleLabels += [label]- else:- classColors += [color]- classLabels += [label]+ result = {+ "type": map_type,+ "colors": colors,+ "labels": labels+ }+ if map_type == "scale":+ result["values"] = values+ return result+++def process_file(file):+ input_file = os.path.join(root, file)id = os.path.splitext(os.path.basename(input_file))[0]- data = {}- if len(scaleColors) > 0:- data["scale"] = {- "colors": scaleColors,- "values": scaleValues,- "labels": scaleLabels,- }- if len(specialColors) > 0:- data["special"] = {- "colors": specialColors,- "labels": specialLabels- }- if len(classColors) > 0:- data["classes"] = {- "colors": classColors,- "labels": classLabels,- }-- data["id"] = id+ if id in skips:+ sys.stderr.write("%s: WARN: [%s] %s\n" % (prog, input_file,+ "Skipping"))+ return+ with open(input_file) as fp:+ xml = fp.read()+ document = xmltodict.parse(xml)++ colormaps = to_list(document["ColorMaps"]["ColorMap"])+ maps = []+ for colormap in colormaps:+ result = {}+ entries = process_entries(colormap["Entries"]["ColorMapEntry"])+ if entries["type"] == "special":+ continue+ result["entries"] = entries+ if "@title" in colormap:+ result["entries"]["title"] = colormap["@title"]+ if "WorldviewLegend" in colormap:+ legend = process_entries(colormap["WorldviewLegend"]["LegendEntry"])+ result["legend"] = legend+ if "@title" in colormap:+ result["legend"]["title"] = colormap["@title"]+ maps += [result]++ data = {+ "id": id,+ "maps": maps+ }json_options = {}json_options["indent"] = 4json_options["separators"] = (',', ': ')@@ -140,8 +146,7 @@ for root, dirs, files in os.walk(input_dir):process_file(file)except Exception as e:sys.stderr.write("%s: ERROR: [%s] %s\n" % (prog, file, str(e)))- # FIXME: Change back to error count!!!- # error_count += 1+ error_count += 1print "%s: %d error(s), %d file(s)" % (prog, error_count, file_count)diff --git a/web/css/wv.palettes.css b/web/css/wv.palettes.cssindex d48df2ef3..78c7530b8 100644--- a/web/css/wv.palettes.css+++ b/web/css/wv.palettes.css@@ -37,24 +37,41 @@vertical-align: middle;}-.bank div .wv-palette {+.bank div.wv-palette {+ padding-bottom: 3px;+}++.bank div.wv-palettes-legend {margin-top: 5px;}-.wv-palettes-ranges {- margin-top: -6px;+.bank div.wv-palettes-ranges {+ margin-top: -3px;width: 100%;+ position: relative;}-.wv-palettes-min, .wv-palettes-max{- font-size:0.8em;+.wv-palettes-min, .wv-palettes-title, .wv-palettes-max{+ font-size:0.7em;white-space:nowrap;}-.layer-hidden .wv-palettes-min, .layer-hidden .wv-palettes-max{+.layer-hidden .wv-palettes-min, .layer-hidden .wv-palettes-max, .layer-hidden .wv-palettes-title {color:#999;}-.wv-palettes-max {- float: right;+.bank div.wv-palettes-title {+ margin: 0 auto;+ width: 100%;+ text-align: center;+}+.bank div.wv-palettes-min {+ position: absolute;+ left: 0;+ width: auto;+}+.bank div.wv-palettes-max {+ position: absolute;+ right: 0;+ width: auto;}/* FIXME: Too specific */@@ -127,3 +144,8 @@#wv-layers-options-dialog .noUi-target {margin: 10px 10px 10px 15px;}++.wv-legend-buttons {+ width: 100%;+ text-align: center;+}diff --git a/web/js/palettes/wv.palettes.js b/web/js/palettes/wv.palettes.jsindex 790613cf8..08ec567d7 100644--- a/web/js/palettes/wv.palettes.js+++ b/web/js/palettes/wv.palettes.js@@ -29,7 +29,7 @@ wv.palettes = (function(self) {}};- self.colorbar = function(target, palette) {+ self.colorbar = function(target, colors) {var canvas;if ( target.length ) {canvas = $(target).get(0);@@ -43,10 +43,6 @@ wv.palettes = (function(self) {g.fillStyle = checkerboard;g.fillRect(0, 0, canvas.width, canvas.height);- if ( !palette ) {- return;- }- var colors = palette.colors || palette.scale.colors;if ( colors ) {var bins = colors.length;var binWidth = canvas.width / bins;@@ -81,23 +77,14 @@ wv.palettes = (function(self) {checkerboard = g.createPattern(canvas, "repeat");};- self.translate = function(sourcePalette, targetPalette) {- var sourceCount = sourcePalette.colors.length;- var targetCount = targetPalette.colors.length;-- var newPalette = {- "id": targetPalette.id,- "name": targetPalette.name || undefined,- "values": sourcePalette.values || undefined- };- var newColors = [];- _.each(sourcePalette.colors, function(color, index) {- var sourcePercent = index / sourceCount;- var targetIndex = Math.floor(sourcePercent * targetCount);- newColors.push(targetPalette.colors[targetIndex]);+ self.translate = function(source, target) {+ var translation = [];+ _.each(source, function(color, index) {+ var sourcePercent = index / source.length;+ var targetIndex = Math.floor(sourcePercent * target.length);+ translation.push(target[targetIndex]);});- newPalette.colors = newColors;- return newPalette;+ return translation;};self.lookup = function(sourcePalette, targetPalette) {diff --git a/web/js/palettes/wv.palettes.legend.js b/web/js/palettes/wv.palettes.legend.jsindex 99f31bbcf..19d657991 100644--- a/web/js/palettes/wv.palettes.legend.js+++ b/web/js/palettes/wv.palettes.legend.js@@ -25,7 +25,6 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {var loaded = false;var self = {};- var $colorbar;var init = function() {var paletteId = layer.palette.id;@@ -55,35 +54,42 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {.addClass("wv-palettes-panel").attr("data-layer", layer.id);$parent.append($legendPanel);- if ( palette.scale ) {- renderScale($legendPanel, palette);- }- if ( palette.classes ) {- renderClasses($legendPanel, palette);- }+ var legends = model.getLegends(layer.id);+ _.each(legends, function(legend, index) {+ if ( legend.type === "scale" ) {+ renderScale($legendPanel, legend, index);+ }+ if ( legend.type === "class" ) {+ renderClasses($legendPanel, legend, index);+ }+ });rendered = true;self.update();};- var renderScale = function($legendPanel, palette) {+ var renderScale = function($legendPanel, legend, index) {+ $container = $("<div></div>")+ .addClass("wv-palettes-legend")+ .attr("data-index", index);$colorbar = $("<canvas></canvas>").addClass("wv-palettes-colorbar")+ .attr("data-index", index).attr("title", "X");- $legendPanel.append($colorbar);+ $container.append($colorbar);var $ranges = $("<div></div>").addClass("wv-palettes-ranges");- var $min = $("<span></span>")+ var $min = $("<div></div>").addClass("wv-palettes-min");- var $max = $("<span></span>")+ var $max = $("<div></div>").addClass("wv-palettes-max");+ var $title = $("<div></div>")+ .addClass("wv-palettes-title");- $ranges.append($min).append($max);- $legendPanel.append($ranges);+ $ranges.append($min).append($max).append($title);+ $container.append($ranges);- $colorbar.on("mousemove", function(event) {- showUnitHover(event);- });+ $colorbar.on("mousemove", showUnitHover);$colorbar.tooltip({position: {my: "left middle",@@ -91,12 +97,16 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {of: $colorbar}});- wv.palettes.colorbar(selector + " .wv-palettes-colorbar");+ $legendPanel.append($container);+ wv.palettes.colorbar(selector + " " ++ "[data-index='" + index + "'] canvas", legend.colors);};- var renderClasses = function($legendPanel, palette) {+ var renderClasses = function($legendPanel, legend, index) {var $panel = $("<div></div>")+ .addClass("wv-palettes-legend").addClass("wv-palettes-classes")+ .attr("data-index", index).attr("title", "X");$legendPanel.append($panel);@@ -108,25 +118,25 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {},content: "X"});- updateClasses(palette);};- var updateClasses = function(palette) {- var $panel = $(selector + " .wv-palettes-classes");+ var updateClasses = function(legend, index) {+ var $panel = $(selector + " [data-index='" + index + "']");$panel.empty();- _.each(palette.classes.colors, function(color, index) {+ _.each(legend.colors, function(color, classIndex) {$panel.append($("<span></span>").attr("data-index", index)+ .attr("data-class-index", classIndex).addClass("wv-palettes-class").html(" ").css("background-color", wv.util.hexToRGB(color)).hover(highlightClass, unhighlightClass));});var $detailPanel = $("<div></div>");- _.each(palette.classes.colors, function(color, index) {+ _.each(legend.colors, function(color, classIndex) {var $row = $("<div></div>").addClass("wv-palettes-class-detail")- .attr("data-index", index);+ .attr("data-class-index", classIndex);$row.append($("<span></span>").addClass("wv-palettes-class")@@ -136,7 +146,8 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {$("<span></span>").addClass("wv-palettes-class-label").attr("data-index", index)- .html(palette.classes.labels[index]));+ .attr("data-class-index", classIndex)+ .html(legend.labels[classIndex]));$detailPanel.append($row);});$panel.tooltip("option", "content", $detailPanel.html());@@ -146,63 +157,67 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {if ( !loaded ) {return;}- var palette = model.get(layer.id);- if ( palette.scale ) {- wv.palettes.colorbar(selector + " .wv-palettes-colorbar",- palette);- showUnitRange();- }- if ( palette.classes ) {- updateClasses(palette);- }+ var legends = model.getLegends(layer.id);+ _.each(legends, function(legend, index) {+ if ( legend.type === "scale" ) {+ wv.palettes.colorbar(selector + " " ++ "[data-index='" + index + "'] canvas", legend.colors);+ showUnitRange(index);+ } else if ( legend.type === "class" ) {+ updateClasses(legend, index);+ }+ });};- var showUnitRange = function() {+ var showUnitRange = function(index) {if ( !loaded ) {return;}- var palette = model.get(layer.id);- var min = palette.scale.labels[0];- var max = palette.scale.labels[palette.scale.labels.length - 1];- $(selector + " .wv-palettes-min").html(min);- $(selector + " .wv-palettes-max").html(max);- $(selector + " .wv-palettes-center").html(" ");+ var legend = model.getLegend(layer.id, index);+ var min = _.first(legend.labels);+ var max = _.last(legend.labels);+ $(selector + " [data-index='" + index + "'] .wv-palettes-min").html(min);+ $(selector + " [data-index='" + index + "'] .wv-palettes-max").html(max);+ var title = legend.title || " ";+ $(selector + " [data-index='" + index + "'] .wv-palettes-title").html(title);};var showUnitHover = function(event) {if ( !loaded ) {return;}- var palette = model.get(layer.id);- var info = palette.scale || palette.classes;- if ( !info ) {- return;- }+ var index = _.parseInt($(this).attr("data-index"));+ var legend = model.getLegend(layer.id, index);+ var $colorbar = $(this);var x = event.pageX - $colorbar.offset().left;var width = $colorbar.width();var percent = x / width;- var bins = info.labels.length;- var index = Math.floor(bins * percent);- if (index >= bins) {- index = bins - 1;+ var bins = legend.colors.length;+ var colorIndex = Math.floor(bins * percent);+ if (colorIndex >= bins) {+ colorIndex = bins - 1;}- var color = info.colors[index];- var label = info.labels[index];+ var color = legend.colors[colorIndex];+ var label = legend.labels[colorIndex];$colorbar.tooltip("option", "content","<span class='wv-palettes-color-box' style='background: " +wv.util.hexToRGBA(color) + "'>" + "</span>" + label);};var highlightClass = function() {- $(".wv-palettes-class-label[data-index='" +- $(this).attr("data-index") + "']")+ legendIndex = $(this).attr("data-index");+ classIndex = $(this).attr("data-class-index");+ $(".wv-palettes-class-label[data-index='" + legendIndex + "']" ++ "[data-class-index='" + classIndex + "']").addClass("wv-palettes-class-highlight");};var unhighlightClass = function() {- $(".wv-palettes-class-label[data-index='" +- $(this).attr("data-index") + "']")+ legendIndex = $(this).attr("data-index");+ classIndex = $(this).attr("data-class-index");+ $(".wv-palettes-class-label[data-index='" + legendIndex + "']" ++ "[data-class-index='" + classIndex + "']").removeClass("wv-palettes-class-highlight");};diff --git a/web/js/palettes/wv.palettes.model.js b/web/js/palettes/wv.palettes.model.jsindex f62065cb7..132ef9333 100644--- a/web/js/palettes/wv.palettes.model.js+++ b/web/js/palettes/wv.palettes.model.js@@ -29,100 +29,125 @@ wv.palettes.model = wv.palettes.model || function(models, config) {self.events = wv.util.events();self.active = {};- self.type = function(layerId) {- var palette = models.palettes.get(layerId);- if ( !palette ) {- return;- }- if ( config.layers[layerId].palette.immutable ) {- return false;- }- if ( palette.scale ) {- return "scale";+ self.getRendered = function(layerId, index) {+ var name = config.layers[layerId].palette.id;+ var palette = config.palettes.rendered[name];+ if ( !_.isUndefined(index) ) {+ palette = palette.maps[index];}- if ( palette.classes && palette.classes.colors.length === 1 ) {- return "single";- }- // FIXME: May not be needed any more- if ( palette.lookup ) {- return ( _.size(palette.lookup) === 1 ) ? "single" : "scale";+ return palette;+ };++ self.getCustom = function(paletteId) {+ palette = config.palettes.custom[paletteId];+ if ( !palette ) {+ throw new Error("Invalid palette: " + paletteId);}+ return palette;+ };++ var prepare = function(layerId) {+ self.active[layerId] = self.active[layerId] || {};+ var active = self.active[layerId];+ active.maps = active.maps || [];+ _.each(self.getRendered(layerId).maps, function(palette, index) {+ if ( !active.maps[index] ) {+ active.maps[index] = _.cloneDeep(palette);+ }+ });};self.allowed = function(layerId) {if ( !wv.palettes.supported ) {return false;}- return self.type(layerId);+ //FIXME: return self.type(layerId);+ return true;};- self.setCustom = function(layerId, paletteId) {- if ( !config.palettes.custom[paletteId] ) {- throw new Error("Invalid palette: " + paletteId);- }+ self.setCustom = function(layerId, paletteId, index) {if ( !config.layers[layerId] ) {throw new Error("Invalid layer: "+ layerId);}+ prepare(layerId);+ index = ( _.isUndefined(index) ) ? 0 : index;var active = self.active[layerId];- if ( active && active.custom === paletteId ) {+ var palette = active.maps[index];+ if ( palette.custom === paletteId ) {return;}- var def = active || {};- def.custom = paletteId;- updateLookup(layerId, def);- self.active[layerId] = def;- self.events.trigger("set-custom", layerId, def);+ palette.custom = paletteId;+ updateLookup(layerId);+ self.events.trigger("set-custom", layerId, active);self.events.trigger("change");};- self.clearCustom = function(layerId) {- var def = self.active[layerId];- if ( def && def.custom ) {- delete def.custom;- if ( !_.isUndefined(def.min) || !_.isUndefined(def.max) ) {- updateLookup(layerId, def);- } else {- delete def.lookup;- }- if ( !def.custom && !def.lookup ) {- delete self.active[layerId];- }- self.events.trigger("clear-custom", layerId);- self.events.trigger("change");+ self.clearCustom = function(layerId, index) {+ index = ( _.isUndefined(index) ) ? 0 : index;+ var active = self.active[layerId];+ if ( !active ) {+ return;+ }+ var palette = active.maps[index];+ if ( !palette.custom ) {+ return;}+ delete palette.custom;+ updateLookup(layerId);+ self.events.trigger("clear-custom", layerId);+ self.events.trigger("change");};- self.setRange = function(layerId, min, max, squash) {- var def = self.active[layerId] || {};- var paletteId = config.layers[layerId].palette.id;- var rendered = config.palettes.rendered[paletteId];- def.min = undefined;- if ( min > 0 ) {- def.min = min;- }- def.max = undefined;- if ( max < rendered.scale.colors.length - 1 ) {- def.max = max;- }- def.squash = squash;- updateLookup(layerId, def);- self.active[layerId] = def;- self.events.trigger("range", layerId, def.min, def.max);+ self.setRange = function(layerId, min, max, squash, index) {+ prepare(layerId);+ index = ( _.isUndefined(index) ) ? 0 : index;+ var palette = self.active[layerId].maps[index];+ palette.min = min;+ palette.max = max;+ palette.squash = squash;+ updateLookup(layerId);+ self.events.trigger("range", layerId, palette.min, palette.max);self.events.trigger("change");};- self.get = function(layerId) {- var layer = config.layers[layerId];- if ( self.active[layer.id] && self.active[layer.id].lookup ) {- return self.active[layer.id];- } else if ( layer.palette ) {- return config.palettes.rendered[layer.palette.id];+ self.getCount = function(layerId) {+ return self.getRendered(layerId).maps.length;+ };++ self.get = function(layerId, index) {+ index = ( _.isUndefined(index) ) ? 0 : index;+ if ( self.active[layerId] ) {+ return self.active[layerId].maps[index];+ }+ return self.getRendered(layerId, index);+ };++ self.getLegend = function(layerId, index) {+ var value = self.get(layerId, index);+ return value.legend || value.entries;+ };++ self.getDefaultLegend = function(layerId, index) {+ var palette = self.getRendered(layerId, index);+ return palette.legend || palette.entries;+ };++ self.getLegends = function(layerId) {+ var legends = [];+ var count = self.getCount(layerId);+ for ( var i = 0; i < count; i++ ) {+ legends.push(self.getLegend(layerId, i));}+ return legends;};+ // Is a canvas required?self.isActive = function(layerId) {- var info = self.active[layerId];- return info && info.lookup;+ return self.active[layerId];+ };++ self.getLookup = function(layerId) {+ return self.active[layerId].lookup;};self.clear = function() {@@ -136,6 +161,7 @@ wv.palettes.model = wv.palettes.model || function(models, config) {};self.save = function(state) {+ /*if ( self.inUse() && !state.l ) {throw new Error("No layers in state");}@@ -159,6 +185,7 @@ wv.palettes.model = wv.palettes.model || function(models, config) {attr.push({ id: "squash" });}});+ */};self.key = function(layerId) {@@ -257,129 +284,78 @@ wv.palettes.model = wv.palettes.model || function(models, config) {return found;};- var useLookup = function(layerId, def) {- var rendered = config.palettes.rendered[layerId];- if ( def.custom ) {- return true;- }- if ( rendered.scale ) {- var bins = rendered.scale.colors.length;- if ( def.min > 0 || def.max < bins - 1 ) {- return true;+ var useLookup = function(layerId) {+ var use = false;+ var active = self.active[layerId].maps;+ _.each(active, function(palette, index) {+ if ( palette.custom ) {+ use = true;+ return false;}- }+ var rendered = self.getRendered(layerId, index);+ if ( palette.min < _.first(_.last(rendered.values)) ) {+ delete palette.min;+ }+ if ( palette.min > _.last(_.first(rendered.values)) ) {+ delete palette.max;+ }+ if ( !_.isUndefined(palette.min) || !_.isUndefined(palette.max) ) {+ use = true;+ return false;+ }+ });+ return use;};- var updateLookup = function(layerId, def) {- if ( !useLookup(layerId, def) ) {- def.lookup = null;- return;- }- if ( models.palettes.type(layerId) === "single" ) {- updateLookupSingle(layerId, def);+ var updateLookup = function(layerId) {+ if ( !useLookup(layerId) ) {+ delete self.active[layerId];return;}- var layerDef = config.layers[layerId];- var source = config.palettes.rendered[layerDef.palette.id];- var target;- if ( def.custom ) {- target = config.palettes.custom[def.custom];- } else {- target = source.scale;- }-- var min = def.min || 0;- var max = def.max || source.scale.colors.length - 1;-- var sourceCount = source.scale.colors.length;- var targetCount = target.colors.length;- var indexCount = max - min;-- var scale = {- "id": target.id,- "name": target.name || undefined- };+ var active = self.active[layerId].maps;+ var lookup = {};+ _.each(active, function(palette, index) {+ entries = palette.entries;+ legend = {+ colors: [],+ labels: entries.labels,+ values: entries.values,+ type: entries.type,+ title: entries.title+ };+ var source = entries.colors;+ var values = entries.values;+ var target = ( palette.custom ) ?+ self.getCustom(palette.custom).colors : source;+ var min = palette.min || 0;+ var max = palette.max || source.length;- var newScale = [];- var newLabels = [];- var newValues = [];- _.each(source.scale.colors, function(color, index) {- if ( index < def.min || index > def.max ) {- newScale.push("00000000");- } else {- var sourcePercent, targetIndex;- if ( def.squash ) {- sourcePercent = (index - min) / (max - min);- if ( index == max ) {- sourcePercent = 1.0;- }- targetIndex = Math.floor(sourcePercent * targetCount);- if ( targetIndex >= targetCount ) {- targetIndex = targetCount - 1;- }+ _.each(source, function(color, index) {+ var newColor;+ if ( index < min || index > max ) {+ targetColor = "00000000";} else {- sourcePercent = index / sourceCount;- targetIndex = Math.floor(sourcePercent * targetCount);+ var sourcePercent = index / source.length;+ var targetIndex = Math.floor(sourcePercent * target.length);+ targetColor = target[targetIndex];}- newScale.push(target.colors[targetIndex]);- }- newLabels.push(source.scale.labels[index]);- newValues.push(source.scale.values[index]);- });- scale.colors = newScale;- scale.labels = newLabels;- scale.values = newValues;- def.scale = scale;-- var lookup = {};- _.each(source.scale.colors, function(sourceColor, index) {- var sourceEntry =- parseInt(sourceColor.substring(0, 2), 16) + "," +- parseInt(sourceColor.substring(2, 4), 16) + "," +- parseInt(sourceColor.substring(4, 6), 16) + "," +- parseInt(sourceColor.substring(6, 8), 16);- var targetColor = newScale[index];- var targetEntry = {- r: parseInt(targetColor.substring(0, 2), 16),- g: parseInt(targetColor.substring(2, 4), 16),- b: parseInt(targetColor.substring(4, 6), 16),- a: parseInt(targetColor.substring(6, 8), 16)- };- lookup[sourceEntry] = targetEntry;+ legend.colors.push(targetColor);+ var lookupSource =+ _.parseInt(color.substring(0, 2), 16) + "," ++ _.parseInt(color.substring(2, 4), 16) + "," ++ _.parseInt(color.substring(4, 6), 16) + "," ++ _.parseInt(color.substring(6, 8), 16);+ var lookupTarget = {+ r: _.parseInt(targetColor.substring(0, 2), 16),+ g: _.parseInt(targetColor.substring(2, 4), 16),+ b: _.parseInt(targetColor.substring(4, 6), 16),+ a: _.parseInt(targetColor.substring(6, 8), 16)+ };+ lookup[lookupSource] = lookupTarget;+ });+ palette.legend = legend;});- def.lookup = lookup;- };-- var updateLookupSingle = function(layerId, def) {- var layerDef = config.layers[layerId];- var source = config.palettes.rendered[layerDef.palette.id];- var target;- if ( def.custom ) {- target = config.palettes.custom[def.custom].colors;- } else {- target = source.colors;- }- var lookup = {};- var sourceColor = source.classes.colors[0];- var targetColor = target[0];-- var sourceEntry =- parseInt(sourceColor.substring(0, 2), 16) + "," +- parseInt(sourceColor.substring(2, 4), 16) + "," +- parseInt(sourceColor.substring(4, 6), 16) + "," +- parseInt(sourceColor.substring(6, 8), 16);- var targetEntry = {- r: parseInt(targetColor.substring(0, 2), 16),- g: parseInt(targetColor.substring(2, 4), 16),- b: parseInt(targetColor.substring(4, 6), 16),- a: parseInt(targetColor.substring(6, 8), 16)- };- def.classes = {- colors: [targetColor],- labels: [source.classes.labels[0]]- };- lookup[sourceEntry] = targetEntry;- def.lookup = lookup;+ self.active[layerId].lookup = lookup;};return self;