Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Add active date/layers to animation #1118

Benjamin Kingd3d14ce478a5
diff --git a/web/js/animation/anim.js b/web/js/animation/anim.js
index a0d2f770d..5ec8a479e 100644
--- a/web/js/animation/anim.js
+++ b/web/js/animation/anim.js
@@ -1,6 +1,6 @@
import lodashEach from 'lodash/each';
-export function parse (state, errors) {
+export function parse(state, errors) {
if (state.a) {
var str = state.a;
var astate = {
@@ -9,15 +9,16 @@ export function parse (state, errors) {
// Get text before (
var on = str.match(/[^(,]+/)[0];
- if (on !== 'on') { // don't do anything if wrong format
- state.a = undefined;
+ if (on !== 'on') {
+ // don't do anything if wrong format
+ state.ab = undefined;
return;
}
// remove (, get key value pairs
str = str.match(/\(.*\)/)[0].replace(/[()]/g, '');
var kvps = str.split(',');
- lodashEach(kvps, function (kvp) {
+ lodashEach(kvps, function(kvp) {
var parts = kvp.split('=');
astate.attributes.push({
id: parts[0],
@@ -26,4 +27,4 @@ export function parse (state, errors) {
});
state.a = astate;
}
-};
+}
diff --git a/web/js/animation/range-select.js b/web/js/animation/range-select.js
index 6f4094183..e0bcfdcd6 100644
--- a/web/js/animation/range-select.js
+++ b/web/js/animation/range-select.js
@@ -24,7 +24,7 @@ export function animationRangeSelect(models, config, ui) {
* @returns {void}
*
*/
- self.init = function () {
+ self.init = function() {
self.setDefaults();
self.render();
models.date.events.on('timeline-change', self.update);
@@ -41,7 +41,7 @@ export function animationRangeSelect(models, config, ui) {
* @returns {void}
*
*/
- self.setDefaults = function () {
+ self.setDefaults = function() {
/*
* Set some defaults
*/
@@ -63,18 +63,18 @@ export function animationRangeSelect(models, config, ui) {
* @returns {void}
*
*/
- self.render = function () {
+ self.render = function() {
var options;
var startLocation;
var endLocation;
var pick = d3.select('#guitarpick');
- var pickWidth = pick.node()
- .getBoundingClientRect()
- .width;
- var animEndLocation = (d3.transform(pick.attr('transform'))
- .translate[0] - (pickWidth / 2)); // getting guitar pick location
+ var pickWidth = pick.node().getBoundingClientRect().width;
+ var animEndLocation =
+ d3.transform(pick.attr('transform')).translate[0] - pickWidth / 2; // getting guitar pick location
if (model.rangeState.startDate) {
- startLocation = self.getLocationFromStringDate(model.rangeState.startDate);
+ startLocation = self.getLocationFromStringDate(
+ model.rangeState.startDate
+ );
endLocation = self.getLocationFromStringDate(model.rangeState.endDate);
} else {
startLocation = animEndLocation - 100;
@@ -112,10 +112,12 @@ export function animationRangeSelect(models, config, ui) {
* @returns {number} OffsetX
*
*/
- self.getHeaderOffset = function () {
- return $header.width() + Number($timeline.css('left')
- .replace('px', '')) + Number($footer.css('margin-left')
- .replace('px', ''));
+ self.getHeaderOffset = function() {
+ return (
+ $header.width() +
+ Number($timeline.css('left').replace('px', '')) +
+ Number($footer.css('margin-left').replace('px', ''))
+ );
};
/*
@@ -129,7 +131,7 @@ export function animationRangeSelect(models, config, ui) {
* @returns {number} OffsetX
*
*/
- self.getLocationFromStringDate = function (date) {
+ self.getLocationFromStringDate = function(date) {
return timeline.x(util.roundTimeTenMinute(date));
};
@@ -143,7 +145,8 @@ export function animationRangeSelect(models, config, ui) {
* @returns {void}
*
*/
- self.update = function () { // being called from timeline.config.js
+ self.update = function() {
+ // being called from timeline.config.js
var props = self.updateOptions();
self.reactComponent.setState(props);
};
@@ -157,7 +160,7 @@ export function animationRangeSelect(models, config, ui) {
* @returns {number} max width
*
*/
- self.getMaxWidth = function () {
+ self.getMaxWidth = function() {
var $elWidth = $footer.width();
var $dataWidth = timeline.x(timeline.data.end());
if ($elWidth > $dataWidth) {
@@ -175,7 +178,7 @@ export function animationRangeSelect(models, config, ui) {
* @returns {object} props
*
*/
- self.updateOptions = function () {
+ self.updateOptions = function() {
var state = model.rangeState;
var props = {};
props.startLocation = self.getLocationFromStringDate(state.startDate);
@@ -198,9 +201,9 @@ export function animationRangeSelect(models, config, ui) {
* @returns {object} props
*
*/
- self.onRangeClick = function (e) {
+ self.onRangeClick = function(e) {
var headerOffset = self.getHeaderOffset();
- var offsetX = (e.pageX - headerOffset);
+ var offsetX = e.pageX - headerOffset;
var date = timeline.x.invert(offsetX);
models.date.select(date);
};
@@ -218,7 +221,7 @@ export function animationRangeSelect(models, config, ui) {
* @returns {object} props
*
*/
- self.updateRange = function (startLocation, EndLocation) {
+ self.updateRange = function(startLocation, EndLocation) {
var startDate = util.roundTimeTenMinute(timeline.x.invert(startLocation));
var endDate = util.roundTimeTenMinute(timeline.x.invert(EndLocation));
var state = model.rangeState;
@@ -230,4 +233,4 @@ export function animationRangeSelect(models, config, ui) {
};
self.init();
return self;
-};
+}
diff --git a/web/js/animation/widget.js b/web/js/animation/widget.js
index a8c70a213..8e059ba8a 100644
--- a/web/js/animation/widget.js
+++ b/web/js/animation/widget.js
@@ -6,7 +6,7 @@ import lodashWithout from 'lodash/without';
import lodashIndexOf from 'lodash/indexOf';
import util from '../util/util';
-export function animationWidget (models, config, ui) {
+export function animationWidget(models, config, ui) {
var zooms = ['yearly', 'monthly', 'daily', '10-Minute'];
var self = {};
var timeline = ui.timeline;
@@ -25,7 +25,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.init = function () {
+ self.init = function() {
$animateButton = $('#animate-button');
var props = {
@@ -54,53 +54,66 @@ export function animationWidget (models, config, ui) {
$('#wv-animation-widet-case')[0]
);
$timelineFooter = $('#timeline-footer');
- $animateButton.on('click', function () {
+ $animateButton.on('click', function() {
googleAnalytics.event('Animation', 'Click', 'Animation Icon');
self.toggleAnimationWidget();
});
- if (model.rangeState.state === 'on') { // show animation widget if active in permalink
+ if (model.rangeState.state === 'on') {
+ // show animation widget if active in permalink
$timelineFooter.toggleClass('wv-anim-active');
}
- $('.wv-date-selector-widget input')
- .on('keydown', function (e) {
- // A bit of a hack
- e.stopPropagation(); // needed to correct event bubbling between react and Document
- });
+ $('.wv-date-selector-widget input').on('keydown', function(e) {
+ // A bit of a hack
+ e.stopPropagation(); // needed to correct event bubbling between react and Document
+ });
model.events.trigger('change');
model.events.on('change', self.update);
models.date.events.on('timeline-change', self.update);
if (models.data) {
dataModel = models.data;
- dataModel.events.on('activate', function () {
+ dataModel.events.on('activate', function() {
self.toggleAnimationWidget();
- self.onDataActivate();
+ self.disableButton('Data Download');
});
- dataModel.events.on('deactivate', function () {
- self.onDataDeactivate();
+ dataModel.events.on('deactivate', function() {
+ self.enableButton();
});
} else {
dataModel = {};
dataModel.active = false;
}
-
- // hack for react bug https://github.com/facebook/react/issues/1920
- $('.wv-date-selector-widget input')
- .keydown(function (e) {
- if (e.keyCode === 13 || e.keyCode === 9) {
- e.preventDefault();
+ if (models.compare) {
+ let compareModel = models.compare;
+ if (compareModel.active) {
+ self.disableButton('Compare');
+ }
+ compareModel.events.on('toggle', () => {
+ if (compareModel.active) {
+ if (model.rangeState.state === 'on') self.toggleAnimationWidget();
+ self.disableButton('Compare');
+ } else {
+ self.enableButton();
}
});
+ }
+
+ // hack for react bug https://github.com/facebook/react/issues/1920
+ $('.wv-date-selector-widget input').keydown(function(e) {
+ if (e.keyCode === 13 || e.keyCode === 9) {
+ e.preventDefault();
+ }
+ });
// Space bar event listener
- $(window)
- .keypress(function (e) {
- if ((e.keyCode === 32 ||
- e.charCode === 32) && // space click
- !$('#layer-modal')
- .dialog('isOpen')) { // layer selector is not open
- e.preventDefault();
- self.onSpaceBar();
- }
- });
+ $(window).keypress(function(e) {
+ if (
+ (e.keyCode === 32 || e.charCode === 32) && // space click
+ !$('#layer-modal').dialog('isOpen')
+ ) {
+ // layer selector is not open
+ e.preventDefault();
+ self.onSpaceBar();
+ }
+ });
};
/*
@@ -113,7 +126,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onSpaceBar = function () {
+ self.onSpaceBar = function() {
if (model.rangeState.state === 'on') {
if (model.rangeState.playing) {
self.onPressPause();
@@ -134,7 +147,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.update = function () {
+ self.update = function() {
var state = model.rangeState;
self.reactComponent.setState({
startDate: new Date(state.startDate),
@@ -155,7 +168,7 @@ export function animationWidget (models, config, ui) {
* @returns {string} timeline interval
*
*/
- self.getIncrements = function () {
+ self.getIncrements = function() {
if (models.date.maxZoom > 3) {
zooms = ['yearly', 'monthly', 'daily', '10-Minute'];
} else {
@@ -178,7 +191,7 @@ export function animationWidget (models, config, ui) {
* @returns {string} timeline interval
*
*/
- self.onZoomSelect = function (increment) {
+ self.onZoomSelect = function(increment) {
var zoomLevel = lodashIndexOf(zooms, increment);
return timeline.config.zoom(zoomLevel + 1);
};
@@ -197,7 +210,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.dateUpdate = function (startDate, endDate) {
+ self.dateUpdate = function(startDate, endDate) {
model.rangeState.startDate = util.toISOStringSeconds(startDate) || 0;
model.rangeState.endDate = util.toISOStringSeconds(endDate);
model.rangeState.playing = false;
@@ -215,20 +228,22 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.toggleAnimationWidget = function () {
+ self.toggleAnimationWidget = function() {
// If timeline is hidden, pressing
// the anim icon will open the
// timeline and the anim widget
- if (model.rangeState.state === null) { // widget hasn't been clicked before
+ if (model.rangeState.state === null) {
+ // widget hasn't been clicked before
model.rangeState.state = 'off';
self.makeDateGuess();
}
if ($timelineFooter.is(':hidden') && !dataModel.active) {
ui.timeline.toggle(); // toggle
- if (model.rangeState.state === 'on') { // activate anim if not already
+ if (model.rangeState.state === 'on') {
+ // activate anim if not already
return;
}
- setTimeout(function () {
+ setTimeout(function() {
model.events.trigger('change');
model.events.trigger('toggle-widget');
}, 500);
@@ -243,12 +258,13 @@ export function animationWidget (models, config, ui) {
return $timelineFooter.toggleClass('wv-anim-active');
};
- self.makeDateGuess = function () {
+ self.makeDateGuess = function() {
var day, intervalStep;
var today = new Date();
- var currentDate = new Date(models.date.selected);
+ var dateModel = models.date;
+ var currentDate = new Date(dateModel[dateModel.activeDate]);
var interval = ui.anim.ui.getInterval();
- if (models.date.selectedZoom === 4) {
+ if (dateModel.selectedZoom === 4) {
intervalStep = 70;
} else {
intervalStep = 7;
@@ -256,10 +272,14 @@ export function animationWidget (models, config, ui) {
day = util.dateAdd(currentDate, interval, intervalStep);
if (day > today) {
model.rangeState.endDate = util.toISOStringSeconds(currentDate);
- model.rangeState.startDate = util.toISOStringSeconds(util.dateAdd(currentDate, interval, -(intervalStep)));
+ model.rangeState.startDate = util.toISOStringSeconds(
+ util.dateAdd(currentDate, interval, -intervalStep)
+ );
} else {
model.rangeState.startDate = util.toISOStringSeconds(currentDate);
- model.rangeState.endDate = util.toISOStringSeconds(util.dateAdd(currentDate, interval, intervalStep));
+ model.rangeState.endDate = util.toISOStringSeconds(
+ util.dateAdd(currentDate, interval, intervalStep)
+ );
}
};
@@ -272,7 +292,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onPressPlay = function () {
+ self.onPressPlay = function() {
let zoomLevel = ui.anim.ui.getInterval();
if (zoomLevel !== 'minute') {
// zero out start/end date times
@@ -295,7 +315,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onRateChange = function (speed) {
+ self.onRateChange = function(speed) {
model.rangeState.speed = speed;
model.events.trigger('change');
};
@@ -310,7 +330,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onPressPause = function () {
+ self.onPressPause = function() {
var state = model.rangeState;
state.playing = false;
model.events.trigger('change');
@@ -327,9 +347,14 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onDataActivate = function () {
+ self.disableButton = function(featureThatIsDisabling) {
$animateButton.addClass('wv-disabled-button');
- $animateButton.prop('title', 'Animation feature is deactivated when data download feature is active');
+ $animateButton.prop(
+ 'title',
+ 'Animation feature is deactivated when ' +
+ featureThatIsDisabling +
+ ' feature is active'
+ );
};
/*
@@ -343,7 +368,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onDataDeactivate = function () {
+ self.enableButton = function() {
$animateButton.removeClass('wv-disabled-button');
$animateButton.prop('title', 'Set up animation');
};
@@ -360,7 +385,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onPressLoop = function (loop) {
+ self.onPressLoop = function(loop) {
var state = model.rangeState;
state.loop = loop;
model.events.trigger('change');
@@ -377,7 +402,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.onPressGIF = function () {
+ self.onPressGIF = function() {
let zoomLevel = ui.anim.ui.getInterval();
if (zoomLevel !== 'minute') {
// zero out start/end date times
@@ -400,7 +425,7 @@ export function animationWidget (models, config, ui) {
* @returns {void}
*
*/
- self.setZeroDateTimes = function () {
+ self.setZeroDateTimes = function() {
let state = model.rangeState;
let startDate = util.parseDateUTC(state.startDate);
let endDate = util.parseDateUTC(state.endDate);
@@ -416,4 +441,4 @@ export function animationWidget (models, config, ui) {
self.init();
return self;
-};
+}