Skip to content

Commit

Permalink
TileAnimation: Fix error thrown if map unset during preloading
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
Edan Schwartz committed Aug 7, 2014
1 parent 8231f70 commit 0940d88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/maps/animations/tileanimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down
22 changes: 19 additions & 3 deletions tests/spec/aeris/maps/animations/tileanimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,11 @@ define([
});

function loadAll(timeLayers) {
_.each(timeLayers, function(lyr) {
lyr.promiseToPreload.resolve();
});
_.each(timeLayers, loadLayer);
}

function loadLayer(layer) {
layer.promiseToPreload.resolve();
}


Expand Down Expand Up @@ -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);
});

});

});


Expand Down

0 comments on commit 0940d88

Please sign in to comment.