Interactive interface for browsing global, full-resolution satellite imagery
WV-568: Granule footprints now working properly
Mike McGannedeb9556ca1b
diff --git a/src/js/Logging.js b/src/js/Logging.jsindex ecb318d20..d67c7031e 100644--- a/src/js/Logging.js+++ b/src/js/Logging.js@@ -1,67 +1,67 @@/** NASA Worldview- *+ ** This code was originally developed at NASA/Goddard Space Flight Center for- * the Earth Science Data and Information System (ESDIS) project.+ * the Earth Science Data and Information System (ESDIS) project.*- * Copyright (C) 2013 United States Government as represented by the+ * Copyright (C) 2013 United States Government as represented by the* Administrator of the National Aeronautics and Space Administration.* All Rights Reserved.*//**- * Simple logging utility.- *+ * Simple logging utility.+ ** Example:- *+ ** var log = Logging.getLogger()* log.message("This is a message");- *+ ** Debug messages can be turned on or off:- *+ ** var log = Logger.getLogger()* log.debug("This is not printed");- *+ ** Logging.debug();* log.debug("This is printed");- *+ ** Logging.undebug();* log.debug("This is not printed");- *+ ** Assign names to loggers:- *+ ** var logA = Logger.getLogger("A");* var logB = Logger.getLogger("B");* Logging.debug("B");* logA.debug("This is not printed");* logB.debug("This is printed");- *+ ** There is no hierarchy of loggers as in log4j. Turning on debug logging* for a given name only enables loggers that exactly match that name.- *+ ** This delgates to the corresponding console methods if available, otherwise* it delgates to console.log. If console is not defined, nothing is* printed out.- *+ ** @module Logging* @class Logging* @static*/(function(ns) {-+var loggers = {};var debugAll = false;-+/*** Gets the logger with the specified name. If a logger with that name* does not exist, one is created.- *+ ** @method getLogger* @static- *- * @param name {String} Name of the logger to get. If not specified, the- * unnamed loggeris returned.- *+ *+ * @param name {String} Name of the logger to get. If not specified, the+ * unnamed loggeris returned.+ ** @return {Logger} The Logger for the given name.*/ns.getLogger = function(name) {@@ -77,16 +77,16 @@logger.setDebugEnabled(true);}return logger;- }-+ };+/*** Turns on logging of debug messages.- *+ ** @method debug* @static- *- * @param name {String} If specified, this enables debug logging for the- * Logger with the given name. If not specified, this enables debug+ *+ * @param name {String} If specified, this enables debug logging for the+ * Logger with the given name. If not specified, this enables debug* logging for all Loggers.*/ns.debug = function(name) {@@ -99,13 +99,13 @@debugAll = true;}};-+/*** Turns off logging of debug messages.- *+ ** @method undebug* @static- *+ ** @param name {string} If specified, this disables logging for the Logger* with the given name. If not specified, this disables debug logging* for all Loggers.@@ -119,106 +119,106 @@});debugAll = false;}- };-+ };+/** Clears out all the known loggers, useful for testing.*/ns.reset = function() {- loggers = {}- }-+ loggers = {};+ };+/*** Logging methods.- *+ ** @class Logger* @for Logging- */+ */var Logger = function() {var self = {};var debugEnabled = false;-+/*** Prints an error message to the console. Uses console.log or does* nothing if console does not exist.- *+ ** @method message* @for Logger- *+ ** @param [message]* {object} The message to print to the console.*/- self.message = ( !window.console || !window.console.log )+ self.message = ( !window.console || !window.console.log )? function() {} : console.log.bind(console);-+/*** Prints an error message to the console. Uses console.error if* it exists, otherwise uses console.log. Does nothing if console* does not exist.- *+ ** @method error* @for Logger- *+ ** @param [message]* {object} The message to print to the console.*/- self.error = ( !window.console || !window.console.error )+ self.error = ( !window.console || !window.console.error )? self.message: console.error.bind(console);/*** Prints an warning message to the console. Uses console.warn if* it exists, otherwise uses console.log. Does nothing if console* does not exist.- *+ ** @method warn* @for Logger- *+ ** @param [message]* {object} The message to print to the console.*/- self.warn = ( !window.console || !window.console.warn )+ self.warn = ( !window.console || !window.console.warn )? self.message : console.warn.bind(console);-+/*** Prints an information message to the console. Uses console.info if* it exists, otherwise uses console.log. Does nothing if console* does not exist.- *+ ** @method info* @for Logger- *+ ** @param [message]* {object} The message to print to the console.*/- self.info = ( !window.console || !window.console.info )+ self.info = ( !window.console || !window.console.info )? self.message : console.info.bind(console);-+/*** Prints a stack trace to the console. If console.trace does not* exist, this method does nothing.- *+ ** @method trace* @for Logger*/self.trace = ( !window.console || !window.console.trace )? function() {} : console.trace;-+/*** Prints a debug message to the console if debugging is enabled.* Debugging can be enabled by calling Logging.debug with the name- * of this logger, by calling Logging.debug with no parameters,- * or by calling setDebugEnabled on this logger. If the console object+ * of this logger, by calling Logging.debug with no parameters,+ * or by calling setDebugEnabled on this logger. If the console object* does not exist, this method does nothing.- *+ ** @method debug* @for Logger** @param [message]* {object} The message to print to the console.*/self.debug = function() {};-+/*** Enables or disables logging of debug messages.- *+ ** @method setDebugEnabled- *+ ** @param enabled {boolean} If true, enables debug messages.*/self.setDebugEnabled = function(enabled) {@@ -229,20 +229,20 @@}debugEnabled = enabled;};-+/*** Indicates if logging messages are enabled.- *+ ** @method isDebugEnabled- *- * @return {boolean} True if debug messages will be printed to the+ *+ * @return {boolean} True if debug messages will be printed to the* console, otherwise returns false.*/self.isDebugEnabled = function() {return debugEnabled;- }-- return self;+ };++ return self;};-+}(window.Logging = window.Logging || {}));diff --git a/src/js/Worldview/DataDownload/Layers/Selection.js b/src/js/Worldview/DataDownload/Layers/Selection.jsindex 948c352a9..1b83bfffc 100644--- a/src/js/Worldview/DataDownload/Layers/Selection.js+++ b/src/js/Worldview/DataDownload/Layers/Selection.js@@ -1,10 +1,10 @@/** NASA Worldview- *+ ** This code was originally developed at NASA/Goddard Space Flight Center for- * the Earth Science Data and Information System (ESDIS) project.+ * the Earth Science Data and Information System (ESDIS) project.*- * Copyright (C) 2013 United States Government as represented by the+ * Copyright (C) 2013 United States Government as represented by the* Administrator of the National Aeronautics and Space Administration.* All Rights Reserved.*/@@ -13,82 +13,94 @@ Worldview.namespace("DataDownload.Layers");Worldview.DataDownload.Layers.Selection = function(model, maps, config) {var LAYER_NAME = "DataDownload_Selection";+ var log = Logging.getLogger("Worldview.DataDownload");- var OPACITY = 0.6;+ var OPACITY = 0.6;var STYLE = {strokeColor: "#808080",fillColor: "#808080",};-+var self = {};var features = {};-+var init = function() {model.events.on("granuleSelect", onGranuleSelect)- .on("granuleUnselect", onGranuleUnselect);+ .on("granuleUnselect", onGranuleUnselect);};-+self.clear = function() {+ log.debug("clear");var layer = Worldview.Map.getLayerByName(maps.map, LAYER_NAME);if ( layer ) {layer.removeAllFeatures();}};-+self.dispose = function() {+ log.debug("dispose");$.each(maps.projections, function(index, map) {var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);if ( layer ) {- map.removeLayer(layer);- }- });+ map.removeLayer(layer);+ }+ });};-+var onGranuleSelect = function(granule) {if ( !granule.geometry ) {return;}var geom = granule.geometry[model.crs];- var extent =+ var extent =config.projections[model.projection].maxExtent.toGeometry();if ( geom && extent.intersects(geom) ) {+ // Exit if already selected+ if ( features[granule.id] ) {+ return;+ }var feature = new OpenLayers.Feature.Vector(geom.clone());features[granule.id] = feature;getLayer().addFeatures([feature]);+ log.debug("select", getLayer().features.length, granule, feature);}};--++var onGranuleUnselect = function(granule) {if ( !granule.geometry ) {return;}var feature = features[granule.id];- getLayer().removeFeatures([feature]);+ getLayer().removeFeatures([feature]);+ getLayer().redraw();+ delete features[granule.id];+ log.debug("unselect", getLayer().features.length, granule, feature);};-- var createLayer = function() {++ var createLayer = function() {layer = new OpenLayers.Layer.Vector(LAYER_NAME, {styleMap: new OpenLayers.StyleMap(STYLE)});layer.div.setAttribute("data-layer-name", LAYER_NAME);layer.setOpacity(OPACITY);maps.map.addLayer(layer);-- return layer;++ return layer;};-+var getLayer = function(map) {map = map || maps.map;var layer = Worldview.Map.getLayerByName(map, LAYER_NAME);if ( !layer ) {+ log.debug("createlayer");layer = createLayer();}return layer;};-+init();return self;-+};\ No newline at end of filediff --git a/src/js/Worldview/DataDownload/MapController.js b/src/js/Worldview/DataDownload/MapController.jsindex 36a3e4a54..9559eb1ff 100644--- a/src/js/Worldview/DataDownload/MapController.js+++ b/src/js/Worldview/DataDownload/MapController.js@@ -1,38 +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.+ * the Earth Science Data and Information System (ESDIS) project.*- * Copyright (C) 2013 United States Government as represented by the+ * Copyright (C) 2013 United States Government as represented by the* Administrator of the National Aeronautics and Space Administration.* All Rights Reserved.*/Worldview.namespace("DataDownload");Worldview.DataDownload.MapController = function(model, maps, config) {-+var ns = Worldview.DataDownload;var log = Logging.getLogger("Worldview.DataDownload");-+var self = {};var results = [];-+var selectionLayers = ns.Layers.Selection(model, maps, config);var swathLayers = ns.Layers.Swath(model, maps, config);var gridLayers = ns.Layers.Grid(model, maps, config);- var hoverLayers = ns.Layers.Hover(model, maps, config);+ var hoverLayers = ns.Layers.Hover(model, maps, config);var buttonLayers = ns.Layers.Button(model, maps, config);// TODO: Remove if not used// var maskLayers = ns.Layers.QueryMask(model, maps, config);-- var init = function() {++ var init = function() {model.events.on("query", clear).on("queryResults", onQueryResults).on("projectionUpdate", onProjectionUpdate).on("deactivate", onDeactivate);-+buttonLayers.events.on("hoverover", function(event) {hoverLayers.hoverOver(event.feature);@@ -41,11 +41,11 @@ Worldview.DataDownload.MapController = function(model, maps, config) {hoverLayers.hoverOut();});};-+var onQueryResults = function(newResults) {update(newResults);};-+var update = function(newResults) {if ( newResults ) {results = newResults;@@ -53,15 +53,15 @@ Worldview.DataDownload.MapController = function(model, maps, config) {swathLayers.update(results);gridLayers.update(results);buttonLayers.update(results);-+// TODO: Remove if not used//maskLayers.update(results);};-+var onProjectionUpdate = function() {update();};-+var onDeactivate = function() {selectionLayers.dispose();swathLayers.dispose();@@ -71,17 +71,17 @@ Worldview.DataDownload.MapController = function(model, maps, config) {// TODO: Remove if not used//maskLayers.dispose();};-+var clear = function() {- selectionLayers.clear();+ //selectionLayers.clear();swathLayers.clear();gridLayers.clear();hoverLayers.clear();buttonLayers.clear();- // TODO: Remove if not used+ // TODO: Remove if not used//maskLayers.clear();};-+init();return self;};