Interactive interface for browsing global, full-resolution satellite imagery
WV-317: setVisiblity causes a layer reload which seems to always refetch the imagery on Chrome. Now using the opacity trick again, but the side-effect is that layers now always load when hidden
Mike McGann19423082a058
diff --git a/css/map.css b/css/map.cssindex 8acdadff8..28bb264b5 100644--- a/css/map.css+++ b/css/map.css@@ -182,7 +182,7 @@ div.olControlZoomPanelCustom .olControlZoomToMaxExtentItemInactive {right: 0px;}-.olLayerGridTile .olTileImage {+.olLayerGrid .olTileImage {-webkit-transition: none;-moz-transition: none;-o-transition: all 0 none;diff --git a/js/Worldview/Map.js b/js/Worldview/Map.jsindex 36a61fbf4..3234efd04 100644--- a/js/Worldview/Map.js+++ b/js/Worldview/Map.js@@ -117,4 +117,9 @@ $(function(ns) {}}+ ns.setVisibility = function(layer, visible, opacity) {+ var actualOpacity = ( visible ) ? opacity : 0;+ layer.div.style.opacity = actualOpacity;+ }+}(Worldview.Map));diff --git a/js/Worldview/Map/DailyProduct.js b/js/Worldview/Map/DailyProduct.jsindex bfd902e40..cd273a079 100644--- a/js/Worldview/Map/DailyProduct.js+++ b/js/Worldview/Map/DailyProduct.js@@ -54,9 +54,6 @@ Worldview.Map.DailyProduct = function(map, config) {// The day of the data displayed on the mapvar currentDay;- // Is this product visible on the map?- var visible = true;-// Active lookup table for all layers in the product, null if no table// is activevar lookupTable = null;@@ -64,8 +61,8 @@ Worldview.Map.DailyProduct = function(map, config) {// Timeout identifier for the reaper that cleans out stale layers.var reaperId = null;- // Time, in seconds, to wait before reaping stale layers.- var reapDelay = 2000;+ // Time, in milliseconds, to wait before reaping stale layers.+ var reapDelay = 500;//-------------------------------------------------------------------------// Public@@ -74,8 +71,9 @@ Worldview.Map.DailyProduct = function(map, config) {var init = function() {self.setDay(Worldview.today());- map.events.register("movestart", self, onMoveStart);- map.events.register("zoomend", self, onZoomEnd);+ map.events.register("movestart", self, clearCache);+ map.events.register("zoomend", self, clearCache);+ $(window).resize(clearCache);};/**@@ -106,18 +104,12 @@ Worldview.Map.DailyProduct = function(map, config) {self.setOpacity = function(opacity) {self.opacity = opacity;- Worldview.Map.setOpacity(currentLayer, opacity);- $.each(cachedLayers, function(key, layer) {- Worldview.Map.setOpacity(layer, opacity);- });+ Worldview.Map.setVisiblity(currentLayer, self.visible, self.opacity);};- self.setVisibility = function(value) {- visible = value;- currentLayer.setVisibility(value);- $.each(cachedLayers, function(key, layer) {- layer.setVisibility(value);- });+ self.setVisibility = function(visible) {+ self.visible = visible;+ Worldview.Map.setVisibility(currentLayer, self.visible, self.opacity);};/**@@ -178,8 +170,9 @@ Worldview.Map.DailyProduct = function(map, config) {if ( reaperId !== null ) {clearTimeout(reaperId);}- map.events.unregister("movestart", self, onMoveStart);- map.events.unregister("zoomend", self, onZoomEnd);+ map.events.unregister("movestart", self, clearCache);+ map.events.unregister("zoomend", self, clearCache);+ $(window).unbind("resize", clearCache);};//-------------------------------------------------------------------------@@ -189,13 +182,14 @@ Worldview.Map.DailyProduct = function(map, config) {var fetchLayer = function() {var previousLayer = currentLayer;- // If a layer was visible, hide it.- if ( previousLayer ) {- previousLayer.div.style.opacity = 0;- }-+ if ( previousLayer ) {+ Worldview.Map.setVisibility(previousLayer, false, 0);+ }+if ( currentDay in cachedLayers ) {currentLayer = cachedLayers[currentDay];+ Worldview.Map.setVisibility(currentLayer, self.visible,+ self.opacity);delete cachedLayers[currentDay];} else {var additionalOptions = {};@@ -207,23 +201,15 @@ Worldview.Map.DailyProduct = function(map, config) {});if ( lookupTable !== null ) {currentLayer.lookupTable = lookupTable;- }- currentLayer.div.style.opacity = 0;-- // If this layer is not visible, set that now to prevent tiles- // from loading- currentLayer.setVisibility(visible);+ }map.addLayer(currentLayer);}-- // The visible layer is one level higher than all the other layers+if ( previousLayer ) {previousLayer.setZIndex(zIndex);}currentLayer.setZIndex(zIndex + 1);-- currentLayer.div.style.opacity = currentLayer.opacity;- currentLayer.setVisibility(visible);+ Worldview.Map.setVisibility(currentLayer, self.visible, self.opacity);};/*@@ -264,6 +250,10 @@ Worldview.Map.DailyProduct = function(map, config) {* to the stale set. Restart the reaper to remove those layers.*/var clearCache = function() {+ if ( $.isEmptyObject(cachedLayers) ) {+ return;+ }+ console.log("clear cache");$.each(cachedLayers, function(day, layer) {staleLayers.push(layer);});@@ -289,15 +279,7 @@ Worldview.Map.DailyProduct = function(map, config) {refreshZOrder();reaperId = null;};-- var onMoveStart = function() {- clearCache();- };- var onZoomEnd = function() {- clearCache();- };-init();return self;}diff --git a/js/Worldview/Map/Product.js b/js/Worldview/Map/Product.jsindex c049c9fed..d3398cd90 100644--- a/js/Worldview/Map/Product.js+++ b/js/Worldview/Map/Product.js@@ -26,6 +26,7 @@ Worldview.Map.Product = function(c) {var self = {};self.opacity = 1;+ self.visible = true;var config;var init = function() {@@ -87,6 +88,7 @@ Worldview.Map.Product = function(c) {} else {properties.opacity = self.opacity;}+ properties.visiblity = false;if ( config.type === "wms" ) {layer = new Worldview.Map.TWMSLayer(config.name, config.url,parameters, properties);@@ -101,6 +103,7 @@ Worldview.Map.Product = function(c) {} else {throw new Error("Unsupported layer type: " + config.type);}+return layer;};diff --git a/js/Worldview/Map/StaticProduct.js b/js/Worldview/Map/StaticProduct.jsindex ac2ca78d4..e3745f0c4 100644--- a/js/Worldview/Map/StaticProduct.js+++ b/js/Worldview/Map/StaticProduct.js@@ -57,11 +57,12 @@ Worldview.Map.StaticProduct = function(map, config) {self.setOpacity = function(opacity) {self.opacity = opacity;- Worldview.Map.setOpacity(layer, opacity);+ Worldview.Map.setVisibility(layer, self.visible, self.opacity);};- self.setVisibility = function(value) {- layer.setVisibility(value);+ self.setVisibility = function(visible) {+ self.visible = visible;+ Worldview.Map.setVisibility(layer, self.visible, self.opacity);};/**