Interactive interface for browsing global, full-resolution satellite imagery
fix currentTransformX update and isdragging issue for refactored animation draggers inside timeline axis, add isdragging logic for componentdidupdate, add widget toggle listener
Edward Platob94ab4beedd4
diff --git a/web/js/components/range-selection/range-selection.js b/web/js/components/range-selection/range-selection.jsindex 3ad186823..9bf02540c 100644--- a/web/js/components/range-selection/range-selection.js+++ b/web/js/components/range-selection/range-selection.js@@ -98,7 +98,7 @@ class TimelineRangeSelector extends React.Component {* @return {void}*/onDragStop() {- this.props.onDrag(this.state.startLocation, this.state.endLocation);+ this.props.onDrag(this.state.startLocation, this.state.endLocation, true);googleTagManager.pushEvent({'event': 'GIF_animation_dragger'});diff --git a/web/js/components/timeline/timeline-axis/timeline-axis.js b/web/js/components/timeline/timeline-axis/timeline-axis.jsindex b8b4094ba..52eb95e27 100644--- a/web/js/components/timeline/timeline-axis/timeline-axis.js+++ b/web/js/components/timeline/timeline-axis/timeline-axis.js@@ -75,22 +75,23 @@ class TimelineAxis extends React.Component {currentTransformX: 0,gridWidth: 100,animationStartLocation: 0,- animationEndLocation: 0+ animationEndLocation: 0,+ isAnimationDraggerDragging: false}}//? how do position and transforms change between scale changes? lock into one line would be idealupdateScale = (inputDate, timeScale, axisWidthInput, leftOffsetFixedCoeff) => {- console.log(inputDate, timeScale, axisWidthInput, leftOffsetFixedCoeff)+ // console.log(inputDate, timeScale, axisWidthInput, leftOffsetFixedCoeff)let maxDateTEMP = moment.utc(new Date());let options = timeScaleOptions[timeScale].timeAxis;let gridWidth = options.gridWidth;let axisWidth = axisWidthInput ? axisWidthInput : this.props.axisWidth;let leftOffset = leftOffsetFixedCoeff ? axisWidth * leftOffsetFixedCoeff : this.state.leftOffset;-// debugger;+ // debugger;if (leftOffset === 0) {leftOffset = axisWidth / 2;}-console.log(leftOffset,axisWidth)+ // console.log(leftOffset,axisWidth)// console.log(leftOffset, this.state.draggerPosition)let numberOfVisibleTiles = Number((axisWidth / gridWidth).toFixed(8));@@ -195,11 +196,11 @@ console.log(leftOffset,axisWidth)if (true || this.props.startLocationDate) {// animationStartLocationDate = moment.utc(this.props.startLocationDate);- animationStartLocationDate = this.state.animationStartLocationDate;+ animationStartLocationDate = this.props.animStartLocationDate;animationStartDraggerLocation = Math.abs(frontDate.diff(animationStartLocationDate, timeScale, true) * gridWidth);// animationEndLocationDate = moment.utc(this.props.endLocationDate);- animationEndLocationDate = this.state.animationEndLocationDate;+ animationEndLocationDate = this.props.animEndLocationDate;animationEndDraggerLocation = Math.abs(frontDate.diff(animationEndLocationDate, timeScale, true) * gridWidth);}@@ -229,8 +230,8 @@ console.log(leftOffset,axisWidth)showHoverLine: false,animationStartLocation: animationStartDraggerLocation + position -pixelsToAdd - 2,animationEndLocation: animationEndDraggerLocation + position -pixelsToAdd - 2,- animationStartLocationDate: animationStartLocationDate,- animationEndLocationDate: animationEndLocationDate+ // animationStartLocationDate: animationStartLocationDate,+ // animationEndLocationDate: animationEndLocationDate})}@@ -657,8 +658,8 @@ console.log(leftOffset,axisWidth)position: midPoint,animationStartLocation: animationStartDraggerLocation + midPoint,animationEndLocation: animationEndDraggerLocation + midPoint,- animationStartLocationDate: animationStartLocationDate,- animationEndLocationDate: animationEndLocationDate+ // animationStartLocationDate: animationStartLocationDate,+ // animationEndLocationDate: animationEndLocationDate})// }, function() {// this.updateScale(time, timeScale, this.props.axisWidth, 0.90)@@ -709,10 +710,12 @@ console.log(leftOffset,axisWidth)componentDidUpdate(prevProps, prevState) {// console.log(prevProps.selectedDate, this.props.selectedDate, this.state.selectedDate, prevState.selectedDate)- // if (this.props.animStartLocationDate !== prevProps.animStartLocationDate ||- // this.props.animEndLocationDate !== prevProps.animEndLocationDate) {- // this.animationDraggerDateUpdate(this.props.animStartLocationDate, this.props.animEndLocationDate)- // }+ if (!this.state.isAnimationDraggerDragging) {+ if (this.props.animStartLocationDate !== prevProps.animStartLocationDate ||+ this.props.animEndLocationDate !== prevProps.animEndLocationDate) {+ this.animationDraggerDateUpdate(this.props.animStartLocationDate, this.props.animEndLocationDate)+ }+ }if (this.props.timeScale !== prevProps.timeScale) {this.updateScale(null, this.props.timeScale);@@ -1052,19 +1055,20 @@ console.log(leftOffset,axisWidth)// }// handle animation dragger drag change- animationDraggerPositionUpdate = (startLocation, endLocation) => {+ animationDraggerPositionUpdate = (startLocation, endLocation, stopDragging) => {+ let isDragging = stopDragging ? false : true;let timeScale = this.props.timeScale;let gridWidth = this.state.gridWidth;// calculate new start and end positionslet deltaXStart = startLocation - this.state.animationStartLocation;- let animationStartLocationDate = this.state.animationStartLocationDate;+ let animationStartLocationDate = this.props.animStartLocationDate;let deltaXEnd = endLocation - this.state.animationEndLocation;- let animationEndLocationDate = this.state.animationEndLocationDate;+ let animationEndLocationDate = this.props.animEndLocationDate;if (deltaXStart !== 0 || deltaXEnd !== 0) {let diffZeroValues = timeScaleOptions[timeScale].timeAxis.scaleMs;// get startDate for diff calculation- let draggerTimeStart = moment.utc(this.state.animationStartLocationDate);+ let draggerTimeStart = moment.utc(this.props.animStartLocationDate);// only need to calculate difference in time unit for varying timescales - month and yearif (!diffZeroValues) {let draggerTimeStartZero = draggerTimeStart.clone().startOf(timeScale);@@ -1078,13 +1082,12 @@ console.log(leftOffset,axisWidth)let diffFactor = diffZeroValues / gridWidth;if (deltaXStart !== 0) { // update new start date- // let draggerTimeStart = moment.utc(this.state.animationStartLocationDate);let draggerTimeStartValue = draggerTimeStart.valueOf();animationStartLocationDate = moment.utc(draggerTimeStartValue + (diffFactor * deltaXStart)).format();}if (deltaXEnd !== 0) { // update new end date- let draggerTimeEnd = moment.utc(this.state.animationEndLocationDate);+ let draggerTimeEnd = moment.utc(this.props.animEndLocationDate);let draggerTimeEndValue = draggerTimeEnd.valueOf();animationEndLocationDate = moment.utc(draggerTimeEndValue + (diffFactor * deltaXEnd)).format();}@@ -1092,10 +1095,9 @@ console.log(leftOffset,axisWidth)// need props function to handle state update?!this.setState({+ isAnimationDraggerDragging: isDragging,animationStartLocation: startLocation,- animationEndLocation: endLocation,- animationStartLocationDate: animationStartLocationDate,- animationEndLocationDate: animationEndLocationDate+ animationEndLocation: endLocation}, function() {this.props.updateAnimationRange(animationStartLocationDate, animationEndLocationDate)})@@ -1113,10 +1115,8 @@ console.log(leftOffset,axisWidth)// console.log(startLocation, endLocation)this.setState({- animationStartLocation: position - startLocation,- animationEndLocation: position - endLocation,- animationStartLocationDate: animationStartLocationDate,- animationEndLocationDate: animationEndLocationDate+ animationStartLocation: position - startLocation + this.state.currentTransformX,+ animationEndLocation: position - endLocation + this.state.currentTransformX})}@@ -1173,25 +1173,28 @@ console.log(leftOffset,axisWidth)</Draggable>{/* //? INSERT RANGE SELECTION HERE */}- {/* <TimelineRangeSelector- startLocation={this.state.animationStartLocation}- endLocation={this.state.animationEndLocation}- startLocationDate={this.state.animationStartLocationDate}- endLocationDate={this.state.animationEndLocationDate}- timelineStartDateLimit={this.props.timelineStartDateLimit}- timelineEndDateLimit={this.props.timelineEndDateLimit}- max={{end: false, start: false, startOffset: -50, width: this.props.axisWidth}}- pinWidth={5}- height={45}- // onDrag={(sx, ex) => console.log('onDrag', sx, ex)}- onDrag={this.animationDraggerPositionUpdate.bind(this)}- onRangeClick={() => console.log('onRangeClick')}- rangeOpacity={0.3}- rangeColor={"#45bdff"}- startColor={"#40a9db"}- startTriangleColor={"#fff"}- endColor={"#295f92"}- endTriangleColor={"#4b7aab"} /> */}+ {this.props.isAnimationWidgetOpen ?+ <TimelineRangeSelector+ startLocation={this.state.animationStartLocation}+ endLocation={this.state.animationEndLocation}+ startLocationDate={this.props.animStartLocationDate}+ endLocationDate={this.props.animEndLocationDate}+ timelineStartDateLimit={this.props.timelineStartDateLimit}+ timelineEndDateLimit={this.props.timelineEndDateLimit}+ max={{end: false, start: false, startOffset: -50, width: this.props.axisWidth}}+ pinWidth={5}+ height={45}+ // onDrag={(sx, ex) => console.log('onDrag', sx, ex)}+ onDrag={this.animationDraggerPositionUpdate.bind(this)}+ onRangeClick={() => console.log('onRangeClick')}+ rangeOpacity={0.3}+ rangeColor={"#45bdff"}+ startColor={"#40a9db"}+ startTriangleColor={"#fff"}+ endColor={"#295f92"}+ endTriangleColor={"#4b7aab"} />+ : null+ }{this.props.draggerSelected === 'selectedB' ?<React.Fragment>diff --git a/web/js/components/timeline/timeline.js b/web/js/components/timeline/timeline.jsindex 0f4eba0c4..45f939538 100644--- a/web/js/components/timeline/timeline.js+++ b/web/js/components/timeline/timeline.js@@ -130,7 +130,8 @@ class Timeline extends React.Component {timelineStartDateLimit: this.props.timelineStartDateLimit,timelineEndDateLimit: this.props.timelineEndDateLimit,animStartLocationDate: this.props.animStartLocationDate,- animEndLocationDate: this.props.animEndLocationDate+ animEndLocationDate: this.props.animEndLocationDate,+ isAnimationWidgetOpen: this.props.isAnimationWidgetOpen});}@@ -209,6 +210,7 @@ class Timeline extends React.Component {updateAnimationRange={this.props.updateAnimationRange}animStartLocationDate={this.state.animStartLocationDate}animEndLocationDate={this.state.animEndLocationDate}+ isAnimationWidgetOpen={this.state.isAnimationWidgetOpen}/></div>diff --git a/web/js/date/timeline.js b/web/js/date/timeline.jsindex 8143dc09b..4f8f73a65 100644--- a/web/js/date/timeline.js+++ b/web/js/date/timeline.js@@ -375,7 +375,6 @@ export function timeline(models, config, ui) {// set custom intervalvar setIntervalInput = (intervalValue, zoomLevel) => {- console.log(intervalValue, zoomLevel)models.date.setCustomInterval(intervalValue, timeScaleToNumberKey[zoomLevel]);let zoomCustomText = document.querySelector('#zoom-custom');zoomCustomText.textContent = `${intervalValue} ${zoomLevel.toUpperCase().substr(0, 3)}`;@@ -391,7 +390,6 @@ export function timeline(models, config, ui) {// set selected interval either custom or standard delta of 1var setSelectedInterval = (interval, intervalChangeAmt, customSelected) => {- console.log(interval, intervalChangeAmt, customSelected)models.date.setSelectedInterval(timeScaleToNumberKey[interval], customSelected);self.reactComponent.setState({timeScaleChangeUnit: interval,@@ -486,8 +484,11 @@ export function timeline(models, config, ui) {// animation dateslet animStartLocationDate = models.anim.rangeState.startDate;let animEndLocationDate = models.anim.rangeState.endDate;+ let isAnimationWidgetOpen = models.anim.rangeState.state === 'on';// console.log(animStartLocationDate, animEndLocationDate)+ console.log(models.anim.rangeState.state)+// get separate input props// TODO: combined props cleaner or too long?let inputProps = getInputProps();@@ -520,7 +521,8 @@ export function timeline(models, config, ui) {customSelected: customSelected,updateAnimationRange: updateAnimationRange,animStartLocationDate: animStartLocationDate,- animEndLocationDate: animEndLocationDate+ animEndLocationDate: animEndLocationDate,+ isAnimationWidgetOpen: isAnimationWidgetOpen};};@@ -655,6 +657,13 @@ export function timeline(models, config, ui) {});};+ var onAnimationWidgetToggle = () => {+ let isAnimationWidgetOpen = models.anim.rangeState.state === 'on';+ self.reactComponent.setState({+ isAnimationWidgetOpen: isAnimationWidgetOpen+ });+ };+var init = function() {var $timelineFooter = $('#timeline-footer');models.layers.events.trigger('toggle-subdaily');@@ -724,7 +733,8 @@ export function timeline(models, config, ui) {models.layers.events.on('change', onLayerUpdate);- // models.anim.events.on('datechange', onAnimationDateChange);+ models.anim.events.on('datechange', onAnimationDateChange);+ models.anim.events.on('toggle-widget', onAnimationWidgetToggle);// Determine maximum end date and move tl pick there if selected date is// greater than the max end date