Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

reorganized animation component

Benjaminab2aedd03af2
diff --git a/web/index.html b/web/index.html
index bad8f8f4e..e3181639b 100644
--- a/web/index.html
+++ b/web/index.html
@@ -176,11 +176,13 @@
<!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/proj/wv.proj.ui.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.anim.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.anim.rangeselect.js"></script>
- <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.anim.widget.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/animation/wv.anim.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/animation/wv.anim.ui.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/animation/wv.anim.model.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/animation/wv.anim.rangeselect.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/animation/wv.anim.widget.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/date/wv.date.label.js"></script>
diff --git a/web/js/animation/wv.anim.js b/web/js/animation/wv.anim.js
new file mode 100644
index 000000000..def7e961f
--- /dev/null
+++ b/web/js/animation/wv.anim.js
@@ -0,0 +1,41 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ *
+ * Licensed under the NASA Open Source Agreement, Version 1.3
+ * http://opensource.gsfc.nasa.gov/nosa.php
+ */
+ 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 || {});
diff --git a/web/js/animation/wv.anim.model.js b/web/js/animation/wv.anim.model.js
new file mode 100644
index 000000000..2f80f6872
--- /dev/null
+++ b/web/js/animation/wv.anim.model.js
@@ -0,0 +1,140 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ *
+ * Licensed under the NASA Open Source Agreement, Version 1.3
+ * http://opensource.gsfc.nasa.gov/nosa.php
+ */
+var wv = wv || {};
+wv.anim = wv.anim || {};
+wv.anim.model = wv.anim.model || function(models, config) {
+ //state.a is now an object, check input and set values
+ var self = {};
+ self.delay = options.delay || 500;
+
+ self.animationState = {
+ active: false,
+ speed: 10,
+ loop: false,
+ reverse: false,
+ };
+
+ self.load = function(state, errors) {
+ if ( !_.isUndefined(state.a) ) {
+ self.doAnimation = true; //set to false if something is wrong
+
+ var attributes = state.a.attributes;
+ attributes.forEach(function(attr) { //handle all input here
+ if(attr.id === 'speed') {
+ try {
+ self.delay = parseFloat(1000 / attr.value);
+ if (self.delay > 1000)
+ self.delay = 1000;
+ else if (self.delay < 33)
+ self.delay = 33;
+ } catch (e) {
+ errors.push({message: "Invalid speed: " + e});
+ self.doAnimation = false;
+ }
+ }
+ else if(attr.id === 'loop')
+ self.loop = attr.value === 'true';
+ else if(attr.id === 'interval') {
+ self.interval = attr.value;
+ if(self.interval !== 'day' && self.interval !== 'month' && self.interval !== 'year')
+ self.interval = 'day';
+ }
+ else if(attr.id === 'start') {
+ try {
+ self.initDate = wv.util.parseDateUTC(attr.value);
+ } catch (e) {
+ errors.push({message: e});
+ self.doAnimation = false;
+ }
+ }
+ else if(attr.id === 'end') {
+ try {
+ self.endDate = wv.util.parseDateUTC(attr.value);
+ } catch (e) {
+ errors.push({message: e});
+ self.doAnimation = false;
+ }
+ }
+ });
+
+ //Check if dates have been set and no data download, otherwise no animation
+ if(self.initDate === undefined || self.endDate === undefined || state.download)
+ self.doAnimation = false;
+
+ if(self.doAnimation) {
+ //Prepare and start animation. Set UI elements
+ $("#dialog").dialog("open");
+
+ //HACK: Weird functionality with Date objects mean to show the right date, need to offset it by one
+ var tempFrom = new Date(self.initDate), tempTo = new Date(self.endDate);
+ tempFrom.setUTCDate(tempFrom.getUTCDate() + 1);
+ tempTo.setUTCDate(tempTo.getUTCDate() + 1);
+ ui.timeline.input.fromDate = _.clone(self.initDate);
+ ui.timeline.input.toDate = _.clone(self.endDate);
+
+ //update date picker widgets and sliders
+ if(self.interval === 'month') {
+ $("#wv-month").attr("checked", "true");
+ ui.timeline.config.zoom(2); //zoom out to see pickers
+ }
+ else if(self.interval === 'year') {
+ $("#wv-year").attr("checked", "true");
+ ui.timeline.config.zoom(2);
+ }
+
+ $("#wv-speed-slider").val((1000 / self.delay).toFixed()); //val is the nouislider setter
+ $("#loopcheck").attr("checked", self.loop);
+ $("#from").datepicker("setDate", tempFrom);
+ $("#to").datepicker("setDate", tempTo);
+ d3.select("#fromPick").attr("transform", ui.timeline.pick.updateAnimPickers(self.initDate));
+ d3.select("#toPick").attr("transform", ui.timeline.pick.updateAnimPickers(self.endDate));
+ model.selected = new Date(self.initDate.valueOf());
+
+ ui.timeline.input.disableDialog();
+ self.setDirectionAndRun(self.endDate.getTime(), self.initDate.getTime());
+ }
+ }
+ };
+ self.add = function(arra) {
+ var updatedState = _.clone(self.state);
+ arra.forEach(function(prop) {
+ updatedState[prop.id] = prop.value;
+ });
+ self.animationState = updatedState;
+ }
+
+ //update animation fields, set animation settings into an object
+ self.save = function(state, args) {
+ var attributes;
+ var activeState;
+ var playStates;
+
+ state.a = state.a || [];
+ attributes = [];
+ activeState = {id: args.active};
+ playStates = {id: speed, args.}
+
+
+
+ if($("#dialog").dialog("isOpen")) { //save if animation dialog open not just animating
+ state.a = state.a || [];
+ var astate = {id: "on"};
+ astate.attributes = [];
+ astate.attributes.push({id: "speed", value: (1000 /self.delay).toFixed()}, {id: "loop", value: (self.loop) ? "true" : "false"}, {id: "interval", value: self.interval});
+ astate.attributes.push({id: "start", value: self.initDate.toISOString().split("T")[0]}, {id: "end", value: self.endDate.toISOString().split("T")[0]});
+ state.a.push(astate);
+ }
+ };
+ return self;
+}
\ No newline at end of file
diff --git a/web/js/date/wv.date.anim.rangeselect.js b/web/js/animation/wv.anim.rangeselect.js
similarity index 92%
rename from web/js/date/wv.date.anim.rangeselect.js
rename to web/js/animation/wv.anim.rangeselect.js
index bd3d60483..f333c3c75 100644
--- a/web/js/date/wv.date.anim.rangeselect.js
+++ b/web/js/animation/wv.anim.rangeselect.js
@@ -12,11 +12,10 @@
* http://opensource.gsfc.nasa.gov/nosa.php
*/
var wv = wv || {};
-wv.date = wv.date || {};
-wv.date.anim = wv.date.anim || {};
+wv.anim = wv.anim || {};
-wv.date.anim.rangeselect = wv.date.anim.rangeselect || function(models, config, ui) {
+wv.anim.rangeselect = wv.anim.rangeselect || function(models, config, ui) {
var self = this;
var timeline = ui.timeline;
var rangeSelectionFactory = React.createFactory(Animate.RangeSelector);
diff --git a/web/js/animation/wv.anim.ui.js b/web/js/animation/wv.anim.ui.js
new file mode 100644
index 000000000..e48695eb5
--- /dev/null
+++ b/web/js/animation/wv.anim.ui.js
@@ -0,0 +1,76 @@
+ /*
+ * Copyright (C) 2013 - 2014 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ *
+ * Licensed under the NASA Open Source Agreement, Version 1.3
+ * http://opensource.gsfc.nasa.gov/nosa.php
+ */
+var wv = wv || {};
+wv.anim = wv.anim || {};
+wv.anim.ui = wv.anim.ui || function(models, ui, options) {
+ options = options || {};
+ var self = {};
+
+ self.delay = options.delay || 500;
+ self.direction = "forward";
+ self.interval = options.interval || "day";
+ self.delta = options.delta || 1;
+ self.active = false;
+ self.loop = false;
+ self.paused = false;
+ self.doAnimation = false;
+ self.initDate = undefined;
+ self.endDate = undefined;
+ var timer;
+
+ self.play = function(direction) {
+ if ( self.active && direction !== self.direction ) {
+ self.stop();
+ } else if ( self.active ) {
+ return;
+ }
+ self.direction = direction || self.direction;
+ self.active = true;
+ prepareFrame();
+ };
+
+ self.forward = function() {
+ self.play("forward");
+ };
+
+ self.reverse = function() {
+ self.play("reverse");
+ };
+
+ self.stop = function() {
+ if ( timer ) {
+ clearTimeout(timer);
+ timer = null;
+ }
+ self.active = false;
+ };
+
+ var prepareFrame = function() {
+ if ( !self.active ) {
+ return;
+ }
+ var amount = ( self.direction === "forward" ) ?
+ self.delta : -self.delta;
+ var newDate = wv.util.dateAdd(model.selected, self.interval, amount);
+ ui.preload(newDate);
+ timer = setTimeout(function() {
+ advance(newDate);
+ }, self.delay);
+ };
+
+ var advance = function(newDate) {
+ var updated = model.select(newDate);
+ if ( !updated ) {
+ self.stop();
+ } else {
+ prepareFrame();
+ }
+ };
+ return self;
+}
\ No newline at end of file
diff --git a/web/js/date/wv.date.anim.widget.js b/web/js/animation/wv.anim.widget.js
similarity index 90%
rename from web/js/date/wv.date.anim.widget.js
rename to web/js/animation/wv.anim.widget.js
index 7aed0d398..0114e3fd5 100644
--- a/web/js/date/wv.date.anim.widget.js
+++ b/web/js/animation/wv.anim.widget.js
@@ -12,11 +12,10 @@
* http://opensource.gsfc.nasa.gov/nosa.php
*/
var wv = wv || {};
-wv.date = wv.date || {};
-wv.date.anim = wv.date.anim || {};
+wv.anim = wv.anim || {};
-wv.date.anim.widget = wv.date.anim.widget || function(models, config, ui) {
+wv.anim.widget = wv.anim.widget || function(models, config, ui) {
var self = this;
var timeline = ui.timeline;
var widgetFactory = React.createFactory(Animate.AnimationWidget);
diff --git a/web/js/date/wv.date.anim.js b/web/js/date/wv.date.anim.js
deleted file mode 100644
index e764b25ef..000000000
--- a/web/js/date/wv.date.anim.js
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 - 2014 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- *
- * Licensed under the NASA Open Source Agreement, Version 1.3
- * http://opensource.gsfc.nasa.gov/nosa.php
- */
- var wv = wv || {};
- wv.date = wv.date || {};
-
- wv.date.anim = wv.date.anim || function(model, ui, options) {
-
- options = options || {};
- var self = {};
-
- self.delay = options.delay || 500;
- self.direction = "forward";
- self.interval = options.interval || "day";
- self.delta = options.delta || 1;
- self.active = false;
- var expired = false;
- var timer;
-
- var init = function() {
- };
-
- self.play = function(direction) {
- if ( self.active && direction !== self.direction ) {
- self.stop();
- } else if ( self.active ) {
- return;
- }
- notify("play");
- self.direction = direction || self.direction;
- self.active = true;
- prepareFrame();
- };
-
- self.forward = function() {
- self.play("forward");
- };
-
- self.reverse = function() {
- self.play("reverse");
- };
-
- self.stop = function() {
- notify("stop");
- if ( timer ) {
- clearTimeout(timer);
- timer = null;
- }
- self.active = false;
- };
-
- var prepareFrame = function() {
- if ( !self.active ) {
- return;
- }
- notify("prepare", self);
- var amount = ( self.direction === "forward" ) ?
- self.delta : -self.delta;
- var newDate = wv.util.dateAdd(model.selected, self.interval, amount);
- ui.preload(newDate);
- timer = setTimeout(function() {
- advance(newDate);
- }, self.delay);
- };
-
- var advance = function(newDate) {
- notify("advance");
- var updated = model.select(newDate);
- if ( !updated ) {
- self.stop();
- } else {
- prepareFrame();
- }
- };
-
- var notify = ( options.debug ) ? console.log : function() {};
-
- init();
- return self;
- };
diff --git a/web/js/link/wv.link.model.js b/web/js/link/wv.link.model.js
index a871e2420..e36f68c0d 100644
--- a/web/js/link/wv.link.model.js
+++ b/web/js/link/wv.link.model.js
@@ -47,6 +47,7 @@ wv.link.model = wv.link.model || function(config) {
self.toQueryString = function() {
var state = {};
_.each(components, function(component) {
+ console.log(component)
component.save(state);
});
var strings = _.map(state, function(value, key) {
diff --git a/web/js/wv.main.js b/web/js/wv.main.js
index cabc33005..c5fa71011 100644
--- a/web/js/wv.main.js
+++ b/web/js/wv.main.js
@@ -70,7 +70,8 @@ $(function() {
wv.layers.parse,
wv.date.parse,
wv.map.parse,
- wv.palettes.parse
+ wv.palettes.parse,
+ wv.anim.parse
];
if ( config.features.dataDownload ) {
parsers.push(wv.data.parse);
@@ -119,12 +120,14 @@ $(function() {
models.date = wv.date.model(config, { initial: initialDate });
models.map = wv.map.model(models, config);
models.link = wv.link.model(config);
+ models.anim = wv.anim.model(models, config);
models.link
.register(models.proj)
.register(models.layers)
.register(models.date)
.register(models.palettes)
- .register(models.map);
+ .register(models.map)
+ .register(models.anim);
models.link.load(state);
// HACK: Map needs to be created before the data download model
@@ -149,9 +152,7 @@ $(function() {
elapsed("ui");
// Create widgets
- ui.anim = wv.date.anim(models.date, ui.map, {
- debug: parameters.debug === "anim"
- });
+ ui.anim = wv.anim.ui(models.date, ui.map);
ui.proj = wv.proj.ui(models, config);
ui.sidebar = wv.layers.sidebar(models, config);
ui.activeLayers = wv.layers.active(models, ui, config);
@@ -166,8 +167,9 @@ $(function() {
ui.timeline.pan = wv.date.timeline.pan(models, config, ui);
ui.timeline.config = wv.date.timeline.config(models, config, ui);
ui.timeline.input = wv.date.timeline.input(models, config, ui);
- ui.timeline.rangeselect = wv.date.anim.rangeselect(models, config, ui);
- ui.timeline.widget = wv.date.anim.widget(models, config, ui);
+ ui.anim.rangeselect = wv.anim.rangeselect(models, config, ui);
+ ui.anim.widget = wv.anim.widget(models, config, ui);
+
ui.dateLabel = wv.date.label(models);
ui.dateWheels = wv.date.wheels(models, config);
}