Interactive interface for browsing global, full-resolution satellite imagery
wip
Benjamin Kingffcb0b3fe4ea
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.jsindex 82991bb64..127e0af9d 100644--- a/web/js/containers/animation-widget.js+++ b/web/js/containers/animation-widget.js@@ -20,14 +20,7 @@ import {changeEndDate} from '../modules/animation/actions';-const timeScaleFromNumberKey = {- '0': 'custom',- '1': 'year',- '2': 'month',- '3': 'day',- '4': 'hour',- '5': 'minute'-};+import { timeScaleFromNumberKey } from '../modules/date/constants';const RangeHandle = props => {const { value, offset, dragging, ...restProps } = props;diff --git a/web/js/components/timeline/timeline.js b/web/js/containers/timeline/timeline.jssimilarity index 63%rename from web/js/components/timeline/timeline.jsrename to web/js/containers/timeline/timeline.jsindex 5d8fb5867..e57eb25cd 100644--- a/web/js/components/timeline/timeline.js+++ b/web/js/containers/timeline/timeline.js@@ -13,31 +13,23 @@ import DateChangeArrows from './timeline-controls/date-change-arrows';import AnimationButton from './timeline-controls/animation-button';import AxisTimeScaleChange from './timeline-controls/axis-timescale-change';+import {+ hasSubDaily,+ lastDate as layersLastDate+} from 'modules/layers/selectors';+import { addDate } from 'modules/date/selectors';+import {+ timeScaleToNumberKey,+ timeScaleFromNumberKey+} from 'modules/layers/constants';-// const timeUnitAbbreviations = {-// year: 'year',-// month: 'mon',-// day: 'day',-// hour: 'hour',-// minute: 'min'-// };--const timeScaleFromNumberKey = {- '0': 'custom',- '1': 'year',- '2': 'month',- '3': 'day',- '4': 'hour',- '5': 'minute'-};+const ANIMATION_DELAY = 500;-const timeScaleToNumberKey = {- custom: '0',- year: '1',- month: '2',- day: '3',- hour: '4',- minute: '5'+const MARGIN = {+ top: 0,+ right: 50,+ bottom: 20,+ left: 30};class Timeline extends React.Component {@@ -65,14 +57,62 @@ class Timeline extends React.Component {timelineStartDateLimit: '',timelineEndDateLimit: '',leftArrowDisabled: '',- rightArrowDisabled: ''+ rightArrowDisabled: '',+ animationInProcess: false};+ this.animator = 0;+ }+ /**+ * Clear animateByIncrement's Timeout+ *+ * @return {void}+ */+ stopper() {+ if (this.state.animationInProcess) {+ setState({+ animationInProcess: false+ });+ clearInterval(this.animator);+ this.animator = 0;+ }+ }+ /**+ * Add timeout to date change when buttons are being held so that+ * date changes don't happen too quickly+ *+ * @todo Create smart precaching so animation is smooth+ *+ * @param {number} delta Amount of time to change+ * @param {String} increment Zoom level of timeline+ * e.g. months,minutes, years, days+ * @return {void}+ */+ animateByIncrement(delta, increment) {+ const { endTime, startDate, selectedDate } = this.props;+ const animationInProcess = this.state.animationInProcess;+ function animate() {+ var nextTime = getNextTimeSelection(delta, increment);+ if (subdaily) {+ // can we remove this logic?+ if (startDate <= nextTime && nextTime <= endTime) {+ changeDate(util.dateAdd(selectedDate, increment, delta));+ }+ } else {+ if (startDate <= nextTime && nextTime <= endTime) {+ changeDate(util.dateAdd(selectedDate, increment, delta));+ }+ }+ setState({+ animationInProcess: true+ });+ this.animator = setTimeout(animate, ANIMATION_DELAY);+ }+ animate();}- updateDate = (date, selectionStr) => {- // console.log(date,selectionStr)- this.props.updateDate(date, selectionStr);- };+ updateDate(date) {+ this.props.changeDate(date);+ }// show/hide custom interval modaltoggleCustomIntervalModal = () => {@@ -117,7 +157,7 @@ class Timeline extends React.Component {// left/right arrows increment dateincrementDate = multiplier => {let delta = this.state.customSelected ? this.state.intervalChangeAmt : 1;- this.props.incrementDate(+ this.animateByIncrement(Number(delta * multiplier),this.state.timeScaleChangeUnit);@@ -259,7 +299,6 @@ class Timeline extends React.Component {}render() {- // console.log(this.state.selectedDate, this.state.dateFormatted)return this.state.dateFormatted ? (<React.Fragment><div@@ -270,10 +309,10 @@ class Timeline extends React.Component {<DateSelector{...this.props}onDateChange={this.updateDate}- date={new Date(this.state.dateFormatted)}- dateB={new Date(this.state.dateFormattedB)}- hasSubdailyLayers={this.state.hasSubdailyLayers}- draggerSelected={this.state.draggerSelected}+ date={new Date(dateFormatted)}+ dateB={new Date(dateFormattedB)}+ hasSubdailyLayers={hasSubdailyLayers}+ draggerSelected={draggerSelected}/></div><div id="zoom-buttons-group">@@ -282,17 +321,17 @@ class Timeline extends React.Component {this.setTimeScaleIntervalChangeUnit}customIntervalZoomLevel={this.state.customIntervalZoomLevel}- customSelected={this.state.customSelected}- customIntervalValue={this.state.customIntervalValue}+ customSelected={customSelected}+ customIntervalValue={customIntervalValue}timeScaleChangeUnit={this.state.timeScaleChangeUnit}/><DateChangeArrowsleftArrowDown={() => this.incrementDate(-1)}- leftArrowUp={this.props.stopper}+ leftArrowUp={this.stopper}leftArrowDisabled={this.state.leftArrowDisabled}rightArrowDown={() => this.incrementDate(1)}- rightArrowUp={this.props.stopper}+ rightArrowUp={stopper}rightArrowDisabled={this.state.rightArrowDisabled}/></div>@@ -304,11 +343,11 @@ class Timeline extends React.Component {{/* Timeline */}<TimelineAxis{...this.state}- axisWidth={this.state.axisWidth}- selectedDate={this.state.dateFormatted}- selectedDateB={this.state.dateFormattedB}+ axisWidth={axisWidth}+ selectedDate={dateFormatted}+ selectedDateB={dateFormattedB}updateDate={this.updateDate}- hasSubdailyLayers={this.state.hasSubdailyLayers}+ hasSubdailyLayers={hasSubdailyLayers}parentOffset={this.state.parentOffset}changeTimeScale={this.changeTimeScale}compareModeActive={this.state.compareModeActive}@@ -325,12 +364,12 @@ class Timeline extends React.Component {{/* custom interval selector */}<CustomIntervalSelectorWidget- customIntervalValue={this.state.customIntervalValue}- customIntervalZoomLevel={this.state.customIntervalZoomLevel}+ customIntervalValue={customIntervalValue}+ customIntervalZoomLevel={customIntervalZoomLevel}toggleCustomIntervalModal={this.toggleCustomIntervalModal}customIntervalModalOpen={this.state.customIntervalModalOpen}setIntervalChangeUnit={this.setIntervalChangeUnit}- hasSubdailyLayers={this.state.hasSubdailyLayers}+ hasSubdailyLayers={hasSubdailyLayers}/></div>@@ -365,13 +404,117 @@ class Timeline extends React.Component {) : null;}}-// Timeline.defaultProps = {-// };-// Timeline.propTypes = {-// width: PropTypes.number,-// drawContainers: PropTypes.func,-// changeDate: PropTypes.func,-// selectedDate: PropTypes.instanceOf(Date)-// };--export default Timeline;+function mapStateToProps(state) {+ const { config, compare, layers, browser, date } = state;+ const {+ customSelected,+ selected,+ selectedB,+ zoomLevel,+ interval,+ customInterval+ } = date;+ const { screenWidth } = browser;+ const { isCompareA, active } = compare;+ const compareModeActive = active;+ let hasSubdailyLayers = hasSubDaily(layers[compare.activeString]);++ if (isCompareModeActive) {+ hasSubdailyLayers =+ hasSubDaily(layers['active']) || hasSubDaily(layers['activeB']);+ endTime = getEndTime(layers, config);+ } else {+ hasSubdailyLayers = hasSubDaily(layers[compare.activeString]);+ endTime = layersLastDateTime(activeLayers, config);+ }+ const dimensionsAndOffsetValues = getOffsetValues(screenWidth, hasSubDaily);+ const timelineEndDateLimit = endTime.toISOString();++ return {+ hasSubdailyLayers,+ customSelected,+ compareModeActive,+ dateFormatted: selected.toISOString(),+ dateFormattedB: selectedB.toISOString(),+ startDate: config.startDate,+ timelineStartDateLimit: config.startDate, // same as startDate+ endTime,+ isAnimationWidgetOpen: animation.active,+ axisWidth: dimensionsAndOffsetValues.width,+ selectedDate: isCompareA ? selected : selectedB,+ timeScale: timeScaleFromNumberKey[selectedZoom],+ timeScaleChangeUnit: customSelected+ ? timeScaleFromNumberKey[customInterval]+ : timeScaleFromNumberKey[interval],+ customIntervalValue: customDelta,+ customIntervalZoomLevel: customInterval,+ intervalChangeAmt: interval,+ parentOffset: dimensionsAndOffsetValues.parentOffset,+ timelineEndDateLimit+ };+}++const mapDispatchToProps = dispatch => ({+ changeDate: val => {+ dispatch(selectDate(val));+ }+});++export default connect(+ mapStateToProps,+ mapDispatchToProps+)(Timeline);++Timeline.propTypes = {+ proj: PropTypes.object.isRequired,+ map: PropTypes.object.isRequired,+ models: PropTypes.object.isRequired,+ url: PropTypes.string.isRequired,+ onClose: PropTypes.func.isRequired,+ screenWidth: PropTypes.number,+ screenHeight: PropTypes.number+};++function getOffsetValues(innerWidth, hasSubDaily) {+ const parentOffset = (hasSubDaily ? 414 : 310) + 10;++ const width =+ innerWidth - parentOffset - 20 - 20 - MARGIN.left - MARGIN.right + 28;+ return { width, parentOffset };+}++function getEndTime(layers, config) {+ const endDateA = layersLastDateTime(layers['active'], config);+ const endDateB = layersLastDateTime(layers['activeB'], config);+ return endDateA > endDateB ? endDateA : endDateB;+}+/**+ * @param {Number} delta Date and direction to change+ * @param {Number} increment Zoom level of change+ * e.g. months,minutes, years, days+ * @return {Object} JS Date Object+ */+var getNextTimeSelection = function(delta, increment, prevDate) {+ switch (increment) {+ case 'year':+ return new Date(+ new Date(prevDate).setUTCFullYear(prevDate.getUTCFullYear() + delta)+ );+ case 'month':+ return new Date(+ new Date(prevDate).setUTCMonth(prevDate.getUTCMonth() + delta)+ );+ case 'day':+ return new Date(+ new Date(prevDate).setUTCDate(prevDate.getUTCDate() + delta)+ );+ case 'hour':+ return new Date(+ new Date(prevDate).setUTCHours(prevDate.getUTCHours() + delta)+ );+ case 'minute':+ return new Date(+ new Date(prevDate).setUTCMinutes(prevDate.getUTCMinutes() + delta)+ );+ }+};diff --git a/web/js/modules/date/actions.js b/web/js/modules/date/actions.jsindex fb0df01a0..4717f8d71 100644--- a/web/js/modules/date/actions.js+++ b/web/js/modules/date/actions.js@@ -1,7 +1,8 @@import {UPDATE_ZOOM_LEVEL,CUSTOM_INTERVAL_CHANGE,- INTERVAL_CHANGE+ INTERVAL_CHANGE,+ SELECT_DATE} from './constants';export function updateZoomLevel(num) {@@ -10,10 +11,23 @@ export function updateZoomLevel(num) {value: num};}-export function customIntervalChange(value) {+export function selectDate(value) {+ return (dispatch, getState) => {+ const compareState = getState().compare;+ const activeString = compareState.isCompareA ? 'selected' : 'selectedB';++ dispatch({+ type: SELECT_DATE,+ activeString,+ value+ });+ };+}+export function customIntervalChange(delta, customInterval) {return {type: CUSTOM_INTERVAL_CHANGE,- value+ customInterval,+ value: delta};}export function intervalChange(value) {diff --git a/web/js/modules/date/constants.js b/web/js/modules/date/constants.jsindex e69de29bb..e3e57a16c 100644--- a/web/js/modules/date/constants.js+++ b/web/js/modules/date/constants.js@@ -0,0 +1,22 @@+export const UPDATE_ZOOM_LEVEL = 'DATE/UPDATE_ZOOM_LEVEL';+export const CUSTOM_INTERVAL_CHANGE = 'DATE/CUSTOM_INTERVAL_CHANGE';+export const INTERVAL_CHANGE = 'DATE/INTERVAL_CHANGE';+export const SELECT_DATE = 'DATE/SELECT_DATE';++export const timeScaleFromNumberKey = {+ '0': 'custom',+ '1': 'year',+ '2': 'month',+ '3': 'day',+ '4': 'hour',+ '5': 'minute'+};++export const timeScaleToNumberKey = {+ custom: '0',+ year: '1',+ month: '2',+ day: '3',+ hour: '4',+ minute: '5'+};diff --git a/web/js/modules/date/reducers.js b/web/js/modules/date/reducers.jsindex 019385605..45ab7ea68 100644--- a/web/js/modules/date/reducers.js+++ b/web/js/modules/date/reducers.js@@ -1,31 +1,41 @@import {UPDATE_ZOOM_LEVEL,CUSTOM_INTERVAL_CHANGE,- INTERVAL_CHANGE+ INTERVAL_CHANGE,+ SELECT_DATE} from './constants';+import util from '../../util/util';import { assign as lodashAssign } from 'lodash';const defaultState = {- isCustomInterval: false,- zoomLevel: 3,- increment: 1+ selectedZoom: 3,+ interval: 1,+ selected: util.now(),+ selectedB: util.dateAdd(),+ customSelected: false,+ customDelta: null,+ customInterval: null};export function timelineReducer(state = defaultState, action) {switch (action.type) {case UPDATE_ZOOM_LEVEL:return lodashAssign({}, state, {- zoomLevel: action.value+ selectedZoom: action.value});case CUSTOM_INTERVAL_CHANGE:return lodashAssign({}, state, {customIncrement: action.value,- isCustomInterval: true+ customSelected: true});case INTERVAL_CHANGE:return lodashAssign({}, state, {- increment: action.value,- isCustomInterval: false+ interval: action.value,+ customSelected: false+ });+ case SELECT_DATE:+ return lodashAssign({}, state, {+ [action.activeString]: action.value});default:return state;diff --git a/web/js/modules/date/selectors.js b/web/js/modules/date/selectors.jsnew file mode 100644index 000000000..dd453f056--- /dev/null+++ b/web/js/modules/date/selectors.js@@ -0,0 +1,5 @@+import util from '../../util/util';++export function addDate(interval, amount, activeDate) {+ return util.dateAdd(activeDate, interval, amount);+}diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.jsindex 6b8315ff6..d7c736537 100644--- a/web/js/modules/layers/reducers.js+++ b/web/js/modules/layers/reducers.js@@ -67,7 +67,6 @@ export function layerReducer(state = initialState, action) {let layerIndex = lodashFindIndex(state[layerGroupStr], {id: action.layerId});- console.log(layerGroupStr, layerIndex);return update(state, {[layerGroupStr]: {[layerIndex]: {diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.jsindex 6e045146a..bcd3bbc7e 100644--- a/web/js/modules/layers/selectors.js+++ b/web/js/modules/layers/selectors.js@@ -401,6 +401,31 @@ export function isRenderable(id, activeLayers, date, state) {);return !obscured;}++export function lastDate(activeLayers, config) {+ var endDate;+ var layersDateRange = dateRange({}, activeLayers, config);+ var today = util.today();+ if (layersDateRange && layersDateRange.end > today) {+ endDate = layersDateRange.end;+ } else {+ endDate = today;+ }+ return endDate;+}++export function lastDateTime(activeLayers, config) {+ var endDate;+ var layersDateRange = dateRange({}, activeLayers, config);+ var now = util.now();+ if (layersDateRange && layersDateRange.end > now) {+ endDate = layersDateRange.end;+ } else {+ endDate = now;+ }+ return endDate;+}+export function getZotsForActiveLayers(config, models, ui) {// var zotObj = {};// var sources = config.sources;