Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Constrain timeline drag to 10-min interval, add roundTimeTenMinute util - create roundTimeTenMinute utility method to round UTC dates to nearest 10 minute - Constrain the timeline pick change event to 10 minute intervals - Create check for keyup / keydown events and roll the date by 10 minutes - Add 10-minute constraint when updating the animation range picks - Make utility functions human readable

ZachTRiceea7a729adfdc
diff --git a/web/index.html b/web/index.html
index bb33d573b..894a737d8 100644
--- a/web/index.html
+++ b/web/index.html
@@ -78,7 +78,7 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (http://opensource.gs
<path d="M 12.5,0 25,8 0,8 z" class="uparrow"></path>
</svg>
</div>
- <input type="text" size="4" maxlength="4" class="button-input-group" id="year-input-group" tabindex="2" />
+ <input type="text" size="4" maxlength="4" class="button-input-group 1-interval-group" id="year-input-group" tabindex="2" />
<div class="date-arrows date-arrow-down" data-interval="year" data-value="-1">
<svg width="25" height="8">
<path d="M 12.5,0 25,8 0,8 z" class="downarrow"></path>
@@ -92,7 +92,7 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (http://opensource.gs
<path d="M 12.5,0 25,8 0,8 z" class="uparrow"></path>
</svg>
</div>
- <input type="text" size="3" maxlength="3" class="button-input-group" id="month-input-group" tabindex="3" />
+ <input type="text" size="3" maxlength="3" class="button-input-group 1-interval-group" id="month-input-group" tabindex="3" />
<div class="date-arrows date-arrow-down" data-interval="month" data-value="-1">
<svg width="25" height="8">
<path d="M 12.5,0 25,8 0,8 z" class="downarrow"></path>
@@ -106,7 +106,7 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (http://opensource.gs
<path d="M 12.5,0 25,8 0,8 z" class="uparrow"></path>
</svg>
</div>
- <input type="text" size="2" maxlength="2" class="button-input-group" id="day-input-group" tabindex="4" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.keyCode == 13 || event.keyCode == 9 || even.keyCode == 8" />
+ <input type="text" size="2" maxlength="2" class="button-input-group 1-interval-group" id="day-input-group" tabindex="4" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.keyCode == 13 || event.keyCode == 9 || even.keyCode == 8" />
<div class="date-arrows date-arrow-down" data-interval="day" data-value="-1">
<svg width="25" height="8">
<path d="M 12.5,0 25,8 0,8 z" class="downarrow"></path>
@@ -120,7 +120,7 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (http://opensource.gs
<path d="M 12.5,0 25,8 0,8 z" class="uparrow"></path>
</svg>
</div>
- <input type="text" size="2" maxlength="2" class="button-input-group" id="hour-input-group" tabindex="5" />
+ <input type="text" size="2" maxlength="2" class="button-input-group 1-interval-group" id="hour-input-group" tabindex="5" />
<div class="date-arrows date-arrow-down" data-interval="hour" data-value="-1">
<svg width="25" height="8">
<path d="M 12.5,0 25,8 0,8 z" class="downarrow"></path>
@@ -134,7 +134,7 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (http://opensource.gs
<path d="M 12.5,0 25,8 0,8 z" class="uparrow"></path>
</svg>
</div>
- <input type="text" size="2" maxlength="2" step="10" class="button-input-group" id="minute-input-group" tabindex="6" />
+ <input type="text" size="2" maxlength="2" step="10" class="button-input-group 10-interval-group" id="minute-input-group" tabindex="6" />
<div class="date-arrows date-arrow-down" data-interval="minute" data-value="-10">
<svg width="25" height="8">
<path d="M 12.5,0 25,8 0,8 z" class="downarrow"></path>
diff --git a/web/js/animation/anim.js b/web/js/animation/anim.js
index 91a42438f..a0d2f770d 100644
--- a/web/js/animation/anim.js
+++ b/web/js/animation/anim.js
@@ -8,14 +8,14 @@ export function parse (state, errors) {
};
// Get text before (
- var on = str.match(/[^\(,]+/)[0];
+ var on = str.match(/[^(,]+/)[0];
if (on !== 'on') { // don't do anything if wrong format
state.a = undefined;
return;
}
// remove (, get key value pairs
- str = str.match(/\(.*\)/)[0].replace(/[\(\)]/g, '');
+ str = str.match(/\(.*\)/)[0].replace(/[()]/g, '');
var kvps = str.split(',');
lodashEach(kvps, function (kvp) {
var parts = kvp.split('=');
diff --git a/web/js/animation/range-select.js b/web/js/animation/range-select.js
index bc03fe1f9..5e70c3154 100644
--- a/web/js/animation/range-select.js
+++ b/web/js/animation/range-select.js
@@ -130,7 +130,7 @@ export function animationRangeSelect(models, config, ui) {
*
*/
self.getLocationFromStringDate = function (date) {
- return timeline.x(new Date(date));
+ return timeline.x(util.roundTimeTenMinute(date));
};
/*
diff --git a/web/js/date/config.js b/web/js/date/config.js
index 10efb479e..3f06bd25e 100644
--- a/web/js/date/config.js
+++ b/web/js/date/config.js
@@ -1,5 +1,6 @@
import $ from 'jquery';
import d3 from 'd3';
+import util from '../util/util';
/**
* Modify zoom levels here. Maybe this isnt the best way to do this.
* It could be called just level without the zoom part instead.
@@ -687,15 +688,17 @@ export function timelineConfig(models, config, ui) {
// When the date updates while dragging the pick forward
tl.zoom.current.pick.nextChange = function (d) {
+ d = util.roundTimeTenMinute(d);
return new Date(Date.UTC(d.getUTCFullYear(),
d.getUTCMonth(),
d.getUTCDate(),
d.getUTCHours(),
- d.getUTCMinutes() + 1));
+ d.getUTCMinutes() + 10));
};
// When the date updates while dragging the pick backward
tl.zoom.current.pick.prevChange = function (d) {
+ d = util.roundTimeTenMinute(d);
return new Date(Date.UTC(d.getUTCFullYear(),
d.getUTCMonth(),
d.getUTCDate(),
diff --git a/web/js/date/timeline-input.js b/web/js/date/timeline-input.js
index e9469f700..de93cb80e 100644
--- a/web/js/date/timeline-input.js
+++ b/web/js/date/timeline-input.js
@@ -442,11 +442,19 @@ export function timelineInput(models, config, ui) {
}
switch (event.keyCode) {
case util.key.LEFT:
- animateReverse('day', -1);
+ if (models.date.selectedZoom === 4) {
+ animateReverse('hour', -1);
+ } else {
+ animateReverse('day', -1);
+ }
event.preventDefault();
break;
case util.key.RIGHT:
- animateForward('day', 1);
+ if (models.date.selectedZoom === 4) {
+ animateReverse('hour', 1);
+ } else {
+ animateReverse('day', 1);
+ }
event.preventDefault();
break;
}
@@ -462,11 +470,15 @@ export function timelineInput(models, config, ui) {
});
// bind click action to interval radio buttons
var $buttons = $('.button-input-group');
+ var $oneIntervalButtons = $('.1-interval-group');
+ var $tenIntervalButtons = $('.10-interval-group');
$buttons.unbind();
+ $oneIntervalButtons.unbind();
+ $tenIntervalButtons.unbind();
// FIXME: Quick fix for fixing the propagation
// of events with arrow keys and input field
- $buttons.keydown(function (event) {
+ $oneIntervalButtons.keydown(function (event) {
var interval = $(this)
.attr('id')
.split('-')[0];
@@ -491,6 +503,33 @@ export function timelineInput(models, config, ui) {
}
});
+ // FIXME: Quick fix for fixing the propagation
+ // of events with arrow keys and input field
+ $tenIntervalButtons.keydown(function (event) {
+ var interval = $(this)
+ .attr('id')
+ .split('-')[0];
+ event.stopPropagation();
+ if (event.keyCode === (util.key.LEFT || util.key.RIGHT)) {
+ event.preventDefault();
+ $(this)
+ .select()
+ .focus();
+ } else if (event.keyCode === (util.key.UP)) {
+ event.preventDefault();
+ roll(interval, 10);
+ $(this)
+ .select()
+ .focus();
+ } else if (event.keyCode === (util.key.DOWN)) {
+ event.preventDefault();
+ roll(interval, -10);
+ $(this)
+ .select()
+ .focus();
+ }
+ });
+
$buttons.on('focus', function (e) {
e.preventDefault();
$buttons.siblings('.date-arrows')
diff --git a/web/js/util/util.js b/web/js/util/util.js
index b3e00dc0c..9879fcb6a 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -249,6 +249,7 @@ export default (function (self) {
var parts = time.split('.')[0].split(':');
return parts[0] + ':' + parts[1];
};
+
/**
* Calculates percent of date between two other dates
*
@@ -262,6 +263,16 @@ export default (function (self) {
self.getDatePercent = function (current, start, end) {
return Math.round((current - start) / (end - start));
};
+
+ self.roundTimeTenMinute = function (time) {
+ var timeToReturn = new Date(time);
+
+ timeToReturn.setMilliseconds(Math.round(timeToReturn.getMilliseconds() / 1000) * 1000);
+ timeToReturn.setSeconds(Math.round(timeToReturn.getSeconds() / 60) * 60);
+ timeToReturn.setMinutes(Math.round(timeToReturn.getMinutes() / 10) * 10);
+ return timeToReturn;
+ };
+
/**
* Sets a date to UTC midnight.
*
@@ -286,6 +297,9 @@ export default (function (self) {
case 'minute':
newDate.setUTCMinutes(newDate.getUTCMinutes() + amount);
break;
+ case 'hour':
+ newDate.setUTCHours(newDate.getUTCHours() + amount);
+ break;
case 'day':
newDate.setUTCDate(newDate.getUTCDate() + amount);
break;
@@ -317,16 +331,16 @@ export default (function (self) {
return i;
};
self.daysInMonth = function (d) {
- var y;
- var m;
+ var year;
+ var month;
if (d.getUTCFullYear) {
- y = d.getUTCFullYear();
- m = d.getUTCMonth();
+ year = d.getUTCFullYear();
+ month = d.getUTCMonth();
} else {
- y = d.year;
- m = d.month;
+ year = d.year;
+ month = d.month;
}
- var lastDay = new Date(Date.UTC(y, m + 1, 0));
+ var lastDay = new Date(Date.UTC(year, month + 1, 0));
return lastDay.getUTCDate();
};
@@ -420,37 +434,37 @@ export default (function (self) {
};
self.rollRange = function (date, interval, minDate, maxDate) {
- var y = date.getUTCFullYear();
- var m = date.getUTCMonth();
+ var year = date.getUTCFullYear();
+ var month = date.getUTCMonth();
var first, last;
switch (interval) {
case 'minute':
- var firstMinute = new Date(Date.UTC(y, m, 1, 0, 0));
- var lastMinute = new Date(Date.UTC(y, m, self.daysInMonth(date), 23, 59));
+ var firstMinute = new Date(Date.UTC(year, month, 1, 0, 0));
+ var lastMinute = new Date(Date.UTC(year, month, self.daysInMonth(date), 23, 59));
first = new Date(Math.max(firstMinute, minDate))
.getUTCMinutes();
last = new Date(Math.min(lastMinute, maxDate))
.getUTCMinutes();
break;
case 'hour':
- var firstHour = new Date(Date.UTC(y, m, 1, 0));
- var lastHour = new Date(Date.UTC(y, m, self.daysInMonth(date), 23));
+ var firstHour = new Date(Date.UTC(year, month, 1, 0));
+ var lastHour = new Date(Date.UTC(year, month, self.daysInMonth(date), 23));
first = new Date(Math.max(firstHour, minDate))
.getUTCHours();
last = new Date(Math.min(lastHour, maxDate))
.getUTCHours();
break;
case 'day':
- var firstDay = new Date(Date.UTC(y, m, 1));
- var lastDay = new Date(Date.UTC(y, m, self.daysInMonth(date)));
+ var firstDay = new Date(Date.UTC(year, month, 1));
+ var lastDay = new Date(Date.UTC(year, month, self.daysInMonth(date)));
first = new Date(Math.max(firstDay, minDate))
.getUTCDate();
last = new Date(Math.min(lastDay, maxDate))
.getUTCDate();
break;
case 'month':
- var firstMonth = new Date(Date.UTC(y, 0, 1));
- var lastMonth = new Date(Date.UTC(y, 11, 31));
+ var firstMonth = new Date(Date.UTC(year, 0, 1));
+ var lastMonth = new Date(Date.UTC(year, 11, 31));
first = new Date(Math.max(firstMonth, minDate))
.getUTCMonth();
last = new Date(Math.min(lastMonth, maxDate))
@@ -623,6 +637,7 @@ export default (function (self) {
parseInt(str.substring(4, 6), 16) + ',' +
parseInt(str.substring(6, 8), 16) + ')';
};
+
self.rgbaToHex = function (r, g, b) {
function hex (c) {
var strHex = c.toString(16);
@@ -630,6 +645,7 @@ export default (function (self) {
}
return hex(r) + hex(g) + hex(b) + 'ff';
};
+
self.hexColorDelta = function (hex1, hex2) {
var r1 = parseInt(hex1.substring(0, 2), 16);
var g1 = parseInt(hex1.substring(2, 4), 16);
@@ -640,6 +656,7 @@ export default (function (self) {
// calculate differences in 3D Space
return Math.sqrt(Math.pow((r1 - r2), 2) + Math.pow((g1 - g2), 2) + Math.pow((b1 - b2), 2));
};
+
/**
* Submits an AJAX request or retreives the result from the cache.
*
@@ -706,6 +723,7 @@ export default (function (self) {
}
};
};
+
/**
* Http request using promises
* http://www.html5rocks.com/en/tutorials/es6/promises/#toc-promisifying-xmlhttprequest
@@ -741,6 +759,7 @@ export default (function (self) {
req.send();
});
};
+
// FIXME: Should be replaced with $.when
self.ajaxJoin = function (calls) {
var completed = 0;
@@ -839,6 +858,7 @@ export default (function (self) {
}
return formatted;
};
+
self.toArray = function (value) {
if (!value) {
return [];