Pass transformed tile coordinates to the tileUrlFunction

This commit is contained in:
Andreas Hocevar
2015-06-12 09:45:03 +02:00
parent fad3cf9672
commit 6a4d1c9b89
21 changed files with 189 additions and 350 deletions
+24 -46
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
@@ -582,15 +577,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 +650,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);
};
+2 -1
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
});
};
+40 -51
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);