Fix return from findLoadedTiles

Previously, the findInterimTiles method was returning undefined if the min x/y coord for a tile range was already in the lookup.  The return says it indicates whether all tiles for the given z are loaded.  This change corrects the return.

This change also reveals a misunderstanding of the tile range returned by `getTileRangeForExtentAndZ`.  The previous findInterimTiles method was treating max values as inclusive.  This is intuitive.  It looks like the method returns a range where max values are exclusive.
This commit is contained in:
Tim Schaub
2013-02-18 14:51:39 -07:00
parent ddf993f0c9
commit 6aa4e99fe5
2 changed files with 100 additions and 10 deletions

View File

@@ -75,12 +75,13 @@ ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ, z,
// FIXME this could be more efficient about filling partial holes
var fullyCovered = true;
var tile, tileCoord, tileCoordKey, x, y;
// TODO: tile range is misunderstood (inclusive or not?)
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y);
tileCoordKey = tileCoord.toString();
if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) {
return false; // TODO: fix this
continue;
}
tile = this.getTile(tileCoord);
if (!goog.isNull(tile) && tile.getState() == ol.TileState.LOADED) {

View File

@@ -30,8 +30,8 @@ describe('ol.source.TileSource', function() {
it('adds loaded tiles to the lookup (z: 0)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
'0/0/-1': true,
'1/0/-1': true
'0/0/0': true,
'1/0/0': true
});
var loadedTilesByZ = {};
@@ -40,7 +40,7 @@ describe('ol.source.TileSource', function() {
source.findLoadedTiles(loadedTilesByZ, 0, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(1);
var tile = loadedTilesByZ['0']['0/0/-1'];
var tile = loadedTilesByZ['0']['0/0/0'];
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.LOADED);
});
@@ -48,8 +48,8 @@ describe('ol.source.TileSource', function() {
it('adds loaded tiles to the lookup (z: 1)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
'0/0/-1': true,
'1/0/-1': true
'0/0/0': true,
'1/0/0': true
});
var loadedTilesByZ = {};
@@ -58,11 +58,100 @@ describe('ol.source.TileSource', function() {
source.findLoadedTiles(loadedTilesByZ, 1, range);
var keys = goog.object.getKeys(loadedTilesByZ);
expect(keys.length).toBe(1);
var tile = loadedTilesByZ['1']['1/0/-1'];
var tile = loadedTilesByZ['1']['1/0/0'];
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.LOADED);
});
it('returns true when all tiles are already loaded', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
// TODO: tile range is misunderstood
'1/0/0': true,
'1/0/1': true,
'1/0/2': true,
'1/1/0': true,
'1/1/1': true,
'1/1/2': true,
'1/2/0': true,
'1/2/1': true,
'1/2/2': true,
});
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var allLoaded = source.findLoadedTiles(loadedTilesByZ, 1, range);
expect(allLoaded).toBe(true);
});
it('returns true when all tiles are already loaded (part 2)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({});
var loadedTilesByZ = {
'1': {
'1/0/0': true,
'1/0/1': true,
'1/0/2': true,
'1/1/0': true,
'1/1/1': true,
'1/1/2': true,
'1/2/0': true,
'1/2/1': true,
'1/2/2': true,
}
};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var allLoaded = source.findLoadedTiles(loadedTilesByZ, 1, range);
expect(allLoaded).toBe(true);
});
it('returns false when all tiles are already loaded', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({
'1/0/0': true,
'1/0/1': true,
'1/0/2': true,
'1/1/0': true,
'1/1/1': false,
'1/1/2': true,
'1/2/0': true,
'1/2/1': true,
'1/2/2': true,
});
var loadedTilesByZ = {};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var allLoaded = source.findLoadedTiles(loadedTilesByZ, 1, range);
expect(allLoaded).toBe(false);
});
it('returns false when all tiles are already loaded (part 2)', function() {
// a source with no loaded tiles
var source = new ol.test.source.MockTileSource({});
var loadedTilesByZ = {
'1': {
'1/0/0': true,
'1/0/1': true,
'1/0/2': true,
'1/1/0': true,
'1/1/1': false,
'1/1/2': true,
'1/2/0': true,
'1/2/1': true,
'1/2/2': true,
}
};
var grid = source.getTileGrid();
var range = grid.getTileRangeForExtentAndZ(source.getExtent(), 1);
var allLoaded = source.findLoadedTiles(loadedTilesByZ, 1, range);
expect(allLoaded).toBe(false);
});
});
});
@@ -80,7 +169,7 @@ ol.test.source.MockTileSource = function(loaded) {
var tileGrid = new ol.tilegrid.TileGrid({
resolutions: [360 / 256, 180 / 256, 90 / 256, 45 / 256],
extent: extent,
origin: new ol.Coordinate(-180, 180),
origin: new ol.Coordinate(-180, -180),
tileSize: new ol.Size(256, 256)
});
@@ -127,7 +216,7 @@ describe('ol.test.source.MockTileSource', function() {
it('returns a tile with state based on constructor arg', function() {
var source = new ol.test.source.MockTileSource({
'0/0/0': true,
'1/0/-1': true
'1/0/0': true
});
var tile;
@@ -142,7 +231,7 @@ describe('ol.test.source.MockTileSource', function() {
expect(tile.state).toBe(ol.TileState.IDLE);
// check another loaded tile
tile = source.getTile(new ol.TileCoord(1, 0, -1));
tile = source.getTile(new ol.TileCoord(1, 0, 0));
expect(tile).toBeA(ol.Tile);
expect(tile.state).toBe(ol.TileState.LOADED);