Add projection parameter to ol.source.Tile#forEachLoadedTile

This commit is contained in:
Petr Sloup
2015-06-10 10:09:34 +02:00
parent 63084d30e9
commit e0cfa1951a
7 changed files with 70 additions and 39 deletions

View File

@@ -115,9 +115,7 @@ ol.source.TileImage.prototype.getTileGridForProjection = function(projection) {
/**
* @param {ol.proj.Projection} projection Projection.
* @return {ol.TileCache} Tile cache.
* @protected
* @inheritDoc
*/
ol.source.TileImage.prototype.getTileCacheForProjection = function(projection) {
if (ol.proj.equivalent(this.getProjection(), projection)) {

View File

@@ -10,6 +10,7 @@ goog.require('ol.Extent');
goog.require('ol.TileCache');
goog.require('ol.TileRange');
goog.require('ol.TileState');
goog.require('ol.proj');
goog.require('ol.size');
goog.require('ol.source.Source');
goog.require('ol.tilecoord');
@@ -105,6 +106,7 @@ ol.source.Tile.prototype.expireCache = function(usedTiles) {
/**
* @param {ol.proj.Projection} projection
* @param {number} z Zoom level.
* @param {ol.TileRange} tileRange Tile range.
* @param {function(ol.Tile):(boolean|undefined)} callback Called with each
@@ -112,15 +114,21 @@ ol.source.Tile.prototype.expireCache = function(usedTiles) {
* considered loaded.
* @return {boolean} The tile range is fully covered with loaded tiles.
*/
ol.source.Tile.prototype.forEachLoadedTile = function(z, tileRange, callback) {
ol.source.Tile.prototype.forEachLoadedTile =
function(projection, z, tileRange, callback) {
var tileCache = this.getTileCacheForProjection(projection);
if (goog.isNull(tileCache)) {
return false;
}
var covered = true;
var tile, tileCoordKey, loaded;
for (var x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (var y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoordKey = this.getKeyZXY(z, x, y);
loaded = false;
if (this.tileCache.containsKey(tileCoordKey)) {
tile = /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
if (tileCache.containsKey(tileCoordKey)) {
tile = /** @type {!ol.Tile} */ (tileCache.get(tileCoordKey));
loaded = tile.getState() === ol.TileState.LOADED;
if (loaded) {
loaded = (callback(tile) !== false);
@@ -203,6 +211,21 @@ ol.source.Tile.prototype.getTileGridForProjection = function(projection) {
};
/**
* @param {ol.proj.Projection} projection Projection.
* @return {ol.TileCache} Tile cache.
* @protected
*/
ol.source.Tile.prototype.getTileCacheForProjection = function(projection) {
if (goog.isNull(this.tileCache) ||
!ol.proj.equivalent(this.getProjection(), projection)) {
return null;
} else {
return this.tileCache;
}
};
/**
* @param {number} z Z.
* @param {number} pixelRatio Pixel ratio.