Add function to iterate over tile coordinates in extent and z
This commit is contained in:
@@ -150,6 +150,24 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
ol.tilegrid.TileGrid.tmpTileCoord_ = [0, 0, 0];
|
||||
|
||||
|
||||
/**
|
||||
* Call a function with each tile coordinate for a given extent and zoom level.
|
||||
*
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} zoom Zoom level.
|
||||
* @param {function(ol.TileCoord)} callback Function called with each tile coordinate.
|
||||
* @api
|
||||
*/
|
||||
ol.tilegrid.TileGrid.prototype.forEachTileCoordInExtentAndZ = function(extent, zoom, callback) {
|
||||
var tileRange = this.getTileRangeForExtentAndZ(extent, zoom);
|
||||
for (var i = tileRange.minX, ii = tileRange.maxX; i <= ii; ++i) {
|
||||
for (var j = tileRange.minY, jj = tileRange.maxY; j <= jj; ++j) {
|
||||
callback([zoom, i, j]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {function(this: T, number, ol.TileRange): boolean} callback Callback.
|
||||
|
||||
@@ -949,6 +949,22 @@ describe('ol.tilegrid.TileGrid', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('forEachTileCoordInExtentAndZ', function() {
|
||||
it('calls the provided function with each tile coordinate', function() {
|
||||
var tileGrid = ol.tilegrid.createXYZ({extent: [-180, -90, 180, 90]});
|
||||
var tileCoords = [];
|
||||
tileGrid.forEachTileCoordInExtentAndZ([15, 47, 16, 48], 8, function(tileCoord) {
|
||||
tileCoords.push(tileCoord);
|
||||
});
|
||||
expect(tileCoords).to.eql([
|
||||
[8, 138, -31],
|
||||
[8, 138, -30],
|
||||
[8, 139, -31],
|
||||
[8, 139, -30]
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('forEachTileCoordParentTileRange', function() {
|
||||
it('iterates as expected', function() {
|
||||
var tileGrid = new ol.tilegrid.TileGrid({
|
||||
|
||||
Reference in New Issue
Block a user