Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

No longer crashes if data download selects a product in the permalink and no active layers match that product

Mike McGann6f2777f717c0
diff --git a/src/js/data/wv.data.model.js b/src/js/data/wv.data.model.js
index 8cbc83d08..064b7f84b 100644
--- a/src/js/data/wv.data.model.js
+++ b/src/js/data/wv.data.model.js
@@ -282,12 +282,23 @@ wv.data.model = wv.data.model || function(models, config) {
}
};
- self.load = function(state) {
+ self.load = function(state, errors) {
var productId = state.dataDownload;
if ( productId ) {
- models.wv.events.on("startup", function() {
- self.activate(productId);
+ var found = false;
+ _.each(models.layers.get(), function(layer) {
+ if ( layer.product === productId ) {
+ found = true;
+ }
});
+ if ( !found ) {
+ errors.push({message: "No active layers match product: " +
+ productId});
+ } else {
+ models.wv.events.on("startup", function() {
+ self.activate(productId);
+ });
+ }
}
};
diff --git a/src/js/layers/wv.layers.model.js b/src/js/layers/wv.layers.model.js
index c519eba17..f31cd9bea 100644
--- a/src/js/layers/wv.layers.model.js
+++ b/src/js/layers/wv.layers.model.js
@@ -67,6 +67,7 @@ wv.layers.model = wv.layers.model || function(models, config) {
};
self.forGroup = function(group, spec) {
+ spec = spec || {};
var results = [];
var groups = self.forProjection();
_.each(groups[group], function(layer) {
@@ -82,6 +83,7 @@ wv.layers.model = wv.layers.model || function(models, config) {
};
self.get = function(spec) {
+ spec = spec || {};
var baselayers = self.forGroup("baselayers", spec);
var overlays = self.forGroup("overlays", spec);
return baselayers.concat(overlays);
diff --git a/test/data/wv.data-test.js b/test/data/wv.data-test.js
index 3360271a0..39191e808 100644
--- a/test/data/wv.data-test.js
+++ b/test/data/wv.data-test.js
@@ -36,4 +36,5 @@ buster.testCase("wv.data", {
buster.refute(state.dataDownload);
buster.assert.equals(this.errors.length, 1);
}
+
});
diff --git a/test/data/wv.data.model-test.js b/test/data/wv.data.model-test.js
index 8f40f05eb..71f71e45c 100644
--- a/test/data/wv.data.model-test.js
+++ b/test/data/wv.data.model-test.js
@@ -14,11 +14,19 @@ buster.testCase("wv.data.model", {
config: null,
models: null,
model: null,
+ errors: null,
setUp: function() {
this.config = {
products: {
"product1": {}
+ },
+ layers: {
+ "layer1": {
+ product: "product1",
+ group: "overlays",
+ projections: { geographic: {} }
+ }
}
};
this.models = {};
@@ -28,7 +36,9 @@ buster.testCase("wv.data.model", {
};
this.models.date = wv.date.model();
this.models.layers = wv.layers.model(this.models, this.config);
+ this.models.layers.add("layer1");
this.model = wv.data.model(this.models, this.config);
+ this.errors = [];
},
"Doesn't save state when not active": function() {
@@ -46,16 +56,29 @@ buster.testCase("wv.data.model", {
buster.assert.equals(state.dataDownload, "product1");
},
- "Subscribed for startup event when data download in permalink": function() {
+ "Subscribed for startup event when data download in load state": function() {
this.models.wv = {
events: {
on: this.stub()
}
};
var state = { dataDownload: "product1" };
- this.model.load(state);
+ this.model.load(state, this.errors);
+ buster.assert.equals(this.errors.length, 0);
buster.assert.calledWith(this.models.wv.events.on, "startup");
- }
+ },
+ "Error product is in state when no active layer is found": function() {
+ this.models.wv = {
+ events: {
+ on: this.stub()
+ }
+ };
+ this.models.layers.remove("layer1");
+ var state = { dataDownload: "product1" };
+ this.model.load(state, this.errors);
+ buster.assert.equals(this.errors.length, 1);
+ buster.refute.calledWith(this.models.wv.events.on, "startup");
+ }
});