Interactive interface for browsing global, full-resolution satellite imagery
WV-952: Defaults to max extent if extent in permalink is invalid
Mike McGann3d4e08464901
diff --git a/src/js/map/wv.map.model.js b/src/js/map/wv.map.model.jsindex b5a50a52f..6c3f63137 100644--- a/src/js/map/wv.map.model.js+++ b/src/js/map/wv.map.model.js@@ -26,9 +26,17 @@ wv.map.model = wv.map.model || function(models, config) {self.events.trigger("update", extent);};- self.load = function(state) {+ self.load = function(state, errors) {if ( state.v ) {- self.extent = state.v;+ var proj = models.proj.selected;+ var extent = new OpenLayers.Bounds(state.v);+ var maxExtent = new OpenLayers.Bounds(proj.maxExtent);+ if ( extent.intersectsBounds(maxExtent) ) {+ self.extent = state.v;+ } else {+ self.extent = proj.maxExtent+ errors.push({message: "Extent outside of range"});+ }} else {if ( models.proj.selected.id === "geographic" ) {self.setExtentToLeading();diff --git a/test/fixtures.js b/test/fixtures.jsindex a9eac8527..4ce3e4669 100644--- a/test/fixtures.js+++ b/test/fixtures.js@@ -17,7 +17,8 @@ fixtures.config = function() { return {geographic: {id: "geographic",epsg: 4326,- crs: "EPSG:4326"+ crs: "EPSG:4326",+ maxExtent: [-180, -90, 180, 90]},arctic: {id: "arctic",@@ -107,6 +108,7 @@ fixtures.models = function(config) {models.proj = wv.proj.model(config);models.layers = wv.layers.model(models, config);models.palettes = wv.palettes.model(models, config);+ models.map = wv.map.model(models, config);return models;};diff --git a/test/map/wv.map.model-test.js b/test/map/wv.map.model-test.jsnew file mode 100644index 000000000..8d2cc8cd6--- /dev/null+++ b/test/map/wv.map.model-test.js@@ -0,0 +1,38 @@+/*+ * NASA Worldview+ *+ * This code was originally developed at NASA/Goddard Space Flight Center for+ * the Earth Science Data and Information System (ESDIS) project.+ *+ * Copyright (C) 2013 - 2014 United States Government as represented by the+ * Administrator of the National Aeronautics and Space Administration.+ * All Rights Reserved.+ */++buster.testCase("wv.map.model", function() {++ var self = {};+ var config;+ var errors;++ self.setUp = function() {+ config = fixtures.config();+ models = fixtures.models(config);+ errors = [];+ };++ self["Loads valid extent"] = function() {+ models.map.load({v: [-10, -10, 10, 10]}, errors);+ buster.assert.equals([-10, -10, 10, 10], models.map.extent);+ buster.assert.equals(0, errors.length);+ };++ self["Defaults to max extent if out-of-bounds on load"] = function() {+ models.map.load({v: [-1000, -1000, -1000, -1000]}, errors);+ buster.assert.equals([-180, -90, 180, 90], models.map.extent);+ buster.assert.equals(1, errors.length);+ };++ return self;++}());