Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-535: Palette code is back in

Mike McGann9d1a803124bb
diff --git a/src/css/bank.css b/src/css/bank.css
index ba9d87d56..588e49340 100644
--- a/src/css/bank.css
+++ b/src/css/bank.css
@@ -51,9 +51,24 @@ background: rgba(238,238,238,0.85); cursor:move;
.bank ul.category { overflow:auto; }
.bank ul.category li h3 {display:block; clear:both; float:none;}
img.bank-item-img { display:block; height: 14px; width:auto;}
-span.p-min {float:left; font-size:0.8em;}
-span.p-max {float:left; font-size: 0.8em;}
-span.p-units {float:left; font-size:0.8em;}
-
+span.p-min {
+ float: left;
+ font-size:0.8em;
+ margin-right: 10px;
+}
+span.p-max {
+ float: left;
+ font-size: 0.8em;
+ margin-left: 10px;
+}
+span.p-units {
+ float: left;
+ font-size: 0.8em;
+ margin-left: 3px;
+}
+.colorBar {
+ width: 100px;
+ height: 14px;
+}
.ui-tabs-hide {/*display:none !important;*/ position:absolute !important; left:-999em !important;}
diff --git a/src/js/Worldview/Palette/Palette.js b/src/js/Worldview/Palette/Palette.js
index ed3decd5d..d407dc582 100644
--- a/src/js/Worldview/Palette/Palette.js
+++ b/src/js/Worldview/Palette/Palette.js
@@ -108,5 +108,5 @@ Worldview.Palette.Palette = function(spec) {
stops: spec.stops || [],
};
-}
+};
diff --git a/src/js/Worldview/Widget/DataDownload.js b/src/js/Worldview/Widget/DataDownload.js
index dd7b99e4e..d649a1c41 100644
--- a/src/js/Worldview/Widget/DataDownload.js
+++ b/src/js/Worldview/Widget/DataDownload.js
@@ -93,6 +93,7 @@ Worldview.Widget.DataDownload = function(config, spec) {
$(spec.selector).height($(spec.selector).parent().outerHeight() - tabs_height);
list = new SOTE.widget.List(self.containerId, {
+ config: config,
data: [],
selected: "~",
close: false,
diff --git a/src/js/Worldview/Widget/Palette.js b/src/js/Worldview/Widget/Palette.js
index 99ef2d0c6..314a45e6d 100644
--- a/src/js/Worldview/Widget/Palette.js
+++ b/src/js/Worldview/Widget/Palette.js
@@ -89,7 +89,7 @@ Worldview.Widget.Palette = function(containerId, config, spec) {
try {
var state = REGISTRY.getState(queryString);
log.debug("Palette: updateComponent", state);
- $.each(self.active, function(product, palette) {
+ $.each(self.active, function(layer, palette) {
if ( $.inArray(layer, state.layers) < 0 ) {
log.debug("Removing palette for " + layer);
delete self.active[layer];
@@ -291,4 +291,4 @@ Worldview.Widget.Palette = function(containerId, config, spec) {
init();
return self;
-}
+};
diff --git a/src/js/bank.js b/src/js/bank.js
index ca392093b..c40a1cffe 100644
--- a/src/js/bank.js
+++ b/src/js/bank.js
@@ -19,7 +19,7 @@ SOTE.widget.Bank.prototype = new SOTE.widget.Component;
* @augments SOTE.widget.Component
*
*/
-SOTE.widget.Bank = function(containerId, config){
+SOTE.widget.Bank = function(containerId, spec){
this.log = Logging.getLogger("Worldview.Widget.Bank");
this.VALID_PROJECTIONS = ["geographic", "arctic", "antarctic"];
this.hidden = {};
@@ -35,43 +35,43 @@ SOTE.widget.Bank = function(containerId, config){
this.containerId=containerId;
//Define an object for holding configuration
- if (config===undefined){
- config={};
+ if (spec===undefined){
+ spec={};
}
- if(config.title === undefined){
- config.title = "My Bank";
+ if(spec.title === undefined){
+ spec.title = "My Bank";
}
- if(config.categories === undefined){
- config.categories = ["Category 1","Category 2"];
+ if(spec.categories === undefined){
+ spec.categories = ["Category 1","Category 2"];
}
- if(config.callback === undefined){
- config.callback = null;
+ if(spec.callback === undefined){
+ spec.callback = null;
}
- if(config.state === undefined || config.state === ""){
- config.state = "geographic";
+ if(spec.state === undefined || spec.state === ""){
+ spec.state = "geographic";
}
- this.state = config.state;
- this.selected = config.selected;
+ this.state = spec.state;
+ this.selected = spec.selected;
- this.dataSourceUrl = config.dataSourceUrl;
+ this.dataSourceUrl = spec.dataSourceUrl;
- this.title = config.title;
- this.callback = config.callback;
- this.selector = config.selector;
+ this.title = spec.title;
+ this.callback = spec.callback;
+ this.selector = spec.selector;
this.data = new Object;
this.buildMetaDone = false;
- this.categories = config.categories;
+ this.categories = spec.categories;
this.initRenderComplete = false;
- this.dataSourceUrl = config.dataSourceUrl;
+ this.dataSourceUrl = spec.dataSourceUrl;
this.statusStr = "";
- this.config = config.config;
- this.paletteWidget = config.paletteWidget;
+ this.config = spec.config;
+ this.paletteWidget = spec.paletteWidget;
this.queryString = "";
this.noFireVal = null;
this.init();
@@ -180,6 +180,7 @@ SOTE.widget.Bank.prototype.render = function(){
$('#'+this.id).height($('#'+this.id).parent().outerHeight() - tabs_height);
this.list = new SOTE.widget.List(this.id,{
+ config: this.config,
data: this.data,
selected: this.selected[this.state],
hide: true,
@@ -188,7 +189,8 @@ SOTE.widget.Bank.prototype.render = function(){
search: false,
sortable: true,
onchange: SOTE.widget.Bank.handleFire,
- args: this
+ args: this,
+ paletteWidget: this.paletteWidget
});
//$("#"+this.id).bind("listchange", {self:this}, SOTE.widget.Bank.handleFire);
diff --git a/src/js/list.js b/src/js/list.js
index c3020a233..ff3839a9a 100644
--- a/src/js/list.js
+++ b/src/js/list.js
@@ -19,7 +19,7 @@ SOTE.widget.List.prototype = new SOTE.widget.Component;
* @augments SOTE.widget.Component
*
*/
-SOTE.widget.List = function(containerId, config){
+SOTE.widget.List = function(containerId, spec){
this.log = Logging.getLogger("Worldview.Widget.List");
//Get the ID of the container element
@@ -33,60 +33,61 @@ SOTE.widget.List = function(containerId, config){
this.containerId=containerId;
//Define an object for holding configuration
- if (config===undefined){
- config={};
+ if (spec===undefined){
+ spec={};
}
- if(config.title === undefined){
- config.title = "My List";
+ if(spec.title === undefined){
+ spec.title = "My List";
}
- if(config.data === undefined){
+ if(spec.data === undefined){
SOTE.util.throwError("List data is not defined.");
}
- if(config.search == undefined){
- config.search = false;
- config.selectedCategory = 'All';
+ if(spec.search == undefined){
+ spec.search = false;
+ spec.selectedCategory = 'All';
}
- if(config.search && config.category == undefined){
- config.selectedCategory = 'All';
+ if(spec.search && spec.category == undefined){
+ spec.selectedCategory = 'All';
}
- if(config.filter == undefined){
- config.filter = false;
+ if(spec.filter == undefined){
+ spec.filter = false;
}
- if(config.customClasses == undefined){
- config.customClasses = '';
+ if(spec.customClasses == undefined){
+ spec.customClasses = '';
}
- if(config.sortable == undefined){
- config.sortable = false;
+ if(spec.sortable == undefined){
+ spec.sortable = false;
}
- this.customClasses = config.customClasses;
+ this.customClasses = spec.customClasses;
this.hidden = new Object;
this.values = new Object;
this.keyword = '';
- this.search = config.search;
- this.filter = config.filter;
- this.hide = config.hide;
- this.close = config.close;
- this.checkbox = config.checkbox;
- this.selectedCategory = config.defaultCategory;
- this.selectableCategories = config.selectableCategories;
- this.action = config.action;
- this.categories = config.categories;
- this.sortable = config.sortable;
- this.callback = config.onchange;
- this.args = config.args;
-
- this.data = config.data;
+ this.search = spec.search;
+ this.filter = spec.filter;
+ this.hide = spec.hide;
+ this.close = spec.close;
+ this.checkbox = spec.checkbox;
+ this.selectedCategory = spec.defaultCategory;
+ this.selectableCategories = spec.selectableCategories;
+ this.action = spec.action;
+ this.categories = spec.categories;
+ this.sortable = spec.sortable;
+ this.callback = spec.onchange;
+ this.args = spec.args;
+ this.config = spec.config;
+ this.data = spec.data;
+ this.paletteWidget = spec.paletteWidget;
- this.selected = this.unserialize(config.selected);
+ this.selected = this.unserialize(spec.selected);
this.selected = this.selected[1];
this.init();
@@ -173,8 +174,26 @@ SOTE.widget.List.prototype.render = function(){
};
-SOTE.widget.List.prototype.update = function(){
+SOTE.widget.List.prototype.update = function() {
+ try {
+ this._update();
+ } catch ( error ) {
+ Worldview.error("Internal error", error);
+ }
+};
+
+SOTE.widget.List.prototype._update = function(){
+ var openPaletteSelector = function(name) {
+ return function() {
+ if ( !Worldview.Support.allowCustomPalettes() ) {
+ Worldview.Support.showUnsupportedMessage();
+ } else {
+ self.paletteWidget.displaySelector(name);
+ }
+ };
+ };
+
$content = $("#" + this.id + "content").empty();
// If search is enabled and a keyword exists, break keyword down into words array
@@ -213,6 +232,7 @@ SOTE.widget.List.prototype.update = function(){
var item = this.data[key].items[i];
var label = item.label;
+ var itemKey = item.value.replace(/:/g,"colon");
var fLabel = item.label.replace(" ","-").toLowerCase();
if(item.value in this.selected){
@@ -248,7 +268,7 @@ SOTE.widget.List.prototype.update = function(){
if(!this.search || (keywords && count == keywords.length)){
- $item = $("<li id='"+key+"-"+item.value+"' class='item'></li>");
+ $item = $("<li id='"+ this.id + key + itemKey + "' class='item'></li>");
if(this.close){
$item.append("<a><img class='close bank-item-img' id='close"+key+"-"+item.value.replace(/:/g,"colon")+"' title='Remove Layer' src='images/close-red-x.png' /></a>");
@@ -269,8 +289,27 @@ SOTE.widget.List.prototype.update = function(){
}
$item.append("<h4>"+label+"</h4>");
$item.append("<p>"+item.sublabel+"</p>");
-
- $category.append($item);
+
+ var paletteInfo = this.getPaletteInfo(item.value);
+ if ( paletteInfo ) {
+ if ( paletteInfo ) {
+ var units = "";
+ if ( paletteInfo.units ) {
+ units = "<span class='units'>(" + paletteInfo.units+")</span>";
+ }
+ $item.append(
+ "<div>" +
+ "<span class='palette'>" +
+ "<span class='p-min'>" + paletteInfo.min + "</span>" +
+ "<canvas class='colorBar' id='canvas_" + this.id + itemKey + "'></canvas>" +
+ "<span class='p-max'>" + paletteInfo.max + "</span>" +
+ units +
+ "</span>" +
+ "</div>"
+ );
+ }
+ }
+ $category.append($item);
}
}
}
@@ -278,6 +317,26 @@ SOTE.widget.List.prototype.update = function(){
// Append the category (heading + items) to the content div
$content.append($category);
+
+ for(var i=0; i<this.data[key].items.length; ++i){
+ var item = this.data[key].items[i];
+ var label = item.label;
+ var itemKey = item.value.replace(/:/g,"colon");
+ if((!this.filter || item.value in this.selected) && (!this.search || (keywords && count == keywords.length))){
+ var paletteInfo = this.getPaletteInfo(item.value);
+ if ( paletteInfo ) {
+ Worldview.Palette.ColorBar({
+ selector: "#canvas_" + this.id + itemKey,
+ bins: paletteInfo.bins,
+ stops: paletteInfo.stops,
+ palette: paletteInfo.palette
+ });
+ $("#canvas_" + this.id + itemKey)
+ .click(openPaletteSelector(item.value))
+ .css("cursor", "pointer");
+ }
+ }
+ }
}
// Append show/hide/checkbox events if this.hide = true / this.close = true / this.checkbox = true
@@ -308,6 +367,31 @@ SOTE.widget.List.prototype.update = function(){
setTimeout(SOTE.widget.List.adjustCategoryHeights,1,{self:this});
};
+SOTE.widget.List.prototype.getPaletteInfo = function(layerName) {
+ // Exit now if showing palettes is not desired
+ if ( !this.paletteWidget ) {
+ return;
+ }
+ var layerConfig = this.config.layers[layerName];
+ var renderedPalette = layerConfig.rendered;
+ // Exit now if layer does not have a palette
+ if ( !renderedPalette ) {
+ return;
+ }
+ return {
+ units: layerConfig.units,
+ min: ( layerConfig.min === undefined )
+ ? "&nbsp;&nbsp;&nbsp;&nbsp"
+ : layerConfig.min,
+ max: ( layerConfig.max === undefined )
+ ? "&nbsp;&nbsp;&nbsp;&nbsp"
+ : layerConfig.max,
+ bins: layerConfig.bins,
+ stops: layerConfig.stops,
+ palette: this.paletteWidget.getPalette(layerName)
+ };
+};
+
SOTE.widget.List.prototype.setButtonEnabled = function(enabled) {
if ( enabled ) {
$("#" + this.id + "action").removeAttr("disabled");
diff --git a/src/js/main.js b/src/js/main.js
index 392d06ac2..a6a940c0f 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -170,7 +170,8 @@ $(function() {// Initialize "static" vars
var dataDownload = Worldview.Widget.DataDownload(config, {
selector: "#DataDownload",
model: dataDownloadModel,
- maps: map.maps
+ maps: map.maps,
+ paletteWidget: palettes
});
dataDownload.render();
diff --git a/src/js/products.js b/src/js/products.js
index 734ca8d5f..1dbca51a6 100644
--- a/src/js/products.js
+++ b/src/js/products.js
@@ -19,7 +19,7 @@ SOTE.widget.Products.prototype = new SOTE.widget.Component;
* @augments SOTE.widget.Component
*
*/
-SOTE.widget.Products = function(containerId, config){
+SOTE.widget.Products = function(containerId, spec){
this.log = Logging.getLogger("Worldview.Widget.Products");
//this.VALID_PROJECTIONS = ["geographic", "arctic", "antarctic"];
@@ -34,35 +34,35 @@ SOTE.widget.Products = function(containerId, config){
this.containerId=containerId;
//Define an object for holding configuration
- if (config===undefined){
- config={};
+ if (spec===undefined){
+ spec={};
}
- if(config.title === undefined){
- config.title = "My Products";
+ if(spec.title === undefined){
+ spec.title = "My Products";
}
- if(config.categories === undefined){
- config.categories = ["Category 1","Category 2"];
+ if(spec.categories === undefined){
+ spec.categories = ["Category 1","Category 2"];
}
- if(config.callback === undefined){
- config.callback = null;
+ if(spec.callback === undefined){
+ spec.callback = null;
}
- if(config.state === undefined || config.state === ""){
- config.state = "geographic";
+ if(spec.state === undefined || spec.state === ""){
+ spec.state = "geographic";
}
- this.state = config.state;
- this.selected = config.selected;
+ this.state = spec.state;
+ this.selected = spec.selected;
this.isCollapsed = false;
- this.dataSourceUrl = config.dataSourceUrl;
- this.categories = config.categories;
+ this.dataSourceUrl = spec.dataSourceUrl;
+ this.categories = spec.categories;
this.initRenderComplete = false;
- this.paletteWidget = config.paletteWidget;
- this.config = config.config;
+ this.paletteWidget = spec.paletteWidget;
+ this.config = spec.config;
this.events = Worldview.Events();
this.init();
@@ -171,7 +171,6 @@ SOTE.widget.Products.prototype.render = function(){
SOTE.widget.Products.change(e, ui);
}});
this.b = new SOTE.widget.Bank("products", {
- paletteWidget: this.paletteWidget,
dataSourceUrl: "ap_products.php",
title: "My Layers",
selected: {
@@ -180,7 +179,8 @@ SOTE.widget.Products.prototype.render = function(){
geographic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,sedac_bound"
},
categories:["Base Layers","Overlays"],
- config: this.config
+ config: this.config,
+ paletteWidget: this.paletteWidget
});
this.s = new SOTE.widget.Selector("selectorbox", {
dataSourceUrl: "ap_products.php",
@@ -192,18 +192,6 @@ SOTE.widget.Products.prototype.render = function(){
},
config: this.config
});
- /* FIXME: Remove
- this.d = new SOTE.widget.Download("ddownload", {
- dataSourceUrl: "ap_products.php",
- categories: ["Base Layers","Overlays"],
- selected: {
- antarctic: "baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,antarctic_coastlines",
- arctic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,arctic_coastlines",
- geographic:"baselayers,!MODIS_Aqua_CorrectedReflectance_TrueColor,MODIS_Terra_CorrectedReflectance_TrueColor~overlays,sedac_bound"
- },
- config: this.config
- });
- */
//$('#'+this.id+"prods").on("tabsshow",SOTE.widget.Products.change);
$('.accordionToggler').bind('click',{self:this},SOTE.widget.Products.toggle);
diff --git a/src/js/selector.js b/src/js/selector.js
index 767f047ef..a30fb47e2 100644
--- a/src/js/selector.js
+++ b/src/js/selector.js
@@ -19,7 +19,7 @@ SOTE.widget.Selector.prototype = new SOTE.widget.Component;
* @augments SOTE.widget.Component
*
*/
-SOTE.widget.Selector = function(containerId, config){
+SOTE.widget.Selector = function(containerId, spec){
//Get the ID of the container element
this.container=document.getElementById(containerId);
if (this.container==null){
@@ -31,30 +31,31 @@ SOTE.widget.Selector = function(containerId, config){
this.containerId=containerId;
//Define an object for holding configuration
- if (config===undefined){
- config={};
+ if (spec===undefined){
+ spec={};
}
- if(config.categories === undefined){
- config.categories = ["Category 1","Category 2"];
+ if(spec.categories === undefined){
+ spec.categories = ["Category 1","Category 2"];
}
- if(config.state === undefined){
- config.state = "geographic";
+ if(spec.state === undefined){
+ spec.state = "geographic";
}
- this.state = config.state;
+ this.state = spec.state;
- this.selected = config.selected;
+ this.selected = spec.selected;
//this.values = this.unserialize(this.selected[this.state]);
this.meta = new Object;
this.data = new Object;
- this.categories = config.categories;
+ this.categories = spec.categories;
this.cats = new Object;
this.initRenderComplete = false;
- this.dataSourceUrl = config.dataSourceUrl;
- this.config = config.config;
+ this.dataSourceUrl = spec.dataSourceUrl;
+ this.config = spec.config;
+ this.paletteWidget = spec.paletteWidget;
this.statusStr = "";
this.init();
//this.updateComponent(this.id+"=baselayers.MODIS_Terra_CorrectedReflectance_TrueColor-overlays.fires48.AIRS_Dust_Score.OMI_Aerosol_Index")
@@ -153,7 +154,9 @@ SOTE.widget.Selector.prototype.render = function(){
defaultCategory: "All",
categories: this.cats,
onchange: SOTE.widget.Selector.handleFire,
- args: this
+ args: this,
+ paletteWidget: this.paletteWidget,
+ config: this.config
});
//$("#"+this.id).bind("listchange", {self:this}, SOTE.widget.Selector.handleFire);