Add ol.TileGrid.getZForResolution
This commit is contained in:
@@ -259,6 +259,30 @@ ol.TileGrid.prototype.getTileCoordResolution = function(tileCoord) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} resolution Resolution.
|
||||||
|
* @return {number} Z.
|
||||||
|
*/
|
||||||
|
ol.TileGrid.prototype.getZForResolution = function(resolution) {
|
||||||
|
var z;
|
||||||
|
for (z = 0; z < this.numResolutions_; ++z) {
|
||||||
|
if (this.resolutions_[z] == resolution) {
|
||||||
|
return z;
|
||||||
|
} else if (this.resolutions_[z] < resolution) {
|
||||||
|
if (z === 0) {
|
||||||
|
return z;
|
||||||
|
} else if (resolution - this.resolutions_[z] <=
|
||||||
|
this.resolutions_[z - 1] - resolution) {
|
||||||
|
return z;
|
||||||
|
} else {
|
||||||
|
return z - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.numResolutions_ - 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @param {function(number, ol.TileBounds): boolean} callback Callback.
|
* @param {function(number, ol.TileBounds): boolean} callback Callback.
|
||||||
|
|||||||
@@ -264,3 +264,38 @@ function testForEachTileCoordParent() {
|
|||||||
assertEquals(0, tileBoundss[2].left);
|
assertEquals(0, tileBoundss[2].left);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function testGetZForResolutionExact() {
|
||||||
|
|
||||||
|
var tileGrid =
|
||||||
|
new ol.TileGrid(resolutions, extent, origin, xEast, ySouth, tileSize);
|
||||||
|
|
||||||
|
assertEquals(0, tileGrid.getZForResolution(1000));
|
||||||
|
assertEquals(1, tileGrid.getZForResolution(500));
|
||||||
|
assertEquals(2, tileGrid.getZForResolution(250));
|
||||||
|
assertEquals(3, tileGrid.getZForResolution(100));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function testGetZForResolutionApproximate() {
|
||||||
|
|
||||||
|
var tileGrid =
|
||||||
|
new ol.TileGrid(resolutions, extent, origin, xEast, ySouth, tileSize);
|
||||||
|
|
||||||
|
assertEquals(0, tileGrid.getZForResolution(2000));
|
||||||
|
assertEquals(0, tileGrid.getZForResolution(1000));
|
||||||
|
assertEquals(0, tileGrid.getZForResolution(900));
|
||||||
|
assertEquals(1, tileGrid.getZForResolution(750));
|
||||||
|
assertEquals(1, tileGrid.getZForResolution(625));
|
||||||
|
assertEquals(1, tileGrid.getZForResolution(500));
|
||||||
|
assertEquals(1, tileGrid.getZForResolution(475));
|
||||||
|
assertEquals(2, tileGrid.getZForResolution(375));
|
||||||
|
assertEquals(2, tileGrid.getZForResolution(250));
|
||||||
|
assertEquals(2, tileGrid.getZForResolution(200));
|
||||||
|
assertEquals(3, tileGrid.getZForResolution(125));
|
||||||
|
assertEquals(3, tileGrid.getZForResolution(100));
|
||||||
|
assertEquals(3, tileGrid.getZForResolution(50));
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user