From cb12063bc8434ccab69592350f06e2b6b8788976 Mon Sep 17 00:00:00 2001 From: Kogis IWI Date: Fri, 18 Nov 2016 15:58:31 +0100 Subject: [PATCH] Fix initial set of tiles to load --- Source/Scene/QuadtreePrimitive.js | 2 +- Source/Scene/QuadtreeTile.js | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Source/Scene/QuadtreePrimitive.js b/Source/Scene/QuadtreePrimitive.js index 702f2ec6bc21..a3a2bc886156 100644 --- a/Source/Scene/QuadtreePrimitive.js +++ b/Source/Scene/QuadtreePrimitive.js @@ -411,7 +411,7 @@ define([ if (terrainProvider && terrainProvider._availableLevels && terrainProvider._rectangle) { var level = terrainProvider._availableLevels[0]; primitive._levelZeroTiles = QuadtreeTile.createMinimumLevelTiles(tilingScheme, - level, terrainProvider._rectangle); + level, terrainProvider); } else { primitive._levelZeroTiles = QuadtreeTile.createLevelZeroTiles(tilingScheme); } diff --git a/Source/Scene/QuadtreeTile.js b/Source/Scene/QuadtreeTile.js index fd002d0dff4d..b6fd1c66bb02 100644 --- a/Source/Scene/QuadtreeTile.js +++ b/Source/Scene/QuadtreeTile.js @@ -144,11 +144,11 @@ define([ * * @param {TilingScheme} tilingScheme The tiling scheme for which the tiles are to be created. * @param {Number} level The minimum level to display. - * @param {Recatngle} rectangle The area to display. + * @param {CesiumTerrainProvider} rectangle The area to display. * @returns {QuadtreeTile[]} An array containing the tiles at minimum level of detail, starting with the * tile in the northwest corner and followed by the tile (if any) to its east of the area. */ - QuadtreeTile.createMinimumLevelTiles = function(tilingScheme, level, rectangle) { + QuadtreeTile.createMinimumLevelTiles = function(tilingScheme, level, terrainProvider) { //>>includeStart('debug', pragmas.debug); if (!defined(tilingScheme)) { throw new DeveloperError('tilingScheme is required.'); @@ -156,24 +156,33 @@ define([ if (!defined(level)) { throw new DeveloperError('level is required.'); } - if (!defined(rectangle)) { - throw new DeveloperError('rectangle is required.'); + if (!defined(terrainProvider)) { + throw new DeveloperError('terrainProvider is required.'); } //>>includeEnd('debug'); + var rectangle = terrainProvider._rectangle; var westSouth = Cartographic.fromRadians(rectangle.west, rectangle.south); var eastNorth = Cartographic.fromRadians(rectangle.east, rectangle.north); var bottomLeft = tilingScheme.positionToTileXY(westSouth, level); var topRight = tilingScheme.positionToTileXY(eastNorth, level); var result = new Array(); + var ranges = terrainProvider._availableTiles[level]; + var numberOfTilesY = tilingScheme.getNumberOfYTilesAtLevel(level); for (var y = topRight.y; y <= bottomLeft.y; y++) { for (var x = bottomLeft.x; x <= topRight.x; x++) { - result.push(new QuadtreeTile({ - tilingScheme : tilingScheme, - x : x, - y : y, - level : level - })); + for (var i = 0, len = ranges.length; i < len; ++i) { + var range = ranges[i]; + var terrainY = numberOfTilesY - y - 1; + if (x >= range.startX && x <= range.endX && terrainY >= range.startY && terrainY <= range.endY) { + result.push(new QuadtreeTile({ + tilingScheme : tilingScheme, + x : x, + y : y, + level : level + })); + } + } } }