Merge pull request #3780 from ahocevar/call-tileurlfunction-with-transformed-tilecoord

Only expose transformed tile coordinates to the API
This commit is contained in:
Andreas Hocevar
2015-06-12 11:18:16 +02:00
27 changed files with 301 additions and 368 deletions

View File

@@ -192,7 +192,7 @@ ol.renderer.dom.TileLayer.prototype.prepareFrame =
tileLayerZ = this.tileLayerZs_[tileLayerZKey];
} else {
tileCoordOrigin =
tileGrid.getTileCoordForCoordAndZ(center, tileLayerZKey);
tileGrid.getTileCoordForCoordAndZInternal(center, tileLayerZKey);
tileLayerZ = new ol.renderer.dom.TileLayerZ_(tileGrid, tileCoordOrigin);
newTileLayerZKeys[tileLayerZKey] = true;
this.tileLayerZs_[tileLayerZKey] = tileLayerZ;

View File

@@ -114,34 +114,32 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
this.tileGrid = tileGrid;
var culture = this.culture_;
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform(),
ol.TileUrlFunction.createFromTileUrlFunctions(
goog.array.map(
resource.imageUrlSubdomains,
function(subdomain) {
var imageUrl = resource.imageUrl
.replace('{subdomain}', subdomain)
.replace('{culture}', culture);
return (
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
goog.asserts.assert(ol.proj.equivalent(
projection, sourceProjection),
'projections are equivalent');
if (goog.isNull(tileCoord)) {
return undefined;
} else {
return imageUrl.replace(
'{quadkey}', ol.tilecoord.quadKey(tileCoord));
}
});
})));
this.tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
goog.array.map(
resource.imageUrlSubdomains,
function(subdomain) {
var imageUrl = resource.imageUrl
.replace('{subdomain}', subdomain)
.replace('{culture}', culture);
return (
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
goog.asserts.assert(ol.proj.equivalent(
projection, sourceProjection),
'projections are equivalent');
if (goog.isNull(tileCoord)) {
return undefined;
} else {
return imageUrl.replace(
'{quadkey}', ol.tilecoord.quadKey(tileCoord));
}
});
}));
if (resource.imageryProviders) {
var transform = ol.proj.getTransformFromProjections(

View File

@@ -7,7 +7,6 @@ goog.require('ol.dom');
goog.require('ol.size');
goog.require('ol.source.Tile');
goog.require('ol.tilecoord');
goog.require('ol.tilegrid.TileGrid');
@@ -15,10 +14,11 @@ goog.require('ol.tilegrid.TileGrid');
* @constructor
* @extends {ol.Tile}
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @param {ol.Size} tileSize Tile size.
* @param {string} text Text.
* @private
*/
ol.DebugTile_ = function(tileCoord, tileGrid) {
ol.DebugTile_ = function(tileCoord, tileSize, text) {
goog.base(this, tileCoord, ol.TileState.LOADED);
@@ -26,8 +26,13 @@ ol.DebugTile_ = function(tileCoord, tileGrid) {
* @private
* @type {ol.Size}
*/
this.tileSize_ = ol.size.toSize(
tileGrid.getTileSize(tileCoord[0]));
this.tileSize_ = tileSize;
/**
* @private
* @type {string}
*/
this.text_ = text;
/**
* @private
@@ -58,8 +63,7 @@ ol.DebugTile_.prototype.getImage = function(opt_context) {
context.textAlign = 'center';
context.textBaseline = 'middle';
context.font = '24px sans-serif';
context.fillText(ol.tilecoord.toString(this.tileCoord),
tileSize[0] / 2, tileSize[1] / 2);
context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2);
this.canvasByContext_[key] = context.canvas;
return context.canvas;
@@ -102,7 +106,11 @@ ol.source.TileDebug.prototype.getTile = function(z, x, y) {
if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.DebugTile_} */ (this.tileCache.get(tileCoordKey));
} else {
var tile = new ol.DebugTile_([z, x, y], this.tileGrid);
var tileSize = ol.size.toSize(this.tileGrid.getTileSize(z));
var tileCoord = [z, x, y];
var text = ol.tilecoord.toString(
this.getTileCoordForTileUrlFunction(tileCoord));
var tile = new ol.DebugTile_(tileCoord, tileSize, text);
this.tileCache.set(tileCoordKey, tile);
return tile;
}

View File

@@ -75,9 +75,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
});
this.tileGrid = tileGrid;
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform(),
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
this.tileUrlFunction = ol.TileUrlFunction.createFromTemplates(tileJSON.tiles);
if (goog.isDef(tileJSON.attribution) &&
goog.isNull(this.getAttributions())) {

View File

@@ -217,8 +217,10 @@ ol.source.Tile.prototype.getTilePixelSize =
/**
* Handles x-axis wrapping and returns a tile coordinate when it is within
* the resolution and extent range.
* Handles x-axis wrapping and returns a tile coordinate transformed from the
* internal tile scheme to the tile grid's tile scheme. When the tile coordinate
* is outside the resolution and extent range of the tile grid, `null` will be
* returned.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.proj.Projection=} opt_projection Projection.
* @return {ol.TileCoord} Tile coordinate to be passed to the tileUrlFunction or
@@ -233,7 +235,8 @@ ol.source.Tile.prototype.getTileCoordForTileUrlFunction =
if (this.getWrapX()) {
tileCoord = ol.tilecoord.wrapX(tileCoord, tileGrid, projection);
}
return ol.tilecoord.restrictByExtentAndZ(tileCoord, tileGrid);
return ol.tilecoord.withinExtentAndZ(tileCoord, tileGrid) ?
tileGrid.transformTileCoord(tileCoord) : null;
};

View File

@@ -82,7 +82,7 @@ ol.source.TileUTFGrid.prototype.getTemplate = function() {
ol.source.TileUTFGrid.prototype.forDataAtCoordinateAndResolution = function(
coordinate, resolution, callback, opt_this, opt_request) {
if (!goog.isNull(this.tileGrid)) {
var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(
var tileCoord = this.tileGrid.getTileCoordForCoordAndResolutionInternal(
coordinate, resolution);
var tile = /** @type {!ol.source.TileUTFGridTile_} */(this.getTile(
tileCoord[0], tileCoord[1], tileCoord[2], 1, this.getProjection()));
@@ -136,9 +136,7 @@ ol.source.TileUTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
return;
}
this.tileUrlFunction_ = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform(),
ol.TileUrlFunction.createFromTemplates(grids));
this.tileUrlFunction_ = ol.TileUrlFunction.createFromTemplates(grids);
if (goog.isDef(tileJSON.attribution)) {
var attributionExtent = goog.isDef(extent) ?
@@ -175,7 +173,9 @@ ol.source.TileUTFGrid.prototype.getTile =
} else {
goog.asserts.assert(projection, 'argument projection is truthy');
var tileCoord = [z, x, y];
var tileUrl = this.tileUrlFunction_(tileCoord, pixelRatio, projection);
var urlTileCoord =
this.getTileCoordForTileUrlFunction(tileCoord, projection);
var tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
var tile = new ol.source.TileUTFGridTile_(
tileCoord,
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,

View File

@@ -3,7 +3,6 @@ goog.provide('ol.source.TileVector');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.object');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.featureloader');
goog.require('ol.source.State');
@@ -52,12 +51,6 @@ ol.source.TileVector = function(options) {
*/
this.tileUrlFunction_ = ol.TileUrlFunction.nullTileUrlFunction;
/**
* @private
* @type {ol.TileCoordTransformType}
*/
this.tileCoordTransform_ = this.tileGrid_.createTileCoordTransform();
/**
* @private
* @type {Object.<string, Array.<ol.Feature>>}
@@ -121,7 +114,7 @@ ol.source.TileVector.prototype.forEachFeatureAtCoordinateAndResolution =
var tileGrid = this.tileGrid_;
var tiles = this.tiles_;
var tileCoord = tileGrid.getTileCoordForCoordAndResolution(coordinate,
var tileCoord = tileGrid.getTileCoordForCoordAndResolutionInternal(coordinate,
resolution);
var tileKey = this.getTileKeyZXY_(tileCoord[0], tileCoord[1], tileCoord[2]);
@@ -254,7 +247,6 @@ ol.source.TileVector.prototype.getTileKeyZXY_ = function(z, x, y) {
*/
ol.source.TileVector.prototype.loadFeatures =
function(extent, resolution, projection) {
var tileCoordTransform = this.tileCoordTransform_;
var tileGrid = this.tileGrid_;
var tileUrlFunction = this.tileUrlFunction_;
var tiles = this.tiles_;
@@ -278,7 +270,7 @@ ol.source.TileVector.prototype.loadFeatures =
tileCoord[0] = z;
tileCoord[1] = x;
tileCoord[2] = y;
tileCoordTransform(tileCoord, projection, tileCoord);
tileGrid.transformTileCoord(tileCoord, tileCoord);
var url = tileUrlFunction(tileCoord, 1, projection);
if (goog.isDef(url)) {
tiles[tileKey] = [];

View File

@@ -140,7 +140,7 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl =
tileGrid = this.getTileGridForProjection(projectionObj);
}
var tileCoord = tileGrid.getTileCoordForCoordAndResolution(
var tileCoord = tileGrid.getTileCoordForCoordAndResolutionInternal(
coordinate, resolution);
if (tileGrid.getResolutions().length <= tileCoord[0]) {

View File

@@ -180,10 +180,6 @@ ol.source.WMTS = function(options) {
goog.array.map(this.urls_, createFromWMTSTemplate)) :
ol.TileUrlFunction.nullTileUrlFunction;
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid),
tileUrlFunction);
goog.base(this, {
attributions: options.attributions,
crossOrigin: options.crossOrigin,

View File

@@ -37,12 +37,6 @@ ol.source.XYZ = function(options) {
wrapX: goog.isDef(options.wrapX) ? options.wrapX : true
});
/**
* @private
* @type {ol.TileCoordTransformType}
*/
this.tileCoordTransform_ = tileGrid.createTileCoordTransform();
if (goog.isDef(options.tileUrlFunction)) {
this.setTileUrlFunction(options.tileUrlFunction);
} else if (goog.isDef(options.urls)) {
@@ -55,17 +49,6 @@ ol.source.XYZ = function(options) {
goog.inherits(ol.source.XYZ, ol.source.TileImage);
/**
* @inheritDoc
* @api
*/
ol.source.XYZ.prototype.setTileUrlFunction = function(tileUrlFunction) {
goog.base(this, 'setTileUrlFunction',
ol.TileUrlFunction.withTileCoordTransform(
this.tileCoordTransform_, tileUrlFunction));
};
/**
* Set the URL to use for requests.
* @param {string} url URL.

View File

@@ -5,7 +5,6 @@ goog.require('ol');
goog.require('ol.ImageTile');
goog.require('ol.TileCoord');
goog.require('ol.TileState');
goog.require('ol.TileUrlFunction');
goog.require('ol.dom');
goog.require('ol.proj');
goog.require('ol.source.TileImage');
@@ -88,35 +87,35 @@ ol.source.Zoomify = function(opt_options) {
resolutions.reverse();
var tileGrid = new ol.tilegrid.Zoomify({
extent: [0, 0, size[0], size[1]],
resolutions: resolutions
});
var url = options.url;
var tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform({extent: [0, 0, size[0], size[1]]}),
/**
* @this {ol.source.TileImage}
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
var tileCoordZ = tileCoord[0];
var tileCoordX = tileCoord[1];
var tileCoordY = tileCoord[2];
var tileIndex =
tileCoordX +
tileCoordY * tierSizeInTiles[tileCoordZ][0] +
tileCountUpToTier[tileCoordZ];
var tileGroup = (tileIndex / ol.DEFAULT_TILE_SIZE) | 0;
return url + 'TileGroup' + tileGroup + '/' +
tileCoordZ + '-' + tileCoordX + '-' + tileCoordY + '.jpg';
}
});
/**
* @this {ol.source.TileImage}
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function tileUrlFunction(tileCoord, pixelRatio, projection) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
var tileCoordZ = tileCoord[0];
var tileCoordX = tileCoord[1];
var tileCoordY = tileCoord[2];
var tileIndex =
tileCoordX +
tileCoordY * tierSizeInTiles[tileCoordZ][0] +
tileCountUpToTier[tileCoordZ];
var tileGroup = (tileIndex / ol.DEFAULT_TILE_SIZE) | 0;
return url + 'TileGroup' + tileGroup + '/' +
tileCoordZ + '-' + tileCoordX + '-' + tileCoordY + '.jpg';
}
}
goog.base(this, {
attributions: options.attributions,

View File

@@ -155,7 +155,7 @@ ol.tilecoord.wrapX = function(tileCoord, tileGrid, projection) {
var worldWidth = ol.extent.getWidth(projectionExtent);
var worldsAway = Math.ceil((projectionExtent[0] - center[0]) / worldWidth);
center[0] += worldWidth * worldsAway;
return tileGrid.getTileCoordForCoordAndZ(center, z);
return tileGrid.getTileCoordForCoordAndZInternal(center, z);
} else {
return tileCoord;
}
@@ -165,15 +165,15 @@ ol.tilecoord.wrapX = function(tileCoord, tileGrid, projection) {
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.
* @return {ol.TileCoord} Tile coordinate.
* @return {boolean} Tile coordinate is within extent and zoom level range.
*/
ol.tilecoord.restrictByExtentAndZ = function(tileCoord, tileGrid) {
ol.tilecoord.withinExtentAndZ = function(tileCoord, tileGrid) {
var z = tileCoord[0];
var x = tileCoord[1];
var y = tileCoord[2];
if (tileGrid.getMinZoom() > z || z > tileGrid.getMaxZoom()) {
return null;
return false;
}
var extent = tileGrid.getExtent();
var tileRange;
@@ -183,8 +183,8 @@ ol.tilecoord.restrictByExtentAndZ = function(tileCoord, tileGrid) {
tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
}
if (goog.isNull(tileRange)) {
return tileCoord;
return true;
} else {
return tileRange.containsXY(x, y) ? tileCoord : null;
return tileRange.containsXY(x, y);
}
};

View File

@@ -114,20 +114,15 @@ ol.tilegrid.TileGrid = function(options) {
/**
* Creates a TileCoord transform function for use with this tile grid.
* Transforms the internal tile coordinates with bottom-left origin to
* the tile coordinates used by the {@link ol.TileUrlFunction}.
* The returned function expects an {@link ol.TileCoord} as first and an
* {@link ol.proj.Projection} as second argument and returns a transformed
* {@link ol.TileCoord}.
* @param {{extent: (ol.Extent|undefined)}=} opt_options Options.
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
* ol.TileCoord} Tile coordinate transform.
* @api
* TileCoord transform function for use with this tile grid. Transforms the
* internal tile coordinates with bottom-left origin to the tile coordinates
* used by the source's {@link ol.TileUrlFunction}.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileCoord=} opt_tileCoord Destination tile coordinate.
* @return {ol.TileCoord} Tile coordinate.
*/
this.createTileCoordTransform = goog.isDef(options.createTileCoordTransform) ?
options.createTileCoordTransform :
goog.functions.identity;
this.transformTileCoord = goog.isDef(options.transformTileCoord) ?
options.transformTileCoord : goog.functions.identity;
/**
* @private
@@ -387,6 +382,28 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent =
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
coordinate, resolution, opt_tileCoord) {
var tileCoord = this.getTileCoordForCoordAndResolutionInternal(
coordinate, resolution, opt_tileCoord);
this.transformTileCoord(tileCoord, tileCoord);
return tileCoord;
};
/**
* Get the tile coordinate for the given map coordinate and resolution. This
* method considers that coordinates that intersect tile boundaries should be
* assigned the higher tile coordinate.
*
* The returned tile coordinate is the internal, untransformed one with
* bottom-left origin.
*
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} resolution Resolution.
* @param {ol.TileCoord=} opt_tileCoord Destination ol.TileCoord object.
* @return {ol.TileCoord} Internal, untransformed tile coordinate.
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolutionInternal =
function(coordinate, resolution, opt_tileCoord) {
return this.getTileCoordForXYAndResolution_(
coordinate[0], coordinate[1], resolution, false, opt_tileCoord);
};
@@ -436,7 +453,24 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForXYAndResolution_ = function(
* @return {ol.TileCoord} Tile coordinate.
* @api
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ =
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ = function(
coordinate, z, opt_tileCoord) {
var tileCoord = this.getTileCoordForCoordAndZInternal(
coordinate, z, opt_tileCoord);
this.transformTileCoord(tileCoord, tileCoord);
return tileCoord;
};
/**
* Get a tile coordinate given a map coordinate and zoom level. The returned
* tile coordinate is the internal one, untransformed with bottom-left origin.
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} z Zoom level.
* @param {ol.TileCoord=} opt_tileCoord Destination ol.TileCoord object.
* @return {ol.TileCoord} Internal, untransformed tile coordinate.
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZInternal =
function(coordinate, z, opt_tileCoord) {
var resolution = this.getResolution(z);
return this.getTileCoordForXYAndResolution_(
@@ -582,15 +616,7 @@ ol.tilegrid.createXYZ = function(opt_options) {
options.extent, options.maxZoom, options.tileSize);
delete options.maxZoom;
/**
* @param {{extent: (ol.Extent|undefined)}=} opt_options Options.
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
* ol.TileCoord} Tile coordinate transform.
* @this {ol.tilegrid.TileGrid}
*/
options.createTileCoordTransform = function(opt_options) {
return ol.tilegrid.createOriginTopLeftTileCoordTransform(this);
};
options.transformTileCoord = ol.tilegrid.originTopLeftTileCoordTransform;
return new ol.tilegrid.TileGrid(options);
};
@@ -663,29 +689,20 @@ ol.tilegrid.extentFromProjection = function(projection) {
/**
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
* ol.TileCoord} Tile coordinate transform.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileCoord=} opt_tileCoord Destination tile coordinate.
* @return {ol.TileCoord} Tile coordinate.
* @this {ol.tilegrid.TileGrid}
*/
ol.tilegrid.createOriginTopLeftTileCoordTransform = function(tileGrid) {
goog.asserts.assert(!goog.isNull(tileGrid), 'tileGrid required');
return (
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.proj.Projection} projection Projection.
* @param {ol.TileCoord=} opt_tileCoord Destination tile coordinate.
* @return {ol.TileCoord} Tile coordinate.
*/
function(tileCoord, projection, opt_tileCoord) {
if (goog.isNull(tileCoord)) {
return null;
}
var z = tileCoord[0];
var fullTileRange = tileGrid.getFullTileRange(z);
var height = (goog.isNull(fullTileRange) || fullTileRange.minY < 0) ?
0 : fullTileRange.getHeight();
return ol.tilecoord.createOrUpdate(
z, tileCoord[1], height - tileCoord[2] - 1, opt_tileCoord);
}
);
ol.tilegrid.originTopLeftTileCoordTransform =
function(tileCoord, opt_tileCoord) {
if (goog.isNull(tileCoord)) {
return null;
}
var z = tileCoord[0];
var fullTileRange = this.getFullTileRange(z);
var height = (goog.isNull(fullTileRange) || fullTileRange.minY < 0) ?
0 : fullTileRange.getHeight();
return ol.tilecoord.createOrUpdate(
z, tileCoord[1], height - tileCoord[2] - 1, opt_tileCoord);
};

View File

@@ -38,7 +38,8 @@ ol.tilegrid.WMTS = function(options) {
resolutions: options.resolutions,
tileSize: options.tileSize,
tileSizes: options.tileSizes,
sizes: options.sizes
sizes: options.sizes,
transformTileCoord: ol.tilegrid.originTopLeftTileCoordTransform
});
};

View File

@@ -2,7 +2,6 @@ goog.provide('ol.tilegrid.Zoomify');
goog.require('goog.math');
goog.require('ol.TileCoord');
goog.require('ol.proj');
goog.require('ol.tilecoord');
goog.require('ol.tilegrid.TileGrid');
@@ -20,64 +19,54 @@ goog.require('ol.tilegrid.TileGrid');
ol.tilegrid.Zoomify = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : options;
/** @type {Array.<ol.TileRange>} */
var tileRangeByZ = goog.isDef(options.extent) ? [] : null;
/**
* @param {{extent: (ol.Extent|undefined)}=} opt_options Options.
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
* ol.TileCoord} Tile coordinate transform.
* @this {ol.tilegrid.Zoomify}
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.TileCoord=} opt_tileCoord Destination tile coordinate.
* @return {ol.TileCoord} Tile coordinate.
*/
var createTileCoordTransform = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
var minZ = this.minZoom;
var maxZ = this.maxZoom;
/** @type {Array.<ol.TileRange>} */
var tileRangeByZ = null;
if (goog.isDef(options.extent)) {
tileRangeByZ = new Array(maxZ + 1);
var z;
for (z = 0; z <= maxZ; ++z) {
if (z < minZ) {
tileRangeByZ[z] = null;
} else {
tileRangeByZ[z] = this.getTileRangeForExtentAndZ(options.extent, z);
}
function transformTileCoord(tileCoord, opt_tileCoord) {
var z = tileCoord[0];
if (z < minZ || maxZ < z) {
return null;
}
var n = Math.pow(2, z);
var x = tileCoord[1];
if (x < 0 || n <= x) {
return null;
}
var y = tileCoord[2];
if (y < -n || -1 < y) {
return null;
}
if (!goog.isNull(tileRangeByZ)) {
if (!tileRangeByZ[z].containsXY(x, -y - 1)) {
return null;
}
}
return (
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.proj.Projection} projection Projection.
* @param {ol.TileCoord=} opt_tileCoord Destination tile coordinate.
* @return {ol.TileCoord} Tile coordinate.
*/
function(tileCoord, projection, opt_tileCoord) {
var z = tileCoord[0];
if (z < minZ || maxZ < z) {
return null;
}
var n = Math.pow(2, z);
var x = tileCoord[1];
if (x < 0 || n <= x) {
return null;
}
var y = tileCoord[2];
if (y < -n || -1 < y) {
return null;
}
if (!goog.isNull(tileRangeByZ)) {
if (!tileRangeByZ[z].containsXY(x, -y - 1)) {
return null;
}
}
return ol.tilecoord.createOrUpdate(z, x, -y - 1, opt_tileCoord);
});
};
return ol.tilecoord.createOrUpdate(z, x, -y - 1, opt_tileCoord);
}
goog.base(this, {
createTileCoordTransform: createTileCoordTransform,
origin: [0, 0],
resolutions: options.resolutions
resolutions: options.resolutions,
transformTileCoord: transformTileCoord
});
if (goog.isDef(options.extent)) {
var minZ = this.minZoom;
var maxZ = this.maxZoom;
tileRangeByZ = [];
var z;
for (z = 0; z <= maxZ; ++z) {
if (z < minZ) {
tileRangeByZ[z] = null;
} else {
tileRangeByZ[z] = this.getTileRangeForExtentAndZ(options.extent, z);
}
}
}
};
goog.inherits(ol.tilegrid.Zoomify, ol.tilegrid.TileGrid);

View File

@@ -9,32 +9,14 @@ goog.require('ol.tilecoord');
/**
* A function that takes an {@link ol.TileCoord} for the tile coordinate,
* a `{number}` representing the pixel ratio and an {@link ol.proj.Projection}
* for the projection as arguments and returns a `{string}` or
* undefined representing the tile URL.
* {@link ol.source.Tile} sources use a function of this type to get the url
* that provides a tile for a given tile coordinate.
*
* The {@link ol.TileCoord}'s `x` value
* increases from left to right, `y` increases from bottom to top. At the
* bottom left corner, `x` and `y` are `0`. To convert `y` to increase from
* top to bottom, use the following code:
* ```js
* var tileGrid = new ol.tilegrid.TileGrid({
* extent: extent,
* resolutions: resolutions,
* tileSize: tileSize
* });
*
* function calculateY(tileCoord) {
* var z = tileCoord[0];
* var yFromBottom = tileCoord[2];
* var resolution = tileGrid.getResolution(z);
* var tileHeight = ol.size.toSize(tileSize)[1];
* var matrixHeight =
* Math.floor(ol.extent.getHeight(extent) / tileHeight / resolution);
* return matrixHeight - yFromBottom - 1;
* };
* ```
* This function takes an {@link ol.TileCoord} for the tile coordinate, a
* `{number}` representing the pixel ratio and an {@link ol.proj.Projection} for
* the projection as arguments and returns a `{string}` representing the tile
* URL, or undefined if no tile should be requested for the passed tile
* coordinate.
*
* @typedef {function(ol.TileCoord, number,
* ol.proj.Projection): (string|undefined)}
@@ -133,34 +115,6 @@ ol.TileUrlFunction.nullTileUrlFunction =
};
/**
* @param {ol.TileCoordTransformType} transformFn Transform function.
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
* @return {ol.TileUrlFunctionType} Tile URL function.
*/
ol.TileUrlFunction.withTileCoordTransform =
function(transformFn, tileUrlFunction) {
var tmpTileCoord = [0, 0, 0];
return (
/**
* @param {ol.TileCoord} tileCoord Tile Coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
if (goog.isNull(tileCoord)) {
return undefined;
} else {
return tileUrlFunction(
transformFn(tileCoord, projection, tmpTileCoord),
pixelRatio,
projection);
}
});
};
/**
* @param {string} url URL.
* @return {Array.<string>} Array of urls.