Enable ol.TileRange re-use
This commit is contained in:
+18
-10
@@ -96,16 +96,17 @@ ol.tilegrid.TileGrid = function(options) {
|
|||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @param {function(this: T, number, ol.TileRange): boolean} callback Callback.
|
* @param {function(this: T, number, ol.TileRange): boolean} callback Callback.
|
||||||
* @param {T=} opt_obj Object.
|
* @param {T=} opt_obj Object.
|
||||||
|
* @param {ol.TileRange=} opt_tileRange Temporary ol.TileRange object.
|
||||||
* @return {boolean} Callback succeeded.
|
* @return {boolean} Callback succeeded.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
ol.tilegrid.TileGrid.prototype.forEachTileCoordParentTileRange =
|
ol.tilegrid.TileGrid.prototype.forEachTileCoordParentTileRange =
|
||||||
function(tileCoord, callback, opt_obj) {
|
function(tileCoord, callback, opt_obj, opt_tileRange) {
|
||||||
var tileCoordExtent = this.getTileCoordExtent(tileCoord);
|
var tileCoordExtent = this.getTileCoordExtent(tileCoord);
|
||||||
var z = tileCoord.z - 1;
|
var z = tileCoord.z - 1;
|
||||||
while (z >= 0) {
|
while (z >= 0) {
|
||||||
if (callback.call(
|
if (callback.call(opt_obj, z,
|
||||||
opt_obj, z, this.getTileRangeForExtentAndZ(tileCoordExtent, z))) {
|
this.getTileRangeForExtentAndZ(tileCoordExtent, z, opt_tileRange))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
--z;
|
--z;
|
||||||
@@ -168,13 +169,15 @@ ol.tilegrid.TileGrid.prototype.getResolutions = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
|
* @param {ol.TileRange=} opt_tileRange Temporary ol.TileRange object.
|
||||||
* @return {ol.TileRange} Tile range.
|
* @return {ol.TileRange} Tile range.
|
||||||
*/
|
*/
|
||||||
ol.tilegrid.TileGrid.prototype.getTileCoordChildTileRange =
|
ol.tilegrid.TileGrid.prototype.getTileCoordChildTileRange =
|
||||||
function(tileCoord) {
|
function(tileCoord, opt_tileRange) {
|
||||||
if (tileCoord.z < this.resolutions_.length) {
|
if (tileCoord.z < this.resolutions_.length) {
|
||||||
var tileCoordExtent = this.getTileCoordExtent(tileCoord);
|
var tileCoordExtent = this.getTileCoordExtent(tileCoord);
|
||||||
return this.getTileRangeForExtentAndZ(tileCoordExtent, tileCoord.z + 1);
|
return this.getTileRangeForExtentAndZ(
|
||||||
|
tileCoordExtent, tileCoord.z + 1, opt_tileRange);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -201,28 +204,33 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
|
|||||||
/**
|
/**
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
|
* @param {ol.TileRange=} opt_tileRange Temporary tile range object.
|
||||||
* @return {ol.TileRange} Tile range.
|
* @return {ol.TileRange} Tile range.
|
||||||
*/
|
*/
|
||||||
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
|
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution =
|
||||||
extent, resolution) {
|
function(extent, resolution, opt_tileRange) {
|
||||||
var tileCoord = this.getTileCoordForXYAndResolution_(
|
var tileCoord = this.getTileCoordForXYAndResolution_(
|
||||||
extent.minX, extent.minY, resolution, false);
|
extent.minX, extent.minY, resolution, false);
|
||||||
var minX = tileCoord.x;
|
var minX = tileCoord.x;
|
||||||
var minY = tileCoord.y;
|
var minY = tileCoord.y;
|
||||||
tileCoord = this.getTileCoordForXYAndResolution_(
|
tileCoord = this.getTileCoordForXYAndResolution_(
|
||||||
extent.maxX, extent.maxY, resolution, true, tileCoord);
|
extent.maxX, extent.maxY, resolution, true, tileCoord);
|
||||||
return new ol.TileRange(minX, minY, tileCoord.x, tileCoord.y);
|
return ol.TileRange.createOrUpdate(
|
||||||
|
minX, minY, tileCoord.x, tileCoord.y, opt_tileRange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {number} z Z.
|
* @param {number} z Z.
|
||||||
|
* @param {ol.TileRange=} opt_tileRange Temporary tile range object.
|
||||||
* @return {ol.TileRange} Tile range.
|
* @return {ol.TileRange} Tile range.
|
||||||
*/
|
*/
|
||||||
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z) {
|
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndZ =
|
||||||
|
function(extent, z, opt_tileRange) {
|
||||||
var resolution = this.getResolution(z);
|
var resolution = this.getResolution(z);
|
||||||
return this.getTileRangeForExtentAndResolution(extent, resolution);
|
return this.getTileRangeForExtentAndResolution(
|
||||||
|
extent, resolution, opt_tileRange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,11 +42,13 @@ goog.inherits(ol.tilegrid.XYZ, ol.tilegrid.TileGrid);
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.tilegrid.XYZ.prototype.getTileCoordChildTileRange = function(tileCoord) {
|
ol.tilegrid.XYZ.prototype.getTileCoordChildTileRange =
|
||||||
|
function(tileCoord, opt_tileRange) {
|
||||||
if (tileCoord.z < this.maxZoom_) {
|
if (tileCoord.z < this.maxZoom_) {
|
||||||
return new ol.TileRange(
|
return ol.TileRange.createOrUpdate(
|
||||||
tileCoord.x << 1, tileCoord.y << 1,
|
tileCoord.x << 1, tileCoord.y << 1,
|
||||||
tileCoord.x + 1 << 1, tileCoord.y + 1 << 1);
|
tileCoord.x + 1 << 1, tileCoord.y + 1 << 1,
|
||||||
|
opt_tileRange);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -57,8 +59,9 @@ ol.tilegrid.XYZ.prototype.getTileCoordChildTileRange = function(tileCoord) {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange =
|
ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange =
|
||||||
function(tileCoord, callback, opt_obj) {
|
function(tileCoord, callback, opt_obj, opt_tileRange) {
|
||||||
var tileRange = new ol.TileRange(0, 0, tileCoord.x, tileCoord.y);
|
var tileRange = ol.TileRange.createOrUpdate(
|
||||||
|
0, 0, tileCoord.x, tileCoord.y, opt_tileRange);
|
||||||
var z;
|
var z;
|
||||||
for (z = tileCoord.z - 1; z >= 0; --z) {
|
for (z = tileCoord.z - 1; z >= 0; --z) {
|
||||||
tileRange.minX = tileRange.maxX >>= 1;
|
tileRange.minX = tileRange.maxX >>= 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user