Interactive interface for browsing global, full-resolution satellite imagery
Make animation feature modular
Benjamin Kingc710d2348d7c
diff --git a/web/js/animation/anim.js b/web/js/animation/anim.jsnew file mode 100644index 000000000..ce0a075b6--- /dev/null+++ b/web/js/animation/anim.js@@ -0,0 +1,29 @@+import loEach from 'lodash/each';++export function parse (state, errors) {+ if (state.a) {+ var str = state.a;+ var astate = {+ attributes: []+ };++ // Get text before (+ 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, '');+ var kvps = str.split(',');+ loEach(kvps, function (kvp) {+ var parts = kvp.split('=');+ astate.attributes.push({+ id: parts[0],+ value: parts[1]+ });+ });+ state.a = astate;+ }+};diff --git a/web/js/animation/wv.anim.gif.js b/web/js/animation/gif.jssimilarity index 88%rename from web/js/animation/wv.anim.gif.jsrename to web/js/animation/gif.jsindex 8e73a6916..4db1fe153 100644--- a/web/js/animation/wv.anim.gif.js+++ b/web/js/animation/gif.js@@ -1,12 +1,16 @@-var wv = wv || {};--wv.anim = wv.anim || {};--wv.anim.gif = wv.anim.gif || function (models, config, ui) {+import $ from 'jquery';+import 'jquery-jcrop';+import wvui from '../ui/ui';+import gifshot from 'gifshot';+import loFind from 'lodash/find';+import loEach from 'lodash/each';+import loIsUndefined from 'lodash/isundefined';+import {GA as googleAnalytics} from 'worldview-components';+import util from '../util/util';++export function animationGif(models, config, ui) {var self = {};- var $cropee = $('#wv-map');var jcropAPI = null;- var coords = null;var animCoords = null;var previousCoords = null;var animModel = models.anim;@@ -14,7 +18,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {var loader;var showDates = true; // show date stampvar progressing = false; // if progress bar has started- var GRATICLE_WARNING =+ var GRATICULE_WARNING ='The graticule layer cannot be used to take a snapshot. Would you ' +'like to hide this layer?';var PALETTE_WARNING =@@ -54,17 +58,16 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {var interval = stateObj.speed;var startDate = stateObj.startDate;var endDate = stateObj.endDate;- var shootGIFafterImageLoad;var imageArra;var stamp;var build;- loader = wv.ui.indicator.loading();+ loader = wvui.indicator.loading();build = function (stamp) {var buildProgressBar = function () {$progress = $('<progress />') // display progress for GIF creation.attr('class', 'wv-gif-progress');- wv.ui.getDialog()+ wvui.getDialog().append($progress).dialog({ // dialog for progresstitle: 'Collecting Images...',@@ -77,7 +80,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {if (!progressing) {buildProgressBar();progressing = true;- wv.ui.indicator.hide(loader);+ wvui.indicator.hide(loader);}$progress.parent().dialog('option', 'title', 'Creating GIF...'); // set dialog title@@ -132,17 +135,16 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {*/var calcRes = function (mode) { // return either multiplier or string resolution// geographic has 10 zoom levels from 0 to 9, polar projections have 8 from 0 to 7+ var str, res;var isGeographic = models.proj.selected.id === 'geographic';// Map the zoom level from 0-9 / 0-7 to an index from 0-4- var zoom_res = [40, 20, 4, 2, 1],- str, res;+ var zoomRes = [40, 20, 4, 2, 1];+if (isGeographic) {- res = zoom_res[Math.floor(ui.map.selected.getView()- .getZoom() / 2)];+ res = zoomRes[Math.floor(ui.map.selected.getView().getZoom() / 2)];} else {- res = zoom_res[Math.floor(((ui.map.selected.getView()- .getZoom() + 2) / 2))];+ res = zoomRes[Math.floor(((ui.map.selected.getView().getZoom() + 2) / 2))];}if (mode === 0) { return res; } else {@@ -186,33 +188,32 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {renderable: true});if (models.palettes.inUse()) {- wv.ui.ask({+ wvui.ask({header: 'Notice',message: PALETTE_WARNING,onOk: function () {- previousPalettes = models.palettes.active;models.palettes.clear();self.getGif();}});return;}- if (_.find(layers, {+ if (loFind(layers, {id: 'Graticule'}) && models.proj.selected.id === 'geographic') {- wv.ui.ask({+ wvui.ask({header: 'Notice',message: GRATICULE_WARNING,onOk: function () {models.layers.setVisibility('Graticule', false);- self.getGif(startDate, endDate, delta, interval);+ self.getGif();}});return;}if (ui.map.selected.getView().getRotation() !== 0.0) {- wv.ui.ask({+ wvui.ask({header: 'Reset rotation?',message: ROTATE_WARNING,onOk: function () {@@ -223,7 +224,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {});return;}- WVC.GA.event('Animation', 'Click', 'Create GIF');+ googleAnalytics.event('Animation', 'Click', 'Create GIF');self.createGIF();};@@ -240,7 +241,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {*/var getLayers = function (products, proj) {var layers = [];- _.each(products, function (layer) {+ loEach(products, function (layer) {if (layer.projections[proj].layer) {layers.push(layer.projections[proj].layer);} else {@@ -264,7 +265,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {reverse: true,renderable: true});- _.each(products, function (layer) {+ loEach(products, function (layer) {if (layer.endDate) {if (date > new Date(layer.endDate)) return;}@@ -290,8 +291,8 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {*/var getOpacities = function (products) {var opacities = [];- _.each(products, function (product) {- opacities.push((_.isUndefined(product.opacity)) ? 1 : product.opacity);+ loEach(products, function (product) {+ opacities.push((loIsUndefined(product.opacity)) ? 1 : product.opacity);});return opacities;};@@ -354,6 +355,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {var opacities;var epsg = (models.proj.change) ? models.proj.change.epsg : models.proj.selected.epsg;var products = getProducts();+ var layers;if (config.features.imageDownload) {host = config.features.imageDownload.host;@@ -365,13 +367,13 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {while (current <= toDate) {j++;- strDate = wv.util.toISOStringDate(current);+ strDate = util.toISOStringDate(current);products = getProducts(current);layers = getLayers(products, proj);opacities = getOpacities(products);- url = wv.util.format(host + '/' + path + '?{1}&extent={2}&epsg={3}&layers={4}&opacities={5}&worldfile=false&format=image/jpeg&width={6}&height={7}', 'TIME={1}', lonlat[0][0] + ',' + lonlat[0][1] + ',' + lonlat[1][0] + ',' + lonlat[1][1], epsg, layers.join(','), opacities.join(','), dimensions[0], dimensions[1]);- src = wv.util.format(url, strDate);+ url = util.format(host + '/' + path + '?{1}&extent={2}&epsg={3}&layers={4}&opacities={5}&worldfile=false&format=image/jpeg&width={6}&height={7}', 'TIME={1}', lonlat[0][0] + ',' + lonlat[0][1] + ',' + lonlat[1][0] + ',' + lonlat[1][1], epsg, layers.join(','), opacities.join(','), dimensions[0], dimensions[1]);+ src = util.format(url, strDate);if (showDates) {a.push({src: src,@@ -380,10 +382,10 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {} else {a.push(src);}- current = wv.util.dateAdd(current, ui.anim.ui.getInterval(), 1);+ current = util.dateAdd(current, ui.anim.ui.getInterval(), 1);if (j > 40) { // too many framesshowUnavailableReason();- wv.ui.indicator.hide(loader);+ ui.indicator.hide(loader);return false;}@@ -404,11 +406,11 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {var showUnavailableReason = function () {var headerMsg = '<h3 class=\'wv-data-unavailable-header\'>GIF Not Available</h3>';var bodyMsg = 'Too many frames were selected. Please request less than 40 frames if you would like to generate a GIF';- callback = function () {+ var callback = function () {$('#timeline-footer').toggleClass('wv-anim-active');};- wv.ui.notify(headerMsg + bodyMsg, 'Notice', 600, callback);+ wvui.notify(headerMsg + bodyMsg, 'Notice', 600, callback);};/*@@ -449,8 +451,8 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {// Create a blob out of the image's base64 encoding because Chrome can't handle large data URIs, taken from:// http://stackoverflow.com/questions/16761927/aw-snap-when-data-uri-is-too-large- var byteCharacters = atob(obj.image.substring(22)),- byteArrays = []; // remove "data:image/gif;base64,"+ var byteCharacters = atob(obj.image.substring(22));+ var byteArrays = []; // remove "data:image/gif;base64,"for (var offset = 0; offset < byteCharacters.length; offset += 512) {var slice = byteCharacters.slice(offset, offset + 512);@@ -466,7 +468,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {});var blobURL = URL.createObjectURL(blob); // supported in Chrome and FFanimatedImage.src = blobURL;- var dlURL = wv.util.format('nasa-worldview-{1}-to-{2}.gif', animModel.rangeState.startDate, animModel.rangeState.endDate);+ var dlURL = util.format('nasa-worldview-{1}-to-{2}.gif', animModel.rangeState.startDate, animModel.rangeState.endDate);var downloadSize = (blob.size / 1024).toFixed();@@ -485,7 +487,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {.removeClass('ui-state-hover');}).click(function () {- WVC.GA.event('Animation', 'Download', 'GIF', downloadSize);+ googleAnalytics.event('Animation', 'Download', 'GIF', downloadSize);});var $catalog =@@ -538,12 +540,12 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {$dialogBodyCase.append($catalog);// calculate the offset of the dialog position based on image size to display it properly// only height needs to be adjusted to center the dialog- var pos_width = animCoords.w * 1 / window.innerWidth,- pos_height = animCoords.h * 50 / window.innerHeight;- var at_string = 'center-' + pos_width.toFixed() + '% center-' + pos_height.toFixed() + '%';+ var posWidth = animCoords.w * 1 / window.innerWidth;+ var posHeight = animCoords.h * 50 / window.innerHeight;+ var atString = 'center-' + posWidth.toFixed() + '% center-' + posHeight.toFixed() + '%';// Create a dialog over the view and place the image there- var $imgDialog = wv.ui.getDialog()+ var $imgDialog = wvui.getDialog().append($dialogBodyCase).append($download);$imgDialog.dialog({@@ -560,19 +562,19 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {},position: { // based on image sizemy: 'center center',- at: at_string,+ at: atString,of: window}});} else {var headerMsg = '<h3 class=\'wv-data-unavailable-header\'>GIF Not Available</h3>';var bodyMsg = 'One or more of the frames requested was unable to be processed';- wv.ui.indicator.hide(loader);- callback = function () {+ wvui.indicator.hide(loader);+ var callback = function () {$('#timeline-footer').toggleClass('wv-anim-active');};- wv.ui.notify(headerMsg + bodyMsg, 'Notice', 600, callback);+ wvui.notify(headerMsg + bodyMsg, 'Notice', 600, callback);}};@@ -589,14 +591,14 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {**/var calcSize = function (c) {- var lonlat1 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x), Math.floor(c.y2)]),- lonlat2 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x2), Math.floor(c.y)]);+ var lonlat1 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x), Math.floor(c.y2)]);+ var lonlat2 = ui.map.selected.getCoordinateFromPixel([Math.floor(c.x2), Math.floor(c.y)]);- var conversionFactor = models.proj.selected.id === 'geographic' ? 0.002197 : 256,- res = calcRes(0);+ var conversionFactor = models.proj.selected.id === 'geographic' ? 0.002197 : 256;+ var res = calcRes(0);- var imgWidth = Math.round((Math.abs(lonlat2[0] - lonlat1[0]) / conversionFactor) / Number(res)),- imgHeight = Math.round((Math.abs(lonlat2[1] - lonlat1[1]) / conversionFactor) / Number(res));+ var imgWidth = Math.round((Math.abs(lonlat2[0] - lonlat1[0]) / conversionFactor) / Number(res));+ var imgHeight = Math.round((Math.abs(lonlat2[1] - lonlat1[1]) / conversionFactor) / Number(res));return ((imgWidth * imgHeight * 24) / 8388608).toFixed(2);@@ -673,7 +675,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {initCheckBox($checkBox);$createButton.on('click', self.getGif);- $dialogBox = wv.ui.getDialog();+ $dialogBox = wvui.getDialog();$dialogBox.html($dialog);$dialogBox.css({paddingBottom: '10px'@@ -852,7 +854,6 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {.html((c.h));},onChange: function (c) { // Update gif size and image size in MB- var modalLeftMargin;animCoords = c;if (c.h !== 0 && c.w !== 0) { previousCoords = c; } // don't save coordinates if empty selection@@ -880,7 +881,7 @@ wv.anim.gif = wv.anim.gif || function (models, config, ui) {$('#timeline-footer').toggleClass('wv-anim-active');if ($dialog) {- wv.ui.close();+ wvui.close();}}}, function () {diff --git a/web/js/animation/wv.anim.model.js b/web/js/animation/model.jssimilarity index 91%rename from web/js/animation/wv.anim.model.jsrename to web/js/animation/model.jsindex dc0c7ddb8..c217bd04d 100644--- a/web/js/animation/wv.anim.model.js+++ b/web/js/animation/model.js@@ -1,10 +1,10 @@-var wv = wv || {};-wv.anim = wv.anim || {};-wv.anim.model = wv.anim.model || function (models, config) {+import util from '../util/util';++export function animationModel(models, config) {// state.a is now an object, check input and set valuesvar self = {};self.delay = 500;- self.events = wv.util.events();+ self.events = util.events();self.animationState = {active: false,@@ -99,12 +99,7 @@ wv.anim.model = wv.anim.model || function (models, config) {**/self.save = function (state) {- var activeState;- var playStates;- var options;- var newState;-- rangeState = self.rangeState;+ var rangeState = self.rangeState;// state.a = state.a || [];// newState = {id: rangeState.state};// newState.attributes = [];diff --git a/web/js/animation/wv.anim.rangeselect.js b/web/js/animation/range-select.jssimilarity index 88%rename from web/js/animation/wv.anim.rangeselect.jsrename to web/js/animation/range-select.jsindex 90fe9c6eb..e5055521c 100644--- a/web/js/animation/wv.anim.rangeselect.js+++ b/web/js/animation/range-select.js@@ -1,20 +1,20 @@-var wv = wv || {};--wv.anim = wv.anim || {};--wv.anim.rangeselect = wv.anim.rangeselect || function (models, config, ui) {+import $ from 'jquery';+import React from 'react';+import ReactDOM from 'react-dom';+import {RangeSelector} from 'worldview-components';+import d3 from 'd3';+import util from '../util/util';++export function animationRangeSelect(models, config, ui) {var self = {};var model;var timeline = ui.timeline;- var widgetOptions = ui.anim.options;- var rangeSelectionFactory = React.createFactory(WVC.RangeSelector);- var $mountLocation = $('#wv-rangeselector-case')[0];- var reactGlobal = {};+ var rangeSelectionFactory = React.createFactory(RangeSelector);+ var $mountLocation = $('#wv-rangeselector-case');var $footer = $('#timeline-footer');var $header = $('#timeline-header');var $timeline = $('#timeline');- ui.anim.rangeOptions = ui.anim.rangeOptions || {};/** set listeners and initiates* widget@@ -26,9 +26,6 @@ wv.anim.rangeselect = wv.anim.rangeselect || function (models, config, ui) {**/self.init = function () {- var $animateButton = $('#animate-button');- var options;-self.setDefaults();self.render();models.date.events.on('timeline-change', self.update);@@ -70,13 +67,11 @@ wv.anim.rangeselect = wv.anim.rangeselect || function (models, config, ui) {self.render = function () {var options;var startLocation;- var EndLocation;+ var endLocation;var pick = d3.select('#guitarpick');var pickWidth = pick.node().getBoundingClientRect().width;- var ticHeight = $('.end-tick')- .height();var animEndLocation = (d3.transform(pick.attr('transform')).translate[0] - (pickWidth / 2)); // getting guitar pick location@@ -104,7 +99,7 @@ wv.anim.rangeselect = wv.anim.rangeselect || function (models, config, ui) {onDrag: self.updateRange,onRangeClick: self.onRangeClick};- self.reactComponent = ReactDOM.render(rangeSelectionFactory(options), $mountLocation);+ self.reactComponent = ReactDOM.render(rangeSelectionFactory(options), $mountLocation[0]);};/*@@ -180,7 +175,6 @@ wv.anim.rangeselect = wv.anim.rangeselect || function (models, config, ui) {**/self.updateOptions = function () {- var max;var state = model.rangeState;var props = {};props.startLocation = self.getLocationFromStringDate(state.startDate);@@ -227,8 +221,8 @@ wv.anim.rangeselect = wv.anim.rangeselect || function (models, config, ui) {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);+ state.startDate = util.toISOStringDate(startDate) || 0;+ state.endDate = util.toISOStringDate(endDate);model.rangeState.playing = false;model.events.trigger('change');model.events.trigger('datechange');diff --git a/web/js/animation/wv.anim.ui.js b/web/js/animation/ui.jssimilarity index 85%rename from web/js/animation/wv.anim.ui.jsrename to web/js/animation/ui.jsindex 6cd83a852..c47e0b74c 100644--- a/web/js/animation/wv.anim.ui.js+++ b/web/js/animation/ui.js@@ -1,13 +1,14 @@-var wv = wv || {};-wv.anim = wv.anim || {};-wv.anim.ui = wv.anim.ui || function (models, ui) {+import loIsEmpty from 'lodash/isempty';+import Queue from 'promise-queue';+import util from '../util/util';+import uiIndicator from '../ui/indicator';++export function animationui(models, ui) {var self = {};- self.events = wv.util.events();+ self.events = util.events();var dateModel = models.date;var animModel = models.anim;var queueLength;- var animateArray;- var map = ui.map.selected;var zooms = ['year', 'month', 'day'];var queue = new Queue(5, Infinity);var preload = {};@@ -15,7 +16,6 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {var inQueue;var pastDates;var loader;-/** sets listeners*@@ -90,8 +90,8 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {};animModel.rangeState.playing = false;animModel.events.trigger('change');- wv.ui.indicator.hide(loader);- wv.ui.indicator._hide(loader);+ uiIndicator.hide(loader);+ uiIndicator._hide(loader);};/*@@ -111,13 +111,13 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {var startDate;var currentDate;state = animModel.rangeState;- endDate = wv.util.parseDateUTC(state.endDate);- startDate = wv.util.parseDateUTC(state.startDate);+ endDate = util.parseDateUTC(state.endDate);+ startDate = util.parseDateUTC(state.startDate);currentDate = dateModel.selected;if (currentDate > startDate && self.nextDate(currentDate) < endDate) {- return wv.util.toISOStringDate(self.nextDate(currentDate));+ return util.toISOStringDate(self.nextDate(currentDate));}- return wv.util.toISOStringDate(startDate);+ return util.toISOStringDate(startDate);};/*@@ -160,7 +160,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {**/self.nextDate = function (date) {- return wv.util.dateAdd(date, self.getInterval(), 1);+ return util.dateAdd(date, self.getInterval(), 1);};/*@@ -201,7 +201,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {**/self.addToInQueue = function (date) {- var strDate = wv.util.toISOStringDate(date);+ var strDate = util.toISOStringDate(date);inQueue[strDate] = date;preloadArray.push(strDate);};@@ -220,7 +220,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {**/self.addDateToCache = function (date) {- var strDate = wv.util.toISOStringDate(date);+ var strDate = util.toISOStringDate(date);preload[strDate] = date;delete inQueue[strDate];};@@ -239,7 +239,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {self.shiftCache = function () {var key;if (preload[preloadArray[0]] &&- wv.util.objectLength(preload) > queueLength + (queueLength / 2) + 1 &&+ util.objectLength(preload) > queueLength + (queueLength / 2) + 1 &&pastDates[preloadArray[0]] &&!self.isInToPlayGroup(preloadArray[0])) {key = preloadArray.shift();@@ -314,17 +314,14 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {**/self.checkQueue = function (bufferLength, index) {- var date;var currentDate;- var startDate = wv.util.parseDateUTC(animModel.rangeState.startDate);- var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);- var loop = animModel.rangeState.loop;+ var startDate = util.parseDateUTC(animModel.rangeState.startDate);+ var endDate = util.parseDateUTC(animModel.rangeState.endDate);var lastToQueue;- var nextDate;if (!animModel.rangeState.playing) {return self.refreshState();}- currentDate = wv.util.parseDateUTC(index);+ currentDate = util.parseDateUTC(index);lastToQueue = self.getLastBufferDateStr(currentDate, startDate, endDate);if (!preloadArray[0] && !inQueue[index]) {@@ -350,9 +347,9 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {var layer;var layers = models.layers.get();- for (var i = 0, len = layers; i < layers.length; i++) {+ for (var i = 0, len = layers.length; i < len; i++) {layer = layers[i];- if (!_.isEmpty(models.palettes.isActive(layer.id)) && layer.visible) {+ if (!loIsEmpty(models.palettes.isActive(layer.id)) && layer.visible) {return true;}}@@ -380,7 +377,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {nextDate = self.setNewDate(nextDate, startDate);}- nextDateStr = wv.util.toISOStringDate(nextDate);+ nextDateStr = util.toISOStringDate(nextDate);if (!preload[nextDateStr] && !inQueue[nextDateStr] && !self.state.playing) {self.clearCache();@@ -416,17 +413,17 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {for (var i = 0; i < queueLength; i++) {self.addDate(day);day = self.getNextBufferDate(day, startDate, endDate);- if (wv.util.toISOStringDate(day) === lastToQueue) {+ if (util.toISOStringDate(day) === lastToQueue) {self.addDate(day);- loader = wv.ui.indicator.loading();+ loader = uiIndicator.loading();return;- } else if (wv.util.toISOStringDate(day) === wv.util.toISOStringDate(currentDate)) {+ } else if (util.toISOStringDate(day) === util.toISOStringDate(currentDate)) {queueLength = i;- loader = wv.ui.indicator.loading();+ loader = uiIndicator.loading();return;}}- loader = wv.ui.indicator.loading();+ loader = uiIndicator.loading();};/*@@ -471,7 +468,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {*/self.addItemToQueue = function (currentDate, startDate, endDate) {var nextDate = self.getNextBufferDate(currentDate, startDate, endDate);- var nextDateStr = wv.util.toISOStringDate(nextDate);+ var nextDateStr = util.toISOStringDate(nextDate);if (!inQueue[nextDateStr] &&!preload[nextDateStr] &&@@ -497,7 +494,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {**/self.getNextBufferDate = function (currentDate, startDate, endDate) {- var lastInBuffer = wv.util.parseDateUTC(preloadArray[preloadArray.length - 1]);+ var lastInBuffer = util.parseDateUTC(preloadArray[preloadArray.length - 1]);var nextDate = self.nextDate(lastInBuffer);if (lastInBuffer >= endDate || self.nextDate(lastInBuffer) > endDate) {return self.setNewDate(nextDate, startDate);@@ -527,7 +524,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {while (i < queueLength) {if (self.nextDate(day) > endDate) {if (!loop) {- return wv.util.toISOStringDate(day);+ return util.toISOStringDate(day);}day = self.setNewDate(day, startDate);} else {@@ -535,7 +532,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {}i++;}- return wv.util.toISOStringDate(day);+ return util.toISOStringDate(day);};/*@@ -554,7 +551,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {self.checkShouldLoop = function (playIndexJSDate) {if (animModel.rangeState.loop) {self.shiftCache();- self.state.playIndex = wv.util.toISOStringDate(self.setNewDate(playIndexJSDate, new Date(animModel.rangeState.startDate)));+ self.state.playIndex = util.toISOStringDate(self.setNewDate(playIndexJSDate, new Date(animModel.rangeState.startDate)));setTimeout(function () {self.checkShouldPlay();self.checkQueue(queueLength, self.state.playIndex);@@ -578,10 +575,9 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {**/self.checkShouldPlay = function () {- var currentDate = wv.util.parseDateUTC(self.state.playIndex);- var fps = 1000 / animModel.rangeState.speed;- var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);- var startDate = wv.util.parseDateUTC(animModel.rangeState.startDate);+ var currentDate = util.parseDateUTC(self.state.playIndex);+ var endDate = util.parseDateUTC(animModel.rangeState.endDate);+ var startDate = util.parseDateUTC(animModel.rangeState.startDate);if (self.state.playing || !animModel.rangeState.playing) {return false;}@@ -592,7 +588,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {}if (self.state.supportingCustomLayers &&preload[self.state.playIndex] &&- _.isEmpty(inQueue)) {+ loIsEmpty(inQueue)) {self.play(self.state.playIndex);return;}@@ -613,8 +609,8 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {*/self.play = function (index) {self.state.playing = true;- wv.ui.indicator.hide(loader);- wv.ui.indicator._hide(loader);+ uiIndicator.hide(loader);+ uiIndicator._hide(loader);self.animate(index);};@@ -650,15 +646,15 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {var interval;var playIndex = index;var playIndexJSDate;- var endDate = wv.util.parseDateUTC(animModel.rangeState.endDate);+ var endDate = util.parseDateUTC(animModel.rangeState.endDate);var player = function () {self.shiftCache();self.checkQueue(queueLength, playIndex);- dateModel.select(wv.util.parseDateUTC(playIndex));- pastDates[playIndex] = wv.util.parseDateUTC(playIndex); // played record+ dateModel.select(util.parseDateUTC(playIndex));+ pastDates[playIndex] = util.parseDateUTC(playIndex); // played recordself.state.playIndex = playIndex;- playIndex = wv.util.toISOStringDate(self.nextDate(new Date(playIndex)));+ playIndex = util.toISOStringDate(self.nextDate(new Date(playIndex)));playIndexJSDate = new Date(playIndex);if (playIndexJSDate > endDate) {clearInterval(interval);@@ -670,7 +666,7 @@ wv.anim.ui = wv.anim.ui || function (models, ui) {clearInterval(interval);self.state.playing = false;if (!preload[playIndex] && animModel.rangeState.playing) { // Still playing, add loader- loader = wv.ui.indicator.loading();+ loader = uiIndicator.loading();self.shiftCache();self.checkQueue(queueLength, self.state.playIndex);} else {diff --git a/web/js/animation/wv.anim.widget.js b/web/js/animation/widget.jssimilarity index 87%rename from web/js/animation/wv.anim.widget.jsrename to web/js/animation/widget.jsindex 3064a46c1..d61c43008 100644--- a/web/js/animation/wv.anim.widget.js+++ b/web/js/animation/widget.js@@ -1,13 +1,17 @@-var wv = wv || {};+import $ from 'jquery';+import {AnimationWidget, GA as googleAnalytics} from 'worldview-components';+import React from 'react';+import ReactDOM from 'react-dom';+import loWithout from 'lodash/without';+import loIndexOf from 'lodash/indexof';+import util from '../util/util';-wv.anim = wv.anim || {};--wv.anim.widget = wv.anim.widget || function (models, config, ui) {+export function animationWidget (models, config, ui) {var zooms = ['yearly', 'monthly', 'daily'];var self = {};var timeline = ui.timeline;var model = models.anim;- var widgetFactory = React.createFactory(WVC.AnimationWidget);+ var widgetFactory = React.createFactory(AnimationWidget);var $timelineFooter;var $animateButton;var dataModel;@@ -22,17 +26,15 @@ wv.anim.widget = wv.anim.widget || function (models, config, ui) {**/self.init = function () {- var speed;var Widget;Widget = self.initWidget();// mount react component$animateButton = $('#animate-button');self.reactComponent = ReactDOM.render(Widget, $('#wv-animation-widet-case')[0]);-$timelineFooter = $('#timeline-footer');$animateButton.on('click', function () {- WVC.GA.event('Animation', 'Click', 'Animation Icon');+ googleAnalytics.event('Animation', 'Click', 'Animation Icon');self.toggleAnimationWidget();});if (model.rangeState.state === 'on') { // show animation widget if active in permalink@@ -99,7 +101,7 @@ wv.anim.widget = wv.anim.widget || function (models, config, ui) {onPushGIF: self.onPressGIF,looping: model.rangeState.loop,increment: self.getIncrements(), // config.currentZoom is a number: 1,2,3- incrementArray: _.without(zooms, self.getIncrements()), // array of zooms without current zoom+ incrementArray: loWithout(zooms, self.getIncrements()), // array of zooms without current zoomonDateChange: self.dateUpdate,sliderLabel: 'Frames Per Second',sliderSpeed: rangeState.speed,@@ -150,7 +152,7 @@ wv.anim.widget = wv.anim.widget || function (models, config, ui) {endDate: new Date(state.endDate),playing: state.playing,increment: self.getIncrements(), // config.currentZoom is a number: 1,2,3- incrementArray: _.without(zooms, self.getIncrements()) // array of zooms without current zoom+ incrementArray: loWithout(zooms, self.getIncrements()) // array of zooms without current zoom});};@@ -182,7 +184,7 @@ wv.anim.widget = wv.anim.widget || function (models, config, ui) {**/self.onZoomSelect = function (increment) {- var zoomLevel = _.indexOf(zooms, increment);+ var zoomLevel = loIndexOf(zooms, increment);return timeline.config.zoom(zoomLevel + 1);};@@ -201,8 +203,8 @@ wv.anim.widget = wv.anim.widget || function (models, config, ui) {**/self.dateUpdate = function (startDate, endDate) {- model.rangeState.startDate = wv.util.toISOStringDate(startDate) || 0;- model.rangeState.endDate = wv.util.toISOStringDate(endDate);+ model.rangeState.startDate = util.toISOStringDate(startDate) || 0;+ model.rangeState.endDate = util.toISOStringDate(endDate);model.rangeState.playing = false;model.events.trigger('change');model.events.trigger('datechange');@@ -247,19 +249,17 @@ wv.anim.widget = wv.anim.widget || function (models, config, ui) {};self.makeDateGuess = function () {- var start;- var end;var currentDate = new Date(models.date.selected);var interval = ui.anim.ui.getInterval();- var day = wv.util.dateAdd(currentDate, interval, 7);+ var day = util.dateAdd(currentDate, interval, 7);var today = new Date();if (day > today) {- model.rangeState.endDate = wv.util.toISOStringDate(currentDate);- model.rangeState.startDate = wv.util.toISOStringDate(wv.util.dateAdd(currentDate, interval, -7));+ model.rangeState.endDate = util.toISOStringDate(currentDate);+ model.rangeState.startDate = util.toISOStringDate(util.dateAdd(currentDate, interval, -7));} else {- model.rangeState.startDate = wv.util.toISOStringDate(currentDate);- model.rangeState.endDate = wv.util.toISOStringDate(wv.util.dateAdd(currentDate, interval, 7));+ model.rangeState.startDate = util.toISOStringDate(currentDate);+ model.rangeState.endDate = util.toISOStringDate(util.dateAdd(currentDate, interval, 7));}};/*diff --git a/web/js/animation/wv.anim.js b/web/js/animation/wv.anim.jsdeleted file mode 100644index 7934f81f4..000000000--- a/web/js/animation/wv.anim.js+++ /dev/null@@ -1,33 +0,0 @@-var wv = wv || {};--wv.anim = (function (self) {- // Given the raw string, parse state.a into an object- self.parse = function (state, errors) {- if (state.a) {- var str = state.a,- astate = {- attributes: []- };-- // Get text before (- 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, '');- var kvps = str.split(',');- _.each(kvps, function (kvp) {- var parts = kvp.split('=');- astate.attributes.push({- id: parts[0],- value: parts[1]- });- });- state.a = astate;- }- };- return self;-})(wv.anim || {});