Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Bank and switch now check for valid values and default or ignore when necessary

Mike McGannba4486cfef36
diff --git a/data/map b/data/map
index 4e087cced..6f9779f98 100644
--- a/data/map
+++ b/data/map
@@ -1,6 +1,8 @@
{
-"projections": {
+"defaultProjection": "geographic",
+
+"projections": {
"geographic": {
"name": "geographic",
"projection": "EPSG:4326",
diff --git a/js/Worldview/Map/ProductMap.js b/js/Worldview/Map/ProductMap.js
index 2b8b72ba4..f642b6b9c 100644
--- a/js/Worldview/Map/ProductMap.js
+++ b/js/Worldview/Map/ProductMap.js
@@ -49,6 +49,12 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
// Public
//-------------------------------------------------------------------------
+ /**
+ * Property: mapConfig
+ * The <Wordlview.JSON.MapConfig> used in configuration (read only).
+ */
+ self.mapConfig = mapConfig;
+
/**
* Property: map
* OpenLayers.Map object used for the currently selected projection
@@ -240,7 +246,8 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
var productConfig = productConfigs[name];
if ( !productConfig ) {
- throw "No such product: " + name;
+ log.warn("No such product: " + name);
+ return true;
}
if ( $.inArray(name, self.products) >= 0 ) {
log.warn("Product already added: " + name);
diff --git a/js/Worldview/Widget/Map.js b/js/Worldview/Widget/Map.js
index bee9d6642..c147234bf 100644
--- a/js/Worldview/Widget/Map.js
+++ b/js/Worldview/Widget/Map.js
@@ -113,16 +113,7 @@ Worldview.Widget.Map = function(containerId, spec) {
*/
self.loadFromQuery = function(queryString) {
log.debug("loadFromQuery: " + queryString);
-
- var query = Worldview.queryStringToObject(queryString);
-
- var projection = query["switch"] || "geographic";
- self.productMap.setProjection(projection)
-
- var extent = query[containerId];
- if ( extent ) {
- self.setValue(extent);
- }
+ self.updateComponent(queryString);
};
/**
@@ -183,7 +174,7 @@ Worldview.Widget.Map = function(containerId, spec) {
var onConfigLoad = function(result) {
try {
- self.config = result;
+ self.config = validateConfig(result);
self.productMap = Worldview.Map.ProductMap(containerId,
self.config, self);
@@ -211,6 +202,19 @@ Worldview.Widget.Map = function(containerId, spec) {
message);
};
+ /*
+ * Make sure that all the required parameters exist in the map
+ * configuration.
+ */
+ var validateConfig = function(config) {
+ var keys = ["defaultProjection", "projections", "products"];
+ $.each(keys, function(index, key) {
+ if ( !(key in config) ) {
+ throw key + " is required in the map configuration";
+ }
+ });
+ return config;
+ }
init();
return self;
};
diff --git a/js/Worldview/Widget/WorldviewMap.js b/js/Worldview/Widget/WorldviewMap.js
index 24f301b69..9c6e4cdd8 100644
--- a/js/Worldview/Widget/WorldviewMap.js
+++ b/js/Worldview/Widget/WorldviewMap.js
@@ -77,7 +77,15 @@ Worldview.Widget.WorldviewMap = function(containerId, spec) {
log.debug(state);
if ( state["switch"] !== last["switch"] ) {
- self.productMap.setProjection(state["switch"]);
+ var projection = state["switch"];
+ if ( !(projection in self.productMap.mapConfig.projections) ) {
+ var defaultProjection =
+ self.productMap.mapConfig.defaultProjection;
+ log.warn("Invalid projection: " + projection + ", using: " +
+ defaultProjection);
+ projection = defaultProjection;
+ }
+ self.productMap.setProjection(projection);
self.productMap.set(state.products);
} else if ( state.productsString !== last.productsString ) {
self.productMap.set(state.products);
@@ -132,6 +140,9 @@ Worldview.Widget.WorldviewMap = function(containerId, spec) {
*/
var splitProducts = function(state) {
var results = [];
+ if ( state.products === undefined ) {
+ return results;
+ }
var sets = state.products.split("~");
for ( var i = 0; i < sets.length; i++ ) {
var set = sets[i];
diff --git a/js/bank.js b/js/bank.js
index caf7fc733..fcc181477 100644
--- a/js/bank.js
+++ b/js/bank.js
@@ -19,6 +19,9 @@ SOTE.widget.Bank.prototype = new SOTE.widget.Component;
*
*/
SOTE.widget.Bank = function(containerId, config){
+ this.log = Logging.Logger("Worldview.Widget.Bank");
+ this.VALID_PROJECTIONS = ["geographic", "artcic", "antarctic"];
+
//Get the ID of the container element
this.container=document.getElementById(containerId);
if (this.container==null){
@@ -352,6 +355,18 @@ SOTE.widget.Bank.prototype.fire = function(){
SOTE.widget.Bank.prototype.setValue = function(valString){
this.values = this.unserialize(valString);
+ for ( category in this.values ) {
+ var validProducts = [];
+ var self = this;
+ $.each(this.values[category], function(index, product) {
+ if ( !(product.value in self.meta) ) {
+ self.log.warn("Invalid product: " + product.value);
+ } else {
+ validProducts.push(product);
+ }
+ });
+ this.values[category] = validProducts;
+ }
this.render();
this.fire();
@@ -436,7 +451,11 @@ SOTE.widget.Bank.handleUpdateSuccess = function(self,qs){
data.selected = (data.selected === undefined || data.selected === "")? SOTE.util.extractFromQuery(args.self.id,args.self.getValue()):data.selected;*/
var projection = SOTE.util.extractFromQuery("switch", qs);
if (projection === "") {
- projection = "geographic";
+ projection = self.VALID_PROJECTIONS[0];
+ } else if ($.inArray(projection, self.VALID_PROJECTIONS) < 0) {
+ self.log.warn("Invalid projection: " + projection + ", using: " +
+ self.VALID_PROJECTIONS[0]);
+ projection = self.VALID_PROJECTIONS[0];
}
if(projection == self.state){
var vals = SOTE.util.extractFromQuery("selectorbox",qs)
@@ -477,7 +496,7 @@ SOTE.widget.Bank.prototype.loadFromQuery = function(qs){
}
if(this.state != newState){
this.state = newState;
- this.buildMeta(SOTE.widget.Bank.loadValue,SOTE.util.extractFromQuery(this.id,qs));
+ this.updateComponent(qs);
}
else {
this.sleep(SOTE.util.extractFromQuery(this.id,qs));
diff --git a/js/switch.js b/js/switch.js
index 3e76111a6..e93d10789 100644
--- a/js/switch.js
+++ b/js/switch.js
@@ -19,6 +19,9 @@ SOTE.widget.Switch.prototype = new SOTE.widget.Component;
*
*/
SOTE.widget.Switch = function(containerId, config){
+ this.log = Logging.Logger("Worldview.Widget.Switch");
+ this.VALID_PROJECTIONS = ["geographic", "arctic", "antarctic"];
+
//Get the ID of the container element
this.container=document.getElementById(containerId);
if (this.container==null){
@@ -135,10 +138,17 @@ SOTE.widget.Switch.prototype.fire = function(){
*/
SOTE.widget.Switch.prototype.setValue = function(valString){
+ // Check to see if the projection is valid. If not, default to the first
+ // projectiond defined.
if ( valString === "" ) {
- valString = "geographic";
+ this.value = this.VALID_PROJECTIONS[0];
+ } else if ( $.inArray(valString, this.VALID_PROJECTIONS) < 0 ) {
+ this.log.warn("Invalid projection: " + valString + ", using: " +
+ this.VALID_PROJECTIONS[0]);
+ this.value = this.VALID_PROJECTIONS[0];
+ } else {
+ this.value = valString;
}
- this.value = valString
$("#" + this.id+"current").attr("src","images/"+this.value+".png");
this.validate();
this.fire();