Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Added indicator, refactored Preloader to be a generic class

Mike McGanne783c370b8ce
diff --git a/etc/ant/css.build.xml b/etc/ant/css.build.xml
index a238490b8..fa8ba7229 100644
--- a/etc/ant/css.build.xml
+++ b/etc/ant/css.build.xml
@@ -37,6 +37,7 @@
<file name="css/products.css"/>
<file name="css/pages.css"/>
<file name="css/about.css"/>
+ <file name="css/indicator.css"/>
</filelist>
diff --git a/etc/ant/js.build.xml b/etc/ant/js.build.xml
index 9763c87a8..f5f396c87 100644
--- a/etc/ant/js.build.xml
+++ b/etc/ant/js.build.xml
@@ -67,6 +67,7 @@
<file name="js/Worldview/Scheduler.js"/>
<file name="js/Worldview/Preloader.js"/>
<file name="js/Worldview/Events.js"/>
+ <file name="js/Worldview/Indicator.js"/>
<file name="js/Worldview/Palette.js"/>
<file name="js/Worldview/Palette/ColorBar.js"/>
diff --git a/src/css/indicator.css b/src/css/indicator.css
new file mode 100644
index 000000000..9e742aefd
--- /dev/null
+++ b/src/css/indicator.css
@@ -0,0 +1,38 @@
+/*
+ * 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 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+#indicator {
+ border-radius: 10px;
+ border: 1px solid #404040;
+ position: absolute;
+ z-index: 10000;
+ background: #262b31;
+ color: #ffffff;
+ width: 200px;
+ height: 52px;
+ left: 50%;
+ top: 150px;
+ margin: -75px 0 0 -75px;
+ text-align: center;
+}
+
+#indicator img {
+ margin: 10px 10px 10px 0;
+ width: 32px;
+ height: 32px;
+ vertical-align: middle;
+}
+
+#indicator .message {
+ margin: 10px;
+ vertical-align: middle;
+ font-weight: bold;
+}
diff --git a/src/images/activity.gif b/src/images/activity.gif
new file mode 100644
index 000000000..4425cc181
Binary files /dev/null and b/src/images/activity.gif differ
diff --git a/src/images/red-x.svg b/src/images/red-x.svg
new file mode 100644
index 000000000..ae09c7c56
--- /dev/null
+++ b/src/images/red-x.svg
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 48 48" width="4pc" height="4pc"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>2013-06-20 15:19Z</dc:date><!-- Produced by OmniGraffle Professional 5.4.3 --></metadata><defs><filter id="Shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" result="blur" stdDeviation="3.488"/><feOffset in="blur" result="offset" dx="0" dy="4"/><feFlood flood-color="black" flood-opacity=".75" result="flood"/><feComposite in="flood" in2="offset" operator="in"/></filter><font-face font-family="Helvetica" font-size="48" units-per-em="1000" underline-position="-75.683594" underline-thickness="49.316406" slope="0" x-height="532.22656" cap-height="719.72656" ascent="770.01953" descent="-229.98047" font-weight="bold"><font-face-src><font-face-name name="Helvetica-Bold"/></font-face-src></font-face></defs><g stroke="none" stroke-opacity="1" stroke-dasharray="none" fill="none" fill-opacity="1"><title>Canvas 1</title><g><title>Layer 1</title><g><use xl:href="#id3_Graphic" filter="url(#Shadow)"/></g><g id="id3_Graphic"><text transform="translate(7.5 -5)" fill="red"><tspan font-family="Helvetica" font-size="48" font-weight="bold" fill="red" x=".4921875" y="47" textLength="32.015625">X</tspan></text></g></g></g></svg>
diff --git a/src/index.html b/src/index.html
index 9bb9829f2..4275afe07 100644
--- a/src/index.html
+++ b/src/index.html
@@ -57,6 +57,7 @@
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/splash.css" />
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/products.css" />
<!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/about.css" />
+ <!-- link.dev --> <link type="text/css" rel="Stylesheet" href="css/indicator.css" />
<!-- JavaScript resources ============================================= -->
<!-- link.prod --> <!-- <script type="text/javascript" src="js/worldview-min.js?v=@BUILD_NONCE@&mobile"></script> -->
@@ -127,6 +128,7 @@
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Permalink.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Preloader.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Events.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/Worldview/Indicator.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Palette.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Palette/ColorBar.js"></script>
@@ -166,7 +168,7 @@
<li class='toolbar-icon'><div id='camera'></div></li>
<li class='toolbar-icon'><div id="switch"></div></li>
<li class='toolbar-icon'><a id='perma_link' class='toolbar-link' title='Permalink' href='javascript:Worldview.Permalink.show();'><img src='images/permalink.png' /></a></li>
- <li class='toolbar-icon'><div class='DataDownload_ModeButton'></div></li>
+ <li class='toolbar-icon'><div class='dataDownload-modeButton'></div></li>
</ul>
</div>
diff --git a/src/js/Worldview/Indicator.js b/src/js/Worldview/Indicator.js
new file mode 100644
index 000000000..f1e5f5129
--- /dev/null
+++ b/src/js/Worldview/Indicator.js
@@ -0,0 +1,89 @@
+/*
+ * 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 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+Worldview.namespace("Indicator");
+
+/**
+ * Displays an indicator on the screen.
+ *
+ * The indicator has an image and text associated with it. Use show to
+ * display and hide to remove. Example:
+ *
+ * Worldview.Indicator.show("Please Wait", "images/wait.png");
+ *
+ * Only one indicator can be visibile at a time. If show is called while
+ * another indicator is already active, it will be replaced.
+ *
+ * @module Worldview
+ * @class Indicator
+ * @static
+ */
+$(function() {
+
+ var ns = Worldview.Indicator;
+
+ /**
+ * Shows the indicator with a message and an icon. If another indicator
+ * is already active, this call will replace the other one.
+ *
+ * @method show
+ * @static
+ *
+ * @param message {string} The message to display
+ * @param icon {string} URL to the icon to display
+ */
+ ns.show = function(message, icon) {
+ ns.hide();
+ $("body").append([
+ "<div id='indicator'>",
+ "<img src='" + icon + "'></img>",
+ "<span>" + message + "</span>",
+ "</div>"
+ ].join("\n"));
+ };
+
+ /**
+ * Hides the indicator. If no indicator is displayed, this method does
+ * nothing.
+ *
+ * @method hide
+ * @static
+ */
+ ns.hide = function() {
+ $("#indicator").remove();
+ };
+
+ /**
+ * Displays a "Searching" indicator. This is a convenience method for:
+ *
+ * Worldview.Indicator.show("Searching", "images/activity.gif")
+ *
+ * @method searching
+ * @static
+ */
+ ns.searching = function() {
+ ns.show("Searching", "images/activity.gif");
+ };
+
+ /**
+ * Displays a "No data available" indicator. This is a convenience method
+ * for:
+ *
+ * Worldview.Indicator.show("No data available", "images/red-x.svg")
+ *
+ * @method noData
+ * @static
+ */
+ ns.noData = function() {
+ ns.show("No data avaialble", "images/red-x.svg");
+ };
+
+});
diff --git a/src/js/Worldview/Preloader.js b/src/js/Worldview/Preloader.js
index c2583d455..dd640d885 100644
--- a/src/js/Worldview/Preloader.js
+++ b/src/js/Worldview/Preloader.js
@@ -10,36 +10,69 @@
*/
/**
- * Namespace: Worldview.Preloader
+ * @module Worldview
+ */
+
+/**
+ * Preloads resources (images, JSON files). This is a light wrapper around
+ * the PreloadJS library (http://www.createjs.com/#!/PreloadJS). The object is
+ * created with a manifest of resources that need to be preloaded. Invoke
+ * execute to start loading. An optional callback passed into execute will be
+ * invoked once all the resources have been loaded.
+ *
+ * Example:
+ *
+ * var preloader = Worldview.Preloader([
+ * "images/foo.png",
+ * {id: "bar", src: "data/bar", type:"json"}
+ * ]);
+ * preloader.execute(function() {
+ * console.log("Ready!");
+ * });
+ *
+ * @class Preloader
+ * @constructor Preloader
+ *
+ * @param manifest {Array(Object)} Array of items to preload. See
+ * http://www.createjs.com/Docs/PreloadJS/classes/LoadQueue.html for the
+ * format of the manifest.
*/
Worldview.namespace("Preloader");
-Worldview.Preloader.init = function(callback) {
+Worldview.Preloader = function(manifest) {
+ var self = {};
var queue = new createjs.LoadQueue();
+ var invoked = false;
- var onComplete = function() {
- callback(queue);
- };
+ var notify = function(callback) {
+ if ( callback ) {
+ callback(queue);
+ }
+ }
- queue.addEventListener("complete", onComplete);
+ /**
+ * Loads resources provided in the mainfest. If this method has already
+ * been called, no resources are loaded and the callback, if provided,
+ * is invoked immediately.
+ *
+ * @method execute
+ * @param callback {function} Function that accepts one argument, the
+ * createjs.LoadQueue object used to load the resources. This function
+ * is called once the load is complete, or if this method has already
+ * been invoked, is called immediately.
+ */
+ self.execute = function(callback) {
+ if ( invoked ) {
+ notify(callback);
+ return;
+ }
+ invoked = true;
+ queue.addEventListener("complete", function() {
+ notify(callback);
+ })
+ queue.loadManifest(manifest);
+ }
- queue.loadManifest([
- { id: "config", src: "data/config", type:"json" },
- "images/logo.png",
- "images/permalink.png",
- "images/geographic.png",
- "images/arctic.png",
- "images/antarctic.png",
- "images/camera.png",
- "images/cameraon.png",
- "images/information.png",
- "images/expandIn.png",
- "images/expandOut.png",
- "images/visible.png",
- "images/invisible.png",
- "images/close-red-x.png",
- "images/collapseDown.png",
- "images/expandUp.png"
- ]);
-};
+ return self;
+}
diff --git a/src/js/Worldview/Widget/DataDownload.js b/src/js/Worldview/Widget/DataDownload.js
index 76c9e8c64..c75a66eff 100644
--- a/src/js/Worldview/Widget/DataDownload.js
+++ b/src/js/Worldview/Widget/DataDownload.js
@@ -33,6 +33,10 @@ Worldview.Widget.DataDownload = function(model, config, spec) {
var HTML_WIDGET_INACTIVE = "<img src='images/camera.png'></img>";
var HTML_WIDGET_ACTIVE = "<img src='images/cameraon.png'></img>";
+ var preloader = Worldview.Preloader([
+ "images/activity.gif"
+ ]);
+
var init = function() {
model.events.on("activate", onActivate);
model.events.on("deactivate", onDeactivate);
@@ -45,15 +49,19 @@ Worldview.Widget.DataDownload = function(model, config, spec) {
}
var onActivate = function() {
- $(spec.selector).html(HTML_WIDGET_ACTIVE);
+ $(spec.selector).html(HTML_WIDGET_ACTIVE);
+ preloader.execute(function() {
+ Worldview.Indicator.searching();
+ });
};
var onDeactivate = function() {
$(spec.selector).html(HTML_WIDGET_INACTIVE);
- }
+ Worldview.Indicator.hide();
+ };
init();
return self;
};
-
+
diff --git a/src/js/main.js b/src/js/main.js
index e501140b9..2e2f40b60 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -65,7 +65,24 @@ $(function() {// Initialize "static" vars
Worldview.notify(html);
});
- Worldview.Preloader.init(onLoad);
+ Worldview.Preloader([
+ { id: "config", src: "data/config", type:"json" },
+ "images/logo.png",
+ "images/permalink.png",
+ "images/geographic.png",
+ "images/arctic.png",
+ "images/antarctic.png",
+ "images/camera.png",
+ "images/cameraon.png",
+ "images/information.png",
+ "images/expandIn.png",
+ "images/expandOut.png",
+ "images/visible.png",
+ "images/invisible.png",
+ "images/close-red-x.png",
+ "images/collapseDown.png",
+ "images/expandUp.png"
+ ]).execute(onLoad);
};
var init = function(config) {
@@ -112,7 +129,7 @@ $(function() {// Initialize "static" vars
var dataDownloadModel = Worldview.DataDownload.Model();
var dataDownloadWidget =
Worldview.Widget.DataDownload(dataDownloadModel, config, {
- selector: ".DataDownload_ModeButton"
+ selector: ".dataDownload-modeButton"
});
// Get rid of address bar on iphone/ipod