Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

correct legend parsing for dual legends

Taylor Gunnoe768283a7bf6c
diff --git a/bin/wv-options-colormap b/bin/wv-options-colormap
index 476e14103..70672f228 100755
--- a/bin/wv-options-colormap
+++ b/bin/wv-options-colormap
@@ -69,7 +69,8 @@ def process_entries(entries):
if a == 0:
continue
colors += [color_format.format(int(r), int(g), int(b), a)]
- labels += [entry["@label"]]
+ if "@label" in entry:
+ labels += [entry["@label"]]
if map_type == "scale":
items = re.sub(r"[\(\)\[\]]", "", entry["@value"]).split(",")
try:
@@ -116,11 +117,18 @@ def process_file(file):
result["entries"] = entries
if "@title" in colormap:
result["entries"]["title"] = colormap["@title"]
- if "WorldviewLegend" in colormap:
- legend = process_entries(colormap["WorldviewLegend"]["LegendEntry"])
+ if "Legend" in colormap:
+
+ legend = process_entries(colormap["Legend"]["LegendEntry"])
result["legend"] = legend
+ result["legend"]["type"] = colormap["Legend"]["@type"]
+ result["entries"]["type"] = result["legend"]["type"]
if "@title" in colormap:
result["legend"]["title"] = colormap["@title"]
+ if "@minLabel" in colormap["Legend"]:
+ result["legend"]["minLabel"] = colormap["Legend"]["@minLabel"]
+ if "@maxLabel" in colormap["Legend"]:
+ result["legend"]["maxLabel"] = colormap["Legend"]["@maxLabel"]
maps += [result]
data = {
diff --git a/web/css/wv.palettes.css b/web/css/wv.palettes.css
index 88bc95264..a4102d51d 100644
--- a/web/css/wv.palettes.css
+++ b/web/css/wv.palettes.css
@@ -62,7 +62,6 @@
.wv-palettes-min, .wv-palettes-title, .wv-palettes-max{
font-size:0.7em;
white-space:nowrap;
- max-width: 112px;
overflow: hidden;
display: inline-block;
text-overflow: ellipsis;
@@ -76,14 +75,12 @@
text-align: center;
}
.bank div.wv-palettes-min {
- position: absolute;
- left: 0;
- width: auto;
+ max-width: 112px;
}
.bank div.wv-palettes-max {
- position: absolute;
- right: 0;
- width: auto;
+ float:right;
+ text-align:right;
+ max-width: 112px;
}
/* FIXME: Too specific */
diff --git a/web/js/layers/wv.layers.options.js b/web/js/layers/wv.layers.options.js
index 95e37cb1b..c61d3afd2 100644
--- a/web/js/layers/wv.layers.options.js
+++ b/web/js/layers/wv.layers.options.js
@@ -48,7 +48,7 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
renderLegendButtons($dialog);
}
var legend = models.palettes.getLegend(layer.id, index);
- if ( legend.type === "scale" ) {
+ if ( legend.type === "continuous" ) {
renderRange($dialog);
}
renderPaletteSelector($dialog);
@@ -150,7 +150,9 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
var $panel = $("<div></div>")
.addClass("wv-legend-buttons");
var legends = models.palettes.getLegends(layer.id);
+
_.each(legends, function(legend, index) {
+
id = "wv-legend-" + index;
$panel.append("<input type='radio' id='" + id + "' " +
"name='legend' value='" + index + "'>" +
@@ -167,11 +169,11 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
};
var renderRange = function() {
+ console.log('range');
var $header = $("<div></div>")
.html("Thresholds")
.addClass("wv-header");
-
var $squash = $("<div></div>")
.addClass("wv-palette-squash");
var $squashButton = $("<input></input>")
@@ -192,8 +194,8 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
};
var rerenderRange = function() {
- var legend = models.palettes.getLegend(layer.id, index);
- var max = legend.values.length - 1;
+ var legend = models.palettes.get(layer.id, index);
+ var max = legend.entries.values.length - 1;
var startMin = legend.min || 0;
var startMax = legend.max || max;
@@ -274,6 +276,7 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
var renderPaletteSelector = function($dialog) {
var $header = $("<div></div>")
.addClass("wv-header")
+ .addClass("wv-color-palette-label")
.html("Color Palette");
var $pane = $("<div></div>")
.attr("id", "wv-palette-selector");
@@ -282,11 +285,7 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
};
var rerenderPaletteSelector = function(firstTime) {
- var $header = $("<div></div>")
- .addClass("wv-header")
- .addClass("wv-color-palette-label")
- .html("Color Palette");
-
+ console.log(layer);
var $pane = $("#wv-palette-selector").empty();
$pane.append(defaultLegend());
var recommended = layer.palette.recommended || [];
@@ -304,7 +303,6 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
}
}
});
- $dialog.append($header);
$dialog.append($pane);
$pane.perfectScrollbar();
@@ -405,7 +403,7 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
var defaultLegend = function() {
var legend = models.palettes.getDefaultLegend(layer.id, index);
- if ( legend.type === "scale" ) {
+ if ( legend.type === "continuous" ) {
return selectorItemScale(legend.colors, "__default", "Default");
} else {
return selectorItemSingle(legend, "__default", "Default");
@@ -415,14 +413,14 @@ wv.layers.options = wv.layers.options || function(config, models, layer) {
var customLegend = function(id) {
var source = models.palettes.getDefaultLegend(layer.id, index);
var target = models.palettes.getCustom(id);
- var targetType = ( target.colors.length === 1 ) ? "single": "scale";
+ var targetType = ( target.colors.length === 1 ) ? "single": "continuous";
- if ( source.type === "scale" && targetType === "scale" ) {
+ if ( source.type === "continuous" && targetType === "continuous" ) {
var translated = wv.palettes.translate(source.colors,
target.colors);
return selectorItemScale(translated, id, target.name);
}
- if ( source.type === "single" && targetType === "single" ) {
+ if ( source.type === "continuous" && targetType === "continuous" ) {
return selectorItemSingle(target, id, target.name);
}
};
diff --git a/web/js/palettes/wv.palettes.legend.js b/web/js/palettes/wv.palettes.legend.js
index 42ca2f216..7a84c704f 100644
--- a/web/js/palettes/wv.palettes.legend.js
+++ b/web/js/palettes/wv.palettes.legend.js
@@ -56,10 +56,10 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
$parent.append($legendPanel);
var legends = model.getLegends(layer.id);
_.each(legends, function(legend, index) {
- if ( legend.type === "scale" ) {
+ if ( legend.type === "continuous" ) {
renderScale($legendPanel, legend, index);
}
- if ( legend.type === "class" ) {
+ if ( legend.type === "classification" ) {
renderClasses($legendPanel, legend, index);
}
});
@@ -86,8 +86,8 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
var $title = $("<div></div>")
.addClass("wv-palettes-title");
-
- $ranges.append($min).append($max).append($title);
+ $container.prepend($title);
+ $ranges.append($max).append($min);
$container.append($ranges);
$colorbar.on("mousemove", showUnitHover);
@@ -160,11 +160,11 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
}
var legends = model.getLegends(layer.id);
_.each(legends, function(legend, index) {
- if ( legend.type === "scale" ) {
+ if ( legend.type === "continuous" ) {
wv.palettes.colorbar(selector + " " +
"[data-index='" + index + "'] canvas", legend.colors);
showUnitRange(index);
- } else if ( legend.type === "class" ) {
+ } else if ( legend.type === "classification" ) {
updateClasses(legend, index);
}
});
@@ -174,13 +174,23 @@ wv.palettes.legend = wv.palettes.legend || function(spec) {
if ( !loaded ) {
return;
}
- 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 || "&nbsp;";
- $(selector + " [data-index='" + index + "'] .wv-palettes-title").html(title);
+ var legends = model.getLegends(layer.id, index);
+ var entries = model.get(layer.id, index).entries;
+ _.each(legends, function(legend, index) {
+ console.log(legend);
+ var min = _.first(legend.labels) || _.first(entries.labels);
+ var max = _.last(legend.labels) || _.last(entries.labels);
+ $(selector + " [data-index='" + index + "'] .wv-palettes-min").html(min);
+ $(selector + " [data-index='" + index + "'] .wv-palettes-max").html(max);
+ var title = legend.title || "&nbsp;";
+
+ if (legends.length === 1 ){
+ $(selector + " [data-index='" + index + "'] .wv-palettes-title").hide();
+ }
+ else{
+ $(selector + " [data-index='" + index + "'] .wv-palettes-title").html(title);
+ }
+ });
};
var showUnitHover = function(event) {
diff --git a/web/js/palettes/wv.palettes.model.js b/web/js/palettes/wv.palettes.model.js
index 411565373..0d47dbc47 100644
--- a/web/js/palettes/wv.palettes.model.js
+++ b/web/js/palettes/wv.palettes.model.js
@@ -53,6 +53,8 @@ wv.palettes.model = wv.palettes.model || function(models, config) {
_.each(self.getRendered(layerId).maps, function(palette, index) {
if ( !active.maps[index] ) {
active.maps[index] = _.cloneDeep(palette);
+ //console.log(palette);
+ //console.log(active.maps[index]);
}
});
};
@@ -400,11 +402,13 @@ wv.palettes.model = wv.palettes.model || function(models, config) {
use = true;
return false;
}
+ //FIXME: palette.min and rendered.values point to inexisting objs
var rendered = self.getRendered(layerId, index);
- if ( palette.min < _.first(_.last(rendered.values)) ) {
+
+ if ( palette.min < _.first(_.last(rendered.entries.values)) ) {
delete palette.min;
}
- if ( palette.min > _.last(_.first(rendered.values)) ) {
+ if ( palette.min > _.last(_.first(rendered.entries.values)) ) {
delete palette.max;
}
if ( !_.isUndefined(palette.min) || !_.isUndefined(palette.max) ) {