Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-214: First attempt at backend for opacity

Mike McGann9d228f518182
diff --git a/ant/js.build.xml b/ant/js.build.xml
index aa6970ea3..71750101e 100644
--- a/ant/js.build.xml
+++ b/ant/js.build.xml
@@ -64,6 +64,7 @@
<file name="Worldview/Widget/Palette.js"/>
<file name="Worldview/Widget/WorldviewMap.js"/>
<file name="Worldview/Widget/ArcticProjectionChangeNotification.js"/>
+ <file name="Worldview/Widget/Opacity.js"/>
<file name="tour.js"/>
<file name="main.js"/>
diff --git a/index.html b/index.html
index 9c3531d3e..68ca3e7e0 100755
--- a/index.html
+++ b/index.html
@@ -114,6 +114,7 @@
<!-- js.dev --> <script type="text/javascript" src="js/Worldview/Widget/Palette.js"></script>
<!-- js.dev --> <script type="text/javascript" src="js/Worldview/Widget/WorldviewMap.js"></script>
<!-- js.dev --> <script type="text/javascript" src="js/Worldview/Widget/ArcticProjectionChangeNotification.js"></script>
+ <!-- js.dev --> <script type="text/javascript" src="js/Worldview/Widget/Opacity.js"></script>
<!-- js.dev --> <script type="text/javascript" src="js/tour.js"></script>
diff --git a/js/Worldview/Map/DailyProduct.js b/js/Worldview/Map/DailyProduct.js
index f69a5516c..3b1df14fd 100644
--- a/js/Worldview/Map/DailyProduct.js
+++ b/js/Worldview/Map/DailyProduct.js
@@ -101,6 +101,14 @@ Worldview.Map.DailyProduct = function(map, config) {
fetchLayer();
};
+ self.setOpacity = function(opacity) {
+ self.opacity = opacity;
+ currentLayer.setOpacity(opacity);
+ $.each(cachedLayers, function(key, layer) {
+ layer.setOpacity(opacity);
+ });
+ };
+
/**
* Method: setLookup
* Applies a lookup table to this product. If this product doesn't have
diff --git a/js/Worldview/Map/Product.js b/js/Worldview/Map/Product.js
index 3986a832f..c049c9fed 100644
--- a/js/Worldview/Map/Product.js
+++ b/js/Worldview/Map/Product.js
@@ -25,6 +25,7 @@ Worldview.namespace("Map");
Worldview.Map.Product = function(c) {
var self = {};
+ self.opacity = 1;
var config;
var init = function() {
@@ -81,6 +82,11 @@ Worldview.Map.Product = function(c) {
additionalParameters);
}
var layer;
+ if ( properties.opacity ) {
+ self.opacity = properties.opacity;
+ } else {
+ properties.opacity = self.opacity;
+ }
if ( config.type === "wms" ) {
layer = new Worldview.Map.TWMSLayer(config.name, config.url,
parameters, properties);
diff --git a/js/Worldview/Map/ProductMap.js b/js/Worldview/Map/ProductMap.js
index 4375c3187..dd8facdcf 100644
--- a/js/Worldview/Map/ProductMap.js
+++ b/js/Worldview/Map/ProductMap.js
@@ -188,6 +188,20 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
}
};
+ self.setOpacity = function(layerName, opacity) {
+ $.each(self.map.products, function(name, product) {
+ if ( name == layerName ) {
+ var value = parseFloat(opacity);
+ if ( isNaN(value) ) {
+ log.warn("Invalid opacity for layer " + layerName + ": " +
+ opacity);
+ } else {
+ product.setOpacity(value);
+ }
+ }
+ });
+ }
+
/**
* Method: set
* Set the products that should be displayed on the map.
diff --git a/js/Worldview/Map/StaticProduct.js b/js/Worldview/Map/StaticProduct.js
index 622d2cf95..895853d60 100644
--- a/js/Worldview/Map/StaticProduct.js
+++ b/js/Worldview/Map/StaticProduct.js
@@ -55,6 +55,11 @@ Worldview.Map.StaticProduct = function(map, config) {
self.setDay = function(d) {
};
+ self.setOpacity = function(opacity) {
+ self.opacity = opacity;
+ layer.setOpacity(opacity);
+ };
+
/**
* Method: setZIndex
* Sets the z-index for the product's layer.
diff --git a/js/Worldview/Permalink.js b/js/Worldview/Permalink.js
index be07562f4..57f7ffc2c 100644
--- a/js/Worldview/Permalink.js
+++ b/js/Worldview/Permalink.js
@@ -160,6 +160,10 @@ $(function() {
var palettes = Worldview.extractFromQuery("palettes", qs);
if ( palettes ) {
link += "&palettes=" + palettes;
+ }
+ var opacity = Worldview.extractFromQuery("opacity", qs);
+ if ( opacity ) {
+ link += "&opacity=" + opacity;
}
var url = window.location.href;
var prefix = url.split("?")[0];
diff --git a/js/Worldview/Widget/Opacity.js b/js/Worldview/Widget/Opacity.js
new file mode 100644
index 000000000..b1f089f7c
--- /dev/null
+++ b/js/Worldview/Widget/Opacity.js
@@ -0,0 +1,93 @@
+/*
+ * 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("Widget");
+
+Worldview.Widget.Opacity = function(config) {
+
+ var self = {};
+ var layers = {};
+ var log = Logging.getLogger("Worldview.Widget.Opacity");
+
+ self.containerId = "opacity";
+
+ var init = function() {
+ REGISTRY.register(self.containerId, self);
+ REGISTRY.markComponentReady(self.containerId);
+ };
+
+ var getConfigOpacity = function(layerName) {
+ var layer = config.products[layerName];
+ if ( layer && layer.properties ) {
+ if ( layer.properties.opacity === 0 || layer.properties.opacity ) {
+ return layer.properties.opacity;
+ }
+ }
+ return 1;
+ };
+
+ self.setLayer = function(layerName, value) {
+ layers[layerName] = value;
+ REGISTRY.fire(self);
+ };
+
+ self.getLayer = function(layerName) {
+ var opacity = layers[layerName];
+ if ( !opacity && opacity !== 0 ) {
+ opacity = getConfigOpacity(layerName);
+ }
+ if ( !opacity && opacity !== 0 ) {
+ opacity = 1;
+ }
+ return opacity;
+ };
+
+ self.getValue = function() {
+ var items = [];
+ $.each(layers, function(layerName, opacity) {
+ items.push(layerName + "," + opacity);
+ });
+ if ( items.length > 0 ) {
+ return self.containerId + "=" + items.join("~");
+ } else {
+ return "";
+ }
+ };
+
+ self.setValue = function(queryString) {
+ layers = {};
+ if ( !queryString ) {
+ return;
+ }
+ var items = queryString.split("~");
+ $.each(items, function(index, item) {
+ var parts = item.split(",");
+ var layerName = parts[0];
+ var opacity = parseFloat(parts[1]);
+ if ( isNaN(opacity) ) {
+ log.warn("Invalid opacity for " + layerName + ": " + parts[1]);
+ } else {
+ layers[layerName] = opacity;
+ }
+ });
+ REGISTRY.fire(self);
+ };
+
+ self.loadFromQuery = function(queryString) {
+ value = Worldview.extractFromQuery("opacity", queryString);
+ if ( value ) {
+ self.setValue(value);
+ }
+ };
+
+ init();
+ return self;
+}
diff --git a/js/Worldview/Widget/WorldviewMap.js b/js/Worldview/Widget/WorldviewMap.js
index 6118bd2a4..ccace9a8b 100644
--- a/js/Worldview/Widget/WorldviewMap.js
+++ b/js/Worldview/Widget/WorldviewMap.js
@@ -68,6 +68,8 @@ Worldview.Widget.WorldviewMap = function(containerId, config) {
state.products = splitProducts(state);
state.palettesString = state.palettes;
state.palettes = splitPalettes(state);
+ state.opacityString = state.opacity;
+ state.opacity = splitOpacity(state);
log.debug(state);
@@ -108,6 +110,11 @@ Worldview.Widget.WorldviewMap = function(containerId, config) {
if ( state.palettesString !== last.palettesString ) {
self.productMap.setPalettes(state.palettes);
}
+ if ( state.opacityString !== last.opacityString) {
+ $.each(state.opacity, function(layerName, opacity) {
+ self.productMap.setOpacity(layerName, opacity);
+ });
+ }
last = state;
last.queryString = queryString;
lastState[self.productMap.projection] = last;
@@ -192,6 +199,21 @@ Worldview.Widget.WorldviewMap = function(containerId, config) {
return results;
};
+ var splitOpacity = function(state) {
+ var results = {}
+ if ( !state.opacity ) {
+ return results;
+ }
+ var definitions = state.opacity.split("~");
+ $.each(definitions, function(index, definition) {
+ var items = definition.split(",");
+ var layerName = items[0];
+ var opacity = parseFloat(items[1]);
+ results[layerName] = opacity;
+ });
+ return results;
+ }
+
init();
return self;
}
diff --git a/js/main.js b/js/main.js
index 14b634099..8cb525293 100644
--- a/js/main.js
+++ b/js/main.js
@@ -55,6 +55,7 @@ $(function() {// Initialize "static" vars
rb = new SOTE.widget.RubberBand("camera",{icon:"images/camera.png",onicon:"images/cameraon.png",cropee:"map",paletteWidget:palettes,mapWidget:m});
var id = new SOTE.widget.ImageDownload("imagedownload",{baseLayer:"MODIS_Terra_CorrectedReflectance_TrueColor",alignTo: rb, m:m});
var apcn = new Worldview.Widget.ArcticProjectionChangeNotification(config, a);
+ var opacity = new Worldview.Widget.Opacity(config);
// Get rid of address bar on iphone/ipod
var fixSize = function() {
@@ -76,6 +77,7 @@ $(function() {// Initialize "static" vars
REGISTRY.addEventListener("selectorbox","products");
REGISTRY.addEventListener("camera","imagedownload");
REGISTRY.addEventListener("palettes","map","camera","products");
+ REGISTRY.addEventListener("opacity", "map");
/*REGISTRY.addEventListener("map","time");
REGISTRY.addEventListener("time","map");
@@ -84,6 +86,8 @@ $(function() {// Initialize "static" vars
REGISTRY.addEventListener("selectorbox","products");
//REGISTRY.addEventListener("hazard","products");*/
+ Worldview.opacity = opacity;
+
var queryString = Worldview.Permalink.decode(window.location.search.substring(1));
var initOrder = [
ss, // projection
@@ -91,7 +95,8 @@ $(function() {// Initialize "static" vars
map, // time
m, // map
palettes,
- apcn
+ apcn,
+ opacity
];
function testQS(){