Interactive interface for browsing global, full-resolution satellite imagery
Add + or - 1 day to dateline toolbar A|B #1246
Benjamin King91a691df15a1
diff --git a/web/js/components/dateline/text.js b/web/js/components/dateline/text.jsindex 66e2b9ba4..732bf12d7 100644--- a/web/js/components/dateline/text.js+++ b/web/js/components/dateline/text.js@@ -1,5 +1,7 @@import React from 'react';import PropTypes from 'prop-types';+import util from '../../util/util';+/** Builds an SVG text box*@@ -20,38 +22,65 @@ class LineText extends React.Component {}render() {+ const leftTextWidth =+ Math.round(+ util.getTextWidth(this.state.dateLeft, '13px Open Sans') * 100+ ) / 100 || this.props.textWidth;+ const rightTextWidth =+ Math.round(+ util.getTextWidth(this.state.dateRight, '13px Open Sans') * 100+ ) / 100 || this.props.textWidth;+ const svgStyle = {+ transform: 'translateX(' + -(leftTextWidth + 20) + 'px)'+ };return (- <svg className="dateline-text" style={this.props.svgStyle}>+ <svg className="dateline-text" style={svgStyle}><rectfill={this.props.fill}- width={this.props.textWidth}+ width={leftTextWidth + 10}height={this.props.textHeight}- x={this.props.x1}+ x={0}rx={this.props.recRadius}- opacity={this.state.active ? this.props.rectOpacity : '0'}+ opacity={+ this.state.active && this.state.dateLeft+ ? this.props.rectOpacity+ : '0'+ }/><texty={this.props.textY}- x={this.props.x1 + 6}+ x={6}fill={this.props.color}width={this.props.width}- opacity={this.state.active ? this.props.textOpacity : '0'}+ opacity={+ this.state.active && this.state.dateLeft+ ? this.props.textOpacity+ : '0'+ }>{this.state.dateLeft}</text><rectfill={this.props.fill}- width={this.props.textWidth}+ width={rightTextWidth + 10}height={this.props.textHeight}- x={this.props.x2}+ x={leftTextWidth + 40}rx={this.props.recRadius}- opacity={this.state.active ? this.props.rectOpacity : '0'}+ opacity={+ this.state.active && this.state.dateRight+ ? this.props.rectOpacity+ : '0'+ }/><texty={this.props.textY}- x={this.props.x2 + 6}+ x={leftTextWidth + 46}fill={this.props.color}- opacity={this.state.active ? this.props.textOpacity : '0'}+ opacity={+ this.state.active && this.state.dateRight+ ? this.props.textOpacity+ : '0'+ }>{this.state.dateRight}</text>diff --git a/web/js/map/datelinebuilder.js b/web/js/map/datelinebuilder.jsindex 85a682203..a9a16029e 100644--- a/web/js/map/datelinebuilder.js+++ b/web/js/map/datelinebuilder.js@@ -59,16 +59,11 @@ export function mapDateLineBuilder(models, config) {updateLineVisibility(false);});models.date.events.on('select', function() {- updateDate(models.date[models.date.activeDate]);+ updateDate(new Date(models.date[models.date.activeDate]));});if (models.compare) {models.compare.events.on('toggle', function() {- var state = {- isTooltipActive: !(models.compare && models.compare.active)- };- lineRight.setState(state);- lineLeft.setState(state);- updateDate(models.date[models.date.activeDate]);+ updateDate(new Date(models.date[models.date.activeDate]));});}models.proj.events.on('select', function() {@@ -111,8 +106,7 @@ export function mapDateLineBuilder(models, config) {lineOut: onMouseOut,lineX: lineX,overlay: overlay,- tooltip: tooltip,- isTooltipActive: !(models.compare && models.compare.active)+ tooltip: tooltip};var component = ReactDOM.render(React.createElement(ReactComponent, props),@@ -134,17 +128,45 @@ export function mapDateLineBuilder(models, config) {** @returns {object} React Component*/- var setTextDefaults = function(ReactComponent, reactCase, date) {- var props = {- dateLeft: util.toISOStringDate(util.dateAdd(date, 'day', 1)),- dateRight: util.toISOStringDate(date)- };+ var setTextDefaults = function(ReactComponent, reactCase, date, isLeft) {+ const props = getTextState(date, isLeft);return ReactDOM.render(React.createElement(ReactComponent, props),reactCase);};+ /*+ * Add Props to React Compents that creates an+ * SVG text component+ *+ * @method updateTextState+ * @private+ *+ * @param {object} Factory - React component Factory+ * @param {object} reactCase - Dom El in which to render component+ * @param {object} date - JS date object+ * @param {boolean} isLeft - is this on left or right side of map+ *+ * @returns {object} React Component+ */+ var getTextState = function(date, isLeft) {+ const isCompareActive = models.compare && models.compare.active;+ var state = {+ dateLeft: !isCompareActive+ ? util.toISOStringDate(util.dateAdd(date, 'day', 1))+ : isLeft+ ? '+ 1 day'+ : '',+ dateRight: !isCompareActive+ ? util.toISOStringDate(date)+ : isLeft+ ? ''+ : '- 1 day'+ };+ return state;+ };+/** Updates active state of line Components*@@ -192,11 +214,12 @@ export function mapDateLineBuilder(models, config) {map.addOverlay(textOverlay1);map.addOverlay(textOverlay2);- textLeft = setTextDefaults(LineText, leftTextCase, date);+ textLeft = setTextDefaults(LineText, leftTextCase, date, true);textRight = setTextDefaults(LineText,rightTextCase,- util.dateAdd(date, 'day', -1)+ util.dateAdd(date, 'day', -1),+ false);lineLeft = setLineDefaults(DateLine,@@ -266,15 +289,8 @@ export function mapDateLineBuilder(models, config) {* @returns {void}*/var updateDate = function(date) {- var leftState, rightState;- leftState = {- dateLeft: util.toISOStringDate(util.dateAdd(date, 'day', 1)),- dateRight: util.toISOStringDate(date)- };- rightState = {- dateLeft: util.toISOStringDate(date),- dateRight: util.toISOStringDate(util.dateAdd(date, 'day', -1))- };+ const leftState = getTextState(date, true);+ const rightState = getTextState(util.dateAdd(date, 'day', -1), false);textLeft.setState(leftState);textRight.setState(rightState);};