Interactive interface for browsing global, full-resolution satellite imagery
created a rangeselector class that handles animation adjustments on the slider
Benjamin5fd51e995ee3
diff --git a/web/js/animation/wv.anim.rangeselect.js b/web/js/animation/wv.anim.rangeselect.jsindex f333c3c75..7f7321e77 100644--- a/web/js/animation/wv.anim.rangeselect.js+++ b/web/js/animation/wv.anim.rangeselect.js@@ -16,20 +16,42 @@ var wv = wv || {};wv.anim = wv.anim || {};wv.anim.rangeselect = wv.anim.rangeselect || function(models, config, ui) {- var self = this;+ var self = {};+ var model;var timeline = ui.timeline;+ var widgetOptions = ui.anim.optionsvar rangeSelectionFactory = React.createFactory(Animate.RangeSelector);+ var $mountLocation = $('#wv-rangeselector-case')[0];+ var reactGlobal = {};++ ui.anim.rangeOptions = ui.anim.rangeOptions || {};self.init = function() {+ 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 locationvar ticHeight = $('.end-tick').height();var $animateButton = $('#animate-button');+ var options;++ model = models.anim || {};+ model.rangeState = model.rangeState || {};+ model.rangeState.state = model.rangeState.state || 'on';- var RangeSelection = rangeSelectionFactory({- startLocation: animEndLocation - 100, // or zero- endLocation: animEndLocation,+ if(model.rangeState.startDate) {+ startLocation = self.getLocationFromStringDate(model.rangeState.startDate);+ endLocation = self.getLocationFromStringDate(model.rangeState.endDate);+ } else {+ startLocation = animEndLocation - 100;+ endLocation = animEndLocation+ }++ self.options = {+ startLocation: startLocation, // or zero+ endLocation: endLocation,+ max: timeline.x(timeline.data.end()),startColor: '#40a9db',endColor: '#295f92',rangeColor: '#45bdff',@@ -38,19 +60,42 @@ wv.anim.rangeselect = wv.anim.rangeselect || function(models, config, ui) {height: 45,onDrag: self.showDateOnDrag,onDragStop: self.updateRange- });- //mount react components- ReactDOM.render(RangeSelection, $('#wv-rangeselector-case')[0]);+ };+ model.events.on('timeline-change', self.update)+ self.render(self.options);};+ self.render = function(options) {+ self.reactComponent = ReactDOM.render(rangeSelectionFactory(options), $mountLocation);+ }+ self.getLocationFromStringDate = function(date) {+ return timeline.x(new Date(date));+ }self.showDateOnDrag = function(firstLocation, secondLocation) {var date = timeline.x.invert(firstLocation);timeline.pick.hoverDate(date)}+ self.update = function() { // being called from timeline.config.js+ var props = self.updateOptions();+ self.reactComponent.setState(props);+ }+ self.updateOptions = function() {+ var state = model.rangeState;+ var props = {};+ props.startLocation = self.getLocationFromStringDate(state.startDate);+ props.endLocation = self.getLocationFromStringDate(state.endDate);+ props.max = timeline.x(timeline.data.end());+ return props;+ }self.updateRange = function(startLocation, EndLocation) {var startDate = timeline.x.invert(startLocation);var endDate = timeline.x.invert(EndLocation);+ var state = model.rangeState;+ state.startDate = wv.util.toISOStringDate(startDate) || 0;+ state.endDate = wv.util.toISOStringDate(endDate);+timeline.ticks.label.remove();+ model.events.trigger('change');}self.init();