Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Move map animation after event selcetion to fix rotation animation

ZachTRicebb57aa380f2e
diff --git a/web/js/components/tour/modal-tour-in-progress.js b/web/js/components/tour/modal-tour-in-progress.js
index 9a9e6fa2a..1190f9ec3 100644
--- a/web/js/components/tour/modal-tour-in-progress.js
+++ b/web/js/components/tour/modal-tour-in-progress.js
@@ -80,7 +80,7 @@ class ModalInProgress extends React.Component {
if (prevStepIndex) prevStepLink = currentStory.steps[prevStepIndex]['stepLink'];
// TESTING HERE:
- // currentStepLink = 'ca=true&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,IMERG_Rain_Rate,Reference_Labels,Reference_Features,Coastlines&t=2018-09-06-T00%3A00%3A00Z&z=2&t1=2018-09-19-T00%3A00%3A00Z&v=-81.00856222007965,31.36000753998159,-72.57106222007965,36.79197390923348';
+ // 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';
currentState = util.fromQueryString(currentStepLink);
prevState = util.fromQueryString(prevStepLink);
@@ -137,6 +137,11 @@ class ModalInProgress extends React.Component {
models.link.load(currentState);
+ // LOAD: Map Projection
+ if (currentState.p) {
+ models.proj.select(currentState.p);
+ }
+
// Set rotation value if it exists
if (currentState.p === 'arctic' || currentState.p === 'antarctic') {
if (!isNaN(currentState.r)) {
@@ -148,6 +153,10 @@ class ModalInProgress extends React.Component {
rotation = 0;
}
+ // LOAD: Layers
+ models.layers.save(currentState);
+ models.layers.load(currentState);
+
// LOAD: Date(s)
if (currentState.ca === 'false') {
models.date.setActiveDate('selectedB');
@@ -162,6 +171,40 @@ class ModalInProgress extends React.Component {
models.date.select(currentState.t1, 'selectedB');
}
+ // Load: Timeline Zoom Level
+ if (currentState.z) {
+ let zoomLevel = Number(currentState.z);
+ ui.timeline.config.zoom(zoomLevel);
+ }
+
+ // LOAD: Animation
+ // Note: Seems like animation must come before comparison
+ // Set state from URL
+ if (currentState.al) {
+ ui.anim.widget.reactComponent.setState({ looping: true });
+ } else {
+ ui.anim.widget.reactComponent.setState({ looping: false });
+ }
+ if (currentState.as) ui.anim.widget.reactComponent.setState({ startDate: currentState.as });
+ if (currentState.ae) ui.anim.widget.reactComponent.setState({ endDate: currentState.ae });
+ if (currentState.av) ui.anim.widget.reactComponent.setState({ value: Number(currentState.av) });
+
+ // If animation is current on, toggle the state and animation widget
+ if (prevState.ab === 'on' && currentState.ab === 'off') {
+ models.anim.activate();
+ ui.anim.widget.toggleAnimationWidget();
+ } else
+ if (prevState.ab === 'on' && !currentState.ab) {
+ models.anim.activate();
+ ui.anim.widget.toggleAnimationWidget();
+ } else if (prevState.ab === 'off' && currentState.ab === 'on') {
+ models.anim.deactivate();
+ ui.anim.widget.toggleAnimationWidget();
+ } else if (!prevState.ab && currentState.ab === 'on') {
+ models.anim.deactivate();
+ ui.anim.widget.toggleAnimationWidget();
+ }
+
// LOAD: Comparison
if (currentState.ca) {
models.compare.active = true;
@@ -213,7 +256,7 @@ class ModalInProgress extends React.Component {
}
models.compare.toggle();
};
- console.log(compareObj);
+
ui.sidebar.reactComponent.setState({
isCompareMode:
compareModel && compareModel.active ? compareModel.active : false,
@@ -226,115 +269,6 @@ class ModalInProgress extends React.Component {
changeCompareMode: compareModel ? compareModel.setMode : null
});
- // LOAD: Map Projection
- if (currentState.p) {
- models.proj.select(currentState.p);
- }
-
- // Load: Timeline Zoom Level
- if (currentState.z) {
- let zoomLevel = Number(currentState.z);
- ui.timeline.config.zoom(zoomLevel);
- }
-
- // LOAD: Map Zoom & View & Rotation(Animated)
- // TODO: Fix rotation animation
- if (currentState.v) {
- // Animate to extent & zoom:
- let extent = currentState.v;
- var coordinateX = extent[0] + (extent[2] - extent[0]) / 2;
- var coordinateY = extent[1] + (extent[3] - extent[1]) / 2;
- let coordinates = [coordinateX, coordinateY];
- let resolution = ui.map.selected.getView().getResolutionForExtent(extent);
- ui.map.selected.getView().animate({
- center: coordinates,
- duration: 4000,
- resolution: resolution,
- rotation: rotation
- });
-
- // To jump to extent & zoom (instead of animate):
- // ui.map.selected.getView().fit(currentState.v, ui.map.selected.getSize());
- }
-
- // LOAD: Animation
- // Note: Seems like animation must come before comparison
- // Set state from URL
- if (currentState.al) {
- ui.anim.widget.reactComponent.setState({ looping: true });
- } else {
- ui.anim.widget.reactComponent.setState({ looping: false });
- }
- if (currentState.as) ui.anim.widget.reactComponent.setState({ startDate: currentState.as });
- if (currentState.ae) ui.anim.widget.reactComponent.setState({ endDate: currentState.ae });
- if (currentState.av) ui.anim.widget.reactComponent.setState({ value: Number(currentState.av) });
-
- // If animation is current on, toggle the state and animation widget
- if (prevState.ab === 'on' && currentState.ab === 'off') {
- models.anim.activate();
- ui.anim.widget.toggleAnimationWidget();
- } else
- if (prevState.ab === 'on' && !currentState.ab) {
- models.anim.activate();
- ui.anim.widget.toggleAnimationWidget();
- } else if (prevState.ab === 'off' && currentState.ab === 'on') {
- models.anim.deactivate();
- ui.anim.widget.toggleAnimationWidget();
- } else if (!prevState.ab && currentState.ab === 'on') {
- models.anim.deactivate();
- ui.anim.widget.toggleAnimationWidget();
- }
-
- // LOAD: Layers
- var layers;
- if (config.features.compare) {
- layers = [
- {
- state: 'l',
- active: 'active'
- },
- {
- state: 'l1',
- active: 'activeB'
- }
- ];
- } else {
- layers = [{ state: 'l', active: 'active' }];
- }
- lodashEach(layers, obj => {
- if (!lodashIsUndefined(currentState[obj.state])) {
- models.layers.clear(models.proj.selected.id, obj.active);
- lodashEachRight(currentState[obj.state], function(layerDef) {
- if (!config.layers[layerDef.id]) {
- errors.push({
- message: 'No such layer: ' + layerDef.id
- });
- return;
- }
- var hidden = false;
- var opacity = 1.0;
- lodashEach(layerDef.attributes, function(attr) {
- if (attr.id === 'hidden') {
- hidden = true;
- }
- if (attr.id === 'opacity') {
- opacity = util.clamp(parseFloat(attr.value), 0, 1);
- if (isNaN(opacity)) opacity = 0; // "opacity=0.0" is opacity in URL, resulting in NaN
- }
- });
-
- models.layers[obj.active] = models.layers.add(
- layerDef.id,
- {
- hidden: hidden,
- opacity: opacity
- },
- obj.active
- );
- });
- }
- });
-
// LOAD: Data Download
if (currentState.download) {
let productId = currentState.download;
@@ -367,6 +301,28 @@ class ModalInProgress extends React.Component {
ui.sidebar.selectTab('layers');
}
+ // LOAD: Map Zoom & View & Rotation(Animated)
+ if (currentState.v) {
+ // Animate to extent & zoom:
+ let extent = currentState.v;
+ var coordinateX = extent[0] + (extent[2] - extent[0]) / 2;
+ var coordinateY = extent[1] + (extent[3] - extent[1]) / 2;
+ let coordinates = [coordinateX, coordinateY];
+ let resolution = ui.map.selected.getView().getResolutionForExtent(extent);
+ var duration;
+ // Don't animate when projection changes
+ if (prevState.p !== currentState.p) { duration = 0; } else { duration = 5000; }
+ ui.map.selected.getView().animate({
+ center: coordinates,
+ duration: duration,
+ resolution: resolution,
+ rotation: rotation
+ });
+
+ // To jump to extent & zoom (instead of animate):
+ // ui.map.selected.getView().fit(currentState.v, ui.map.selected.getSize());
+ }
+
// ACTION: Animation
if (stepTransition) {
if (stepTransition.element === 'animation' && stepTransition.action === 'play') {
diff --git a/web/js/layers/model.js b/web/js/layers/model.js
index 637636b96..c56fdf95d 100644
--- a/web/js/layers/model.js
+++ b/web/js/layers/model.js
@@ -502,7 +502,7 @@ export function layersModel(models, config) {
});
};
self.load = function(state, errors) {
- if (self.loaded) return;
+ // if (self.loaded) return;
var layers;
if (config.features.compare) {
@@ -555,7 +555,7 @@ export function layersModel(models, config) {
if (state.ca && state.ca !== 'true') {
self.activeLayers = 'activeB';
}
- self.loaded = true;
+ // self.loaded = true;
};
var forGroup = function(group, spec, activeLayers) {
spec = spec || {};