From 0940d88c53671942f5d1e88dd542b8ba73b15e46 Mon Sep 17 00:00:00 2001 From: Edan Schwartz Date: Thu, 7 Aug 2014 09:27:08 -0500 Subject: [PATCH] TileAnimation: Fix error thrown if map unset during preloading - A layer cannot preload without a map. So when the masterLayer's map was unset, layer.preload threw and error. Fixed this by caching the masterLayer's map when preloading starts. Calling TileAnimation#preload with no map set to begin with will still throw an error (expected behavior). --- src/maps/animations/tileanimation.js | 6 +++-- .../aeris/maps/animations/tileanimation.js | 22 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/maps/animations/tileanimation.js b/src/maps/animations/tileanimation.js index e6bc7fe2..e149f907 100644 --- a/src/maps/animations/tileanimation.js +++ b/src/maps/animations/tileanimation.js @@ -156,7 +156,7 @@ define([ */ TileAnimation.prototype.preload = function() { var promiseToPreload = new Promise(); - + var mapToUseForPreloading = this.masterLayer_.getMap(); // We need our times (and timeLayers) // to be loaded, before we can preload layers @@ -165,7 +165,9 @@ define([ var layers = _.values(this.timeLayers_); // Preload each layer in sequece - Promise.sequence(layers, this.preloadLayer_.bind(this)). + Promise.sequence(layers, function(layer) { + return layer.preload(mapToUseForPreloading); + }). done(promiseToPreload.resolve). fail(promiseToPreload.reject); }, this). diff --git a/tests/spec/aeris/maps/animations/tileanimation.js b/tests/spec/aeris/maps/animations/tileanimation.js index fb618963..cf95bf2e 100644 --- a/tests/spec/aeris/maps/animations/tileanimation.js +++ b/tests/spec/aeris/maps/animations/tileanimation.js @@ -677,9 +677,11 @@ define([ }); function loadAll(timeLayers) { - _.each(timeLayers, function(lyr) { - lyr.promiseToPreload.resolve(); - }); + _.each(timeLayers, loadLayer); + } + + function loadLayer(layer) { + layer.promiseToPreload.resolve(); } @@ -745,6 +747,20 @@ define([ expect(onReject).toHaveBeenCalled(); }); + describe('if the masterLayer\'s map is unset during preloading', function() { + + it('should continue to use the original map object for preloading', function() { + masterLayer.setMap(map); + animation.preload(); + + masterLayer.setMap(null); + loadLayer(timeLayers[0]); + + expect(timeLayers[1].preload).toHaveBeenCalledWith(map); + }); + + }); + });