Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Make bad proj not break app #1792

Benjamin King2c5bc8462ab8
diff --git a/web/js/location.js b/web/js/location.js
index be46a4532..ecab55894 100644
--- a/web/js/location.js
+++ b/web/js/location.js
@@ -10,7 +10,10 @@ import {
import { getMapParameterSetup } from './modules/map/util';
import { eventParse, serializeEvent } from './modules/natural-events/util';
import { mapLocationToCompareState } from './modules/compare/util';
-import { mapLocationToProjState } from './modules/projection/util';
+import {
+ mapLocationToProjState,
+ parseProjection
+} from './modules/projection/util';
import {
layersParse12,
serializeLayers,
@@ -115,7 +118,12 @@ const getParameters = function(config, parameters) {
return {
p: {
stateKey: 'proj.id',
- initialState: 'geographic'
+ initialState: 'geographic',
+ options: {
+ parse: str => {
+ return parseProjection(str, config);
+ }
+ }
},
now: {
stateKey: 'date.testNow',
diff --git a/web/js/map/model.js b/web/js/map/model.js
index 8ad1528b2..bd319132a 100644
--- a/web/js/map/model.js
+++ b/web/js/map/model.js
@@ -70,18 +70,24 @@ export function mapModel(models, config) {
if (state.v) {
const projId = state.p ? state.p : 'geographic';
var proj = config.projections[projId];
- var extent = state.v;
- var maxExtent = proj.maxExtent;
+ if (proj) {
+ var extent = state.v;
+ var maxExtent = proj.maxExtent;
- if (proj.id === 'geographic') {
- proj.wrapExtent = maxExtent = [-250, -90, 250, 90];
- }
- if (intersects(extent, maxExtent)) {
- self.extent = state.v;
+ if (proj.id === 'geographic') {
+ proj.wrapExtent = maxExtent = [-250, -90, 250, 90];
+ }
+ if (intersects(extent, maxExtent)) {
+ self.extent = state.v;
+ } else {
+ self.extent = lodashClone(proj.maxExtent);
+ errors.push({
+ message: 'Extent outside of range'
+ });
+ }
} else {
- self.extent = lodashClone(proj.maxExtent);
errors.push({
- message: 'Extent outside of range'
+ message: 'Projection does not exist'
});
}
}
diff --git a/web/js/modules/projection/util.js b/web/js/modules/projection/util.js
index 4a191f362..703a2e4b8 100644
--- a/web/js/modules/projection/util.js
+++ b/web/js/modules/projection/util.js
@@ -11,6 +11,10 @@ export function getProjInitialState(config) {
selected: selected || {}
};
}
+export function parseProjection(str, config) {
+ const exists = !!lodashGet(config, `projections.${str}`);
+ return exists ? str : 'geographic';
+}
/**
* Update 'proj.selected' object from config based
* on updated states `proj.id` value