Interactive interface for browsing global, full-resolution satellite imagery
Save and load animation widget state, fix compare mode bugs
ZachTRice69b6e159e332
diff --git a/web/js/app.js b/web/js/app.jsindex a695a2ceb..0a5ab3c70 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -440,8 +440,8 @@ class App extends React.Component {// Create widgetsui.alert = alertUi(ui);ui.proj = projectionUi(models, config);- ui.tour = tourUi(models, ui, config);ui.sidebar = sidebarUi(models, config, ui);+ ui.tour = tourUi(models, ui, config);ui.activeLayers = layersActive(models, ui, config);ui.addModal = layersModal(models, ui, config);ui.layerSettingsModal = layersOptions(models, ui, config);diff --git a/web/js/components/tour/modal-tour-in-progress.js b/web/js/components/tour/modal-tour-in-progress.jsindex 148e41c53..f0b3e3ba7 100644--- a/web/js/components/tour/modal-tour-in-progress.js+++ b/web/js/components/tour/modal-tour-in-progress.js@@ -75,7 +75,17 @@ class ModalInProgress extends React.Component {if (prevStepIndex) prevStepLink = currentStory.steps[prevStepIndex]['stepLink'];// TESTING HERE:- // currentStepLink = 'ca=false&cm=swipe&cv=50&p=geographic&l=VIIRS_SNPP_CorrectedReflectance_TrueColor(hidden),MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor,IMERG_Rain_Rate,Reference_Labels,Reference_Features,Coastlines&l1=VIIRS_SNPP_CorrectedReflectance_TrueColor(hidden),MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor,AMSUA_NOAA15_Brightness_Temp_Channel_1,IMERG_Rain_Rate,Reference_Labels,Reference_Features,Coastlines&t=2018-09-06-T00%3A00%3A00Z&z=2&t1=2018-03-06-T00%3A00%3A00Z&v=-202.1385353269304,-23.272676762951903,67.8614646730696,108.6335732370481';+ currentStepLink =+ 'ca=true' ++ '&cm=opacity' ++ '&cv=50' ++ '&p=geographic' ++ '&l=VIIRS_SNPP_CorrectedReflectance_TrueColor(hidden),MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor,MODIS_Combined_Value_Added_AOD,Reference_Labels(hidden),Reference_Features(hidden),Coastlines' ++ '&l1=BlueMarble_NextGeneration,IMERG_Snow_Rate,IMERG_Rain_Rate' ++ '&t=2018-09-06-T00%3A00%3A00Z' ++ '&z=2' ++ '&t1=2018-03-06-T00%3A00%3A00Z' ++ '&v=-202.1385353269304,-23.272676762951903,67.8614646730696,108.6335732370481';currentState = util.fromQueryString(currentStepLink);prevState = util.fromQueryString(prevStepLink);@@ -141,9 +151,6 @@ class ModalInProgress extends React.Component {rotation = 0;}- // LOAD: Initial Load- models.link.load(currentState);-// LOAD: Map Projectionif (currentState.p) {models.proj.select(currentState.p);@@ -155,6 +162,88 @@ class ModalInProgress extends React.Component {// LOAD: Layersmodels.layers.load(currentState);+ // LOAD: Comparison+ if (currentState.ca) {+ models.compare.active = true;+ models.compare.isCompareA = 'true';+ if (currentState.ca === 'false') {+ models.compare.isCompareA = 'false';+ }+ }+ if (currentState.cm) {+ models.compare.active = true;+ models.compare.isCompareA = 'true';+ if (currentState.ca === 'false') {+ models.compare.isCompareA = 'false';+ }+ models.compare.mode = currentState.cm;+ models.compare.setMode(currentState.cm);+ }+ if (currentState.cv) {+ models.compare.value = Number(currentState.cv);+ models.compare.setValue(currentState.cv);+ }++ if (currentState.ca || currentState.cm) {+ models.compare.save(currentState);+ models.compare.load(currentState);++ // TODO: Tweak this+ models.date.events.trigger('state-update');+ ui.timeline.input.update();++ var compareObj = {};+ if (config.features.compare) {+ if (models.compare.active) {+ compareObj.a = {+ dateString: util.toISOStringDate(currentState.t),+ layers: models.layers.get(+ { group: 'all', proj: 'all' },+ models.layers['active']+ )+ };+ compareObj.b = {+ dateString: util.toISOStringDate(currentState.t1),+ layers: models.layers.get(+ { group: 'all', proj: 'all' },+ models.layers['activeB']+ )+ };+ }+ }++ var toggleComparisonObject = function() {+ models.compare.toggleState();+ };++ var toggleComparisonMode = function() {+ console.log(models.date.selectedB);+ if (!models.layers.activeB || !models.date.selectedB) {+ if (!models.date.selectedB) {+ models.date.initCompare();+ }+ if (!models.layers.activeB) {+ models.layers.initCompare();+ }+ }+ models.compare.toggle();+ };+ console.log(models.compare.isCompareA);+ ui.sidebar.reactComponent.setState({+ compareFeature: config.features.compare,+ isCompareMode:+ models.compare && models.compare.active ? models.compare.active : false,+ firstDateObject: compareObj.a,+ secondDateObject: compareObj.b,+ toggleComparisonObject: toggleComparisonObject,+ toggleMode: toggleComparisonMode,+ isCompareA: models.compare && models.compare.isCompareA,+ comparisonType: currentState.cm+ });++ // models.compare.events.trigger('toggle');+ }+// LOAD: Date(s)if (currentState.ca === 'false') {models.date.setActiveDate('selectedB');@@ -176,6 +265,10 @@ class ModalInProgress extends React.Component {}// LOAD: Animation+ models.anim.save(currentState);+ models.anim.load(currentState);++ // SET UI: ANIMATIONif (currentState.al) {ui.anim.widget.reactComponent.setState({ looping: true });} else {@@ -201,70 +294,6 @@ class ModalInProgress extends React.Component {ui.anim.widget.toggleAnimationWidget();}- // LOAD: Comparison- if (currentState.ca) {- models.compare.active = true;- models.compare.isCompareA = currentState.ca === 'true';- }- if (currentState.cm) {- models.compare.active = true;- models.compare.mode = currentState.cm;- }- if (currentState.cv) {- models.compare.value = Number(currentState.cv);- }- var compareModel;- var compareObj = {};- var compareModeType = 'swipe';- if (config.features.compare) {- compareModel = models.compare;- if (models.compare.active) {- compareObj.a = {- dateString: util.toISOStringDate(currentState.t),- layers: models.layers.get(- { group: 'all', proj: 'all' },- models.layers['active']- )- };- compareObj.b = {- dateString: util.toISOStringDate(currentState.t1),- layers: models.layers.get(- { group: 'all', proj: 'all' },- models.layers['activeB']- )- };- compareModeType = compareModel.mode;- }- }-- var toggleComparisonObject = function() {- models.compare.toggleState();- };-- var toggleComparisonMode = function() {- if (!models.layers.activeB || !models.date.selectedB) {- if (!models.date.selectedB) {- models.date.initCompare();- }- if (!models.layers.activeB) {- models.layers.initCompare();- }- }- models.compare.toggle();- };-- ui.sidebar.reactComponent.setState({- isCompareMode:- compareModel && compareModel.active ? compareModel.active : false,- firstDateObject: compareObj.a,- secondDateObject: compareObj.b,- toggleComparisonObject: toggleComparisonObject,- toggleMode: toggleComparisonMode,- isCompareA: compareModel && compareModel.isCompareA,- comparisonType: compareModeType,- changeCompareMode: compareModel ? compareModel.setMode : null- });-// LOAD: Data Downloadif (currentState.download) {let productId = currentState.download;diff --git a/web/js/layers/model.js b/web/js/layers/model.jsindex c56fdf95d..580324e79 100644--- a/web/js/layers/model.js+++ b/web/js/layers/model.js@@ -150,49 +150,51 @@ export function layersModel(models, config) {var range = false;var maxDates = [];lodashEach(layers, function(def) {- if (def.startDate) {- range = true;- var start = util.parseDateUTC(def.startDate).getTime();- min = Math.min(min, start);- }- // For now, we assume that any layer with an end date is- // an ongoing product unless it is marked as inactive.- if (def.futureLayer && def.endDate) {- range = true;- max = util.parseDateUTC(def.endDate).getTime();- maxDates.push(new Date(max));- } else if (def.inactive && def.endDate) {- range = true;- var end = util.parseDateUTC(def.endDate).getTime();- max = Math.max(max, end);- maxDates.push(new Date(max));- } else if (def.endDate) {- range = true;- max = util.now().getTime();- maxDates.push(new Date(max));- }- // If there is a start date but no end date, this is a- // product that is currently being created each day, set- // the max day to today.- if (def.futureLayer && def.futureTime && !def.endDate) {- // Calculate endDate + parsed futureTime from layer JSON- max = new Date();- var futureTime = def.futureTime;- var dateType = futureTime.slice(-1);- var dateInterval = futureTime.slice(0, -1);- if (dateType === 'D') {- max.setDate(max.getDate() + parseInt(dateInterval));+ if (def) {+ if (def.startDate) {+ range = true;+ var start = util.parseDateUTC(def.startDate).getTime();+ min = Math.min(min, start);+ }+ // For now, we assume that any layer with an end date is+ // an ongoing product unless it is marked as inactive.+ if (def.futureLayer && def.endDate) {+ range = true;+ max = util.parseDateUTC(def.endDate).getTime();maxDates.push(new Date(max));- } else if (dateType === 'M') {- max.setMonth(max.getMonth() + parseInt(dateInterval));+ } else if (def.inactive && def.endDate) {+ range = true;+ var end = util.parseDateUTC(def.endDate).getTime();+ max = Math.max(max, end);maxDates.push(new Date(max));- } else if (dateType === 'Y') {- max.setYear(max.getYear() + parseInt(dateInterval));+ } else if (def.endDate) {+ range = true;+ max = util.now().getTime();+ maxDates.push(new Date(max));+ }+ // If there is a start date but no end date, this is a+ // product that is currently being created each day, set+ // the max day to today.+ if (def.futureLayer && def.futureTime && !def.endDate) {+ // Calculate endDate + parsed futureTime from layer JSON+ max = new Date();+ var futureTime = def.futureTime;+ var dateType = futureTime.slice(-1);+ var dateInterval = futureTime.slice(0, -1);+ if (dateType === 'D') {+ max.setDate(max.getDate() + parseInt(dateInterval));+ maxDates.push(new Date(max));+ } else if (dateType === 'M') {+ max.setMonth(max.getMonth() + parseInt(dateInterval));+ maxDates.push(new Date(max));+ } else if (dateType === 'Y') {+ max.setYear(max.getYear() + parseInt(dateInterval));+ maxDates.push(new Date(max));+ }+ } else if (def.startDate && !def.endDate) {+ max = util.now().getTime();maxDates.push(new Date(max));}- } else if (def.startDate && !def.endDate) {- max = util.now().getTime();- maxDates.push(new Date(max));}});if (range) {diff --git a/web/js/map/ui.js b/web/js/map/ui.jsindex e752c1fb2..e8b5ce774 100644--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@ -452,7 +452,7 @@ export function mapui(models, config) {var layer = findLayer(def, activeLayerString);if (models.compare && models.compare.active) {let layerGroup = getActiveLayerGroup(self.selected, activeLayerString);- layerGroup.getLayers().remove(layer);+ if (layerGroup) layerGroup.getLayers().remove(layer);} else {self.selected.removeLayer(layer);}