Merge pull request #3747 from ahocevar/tilecoordtransform
Make tileCoordTransform a member again
This commit is contained in:
@@ -6036,7 +6036,8 @@ olx.tilegrid;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{extent: (ol.Extent|undefined),
|
* @typedef {{createTileCoordTransform: (undefined|function({extent: (ol.Extent|undefined)}):function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):ol.TileCoord),
|
||||||
|
* extent: (ol.Extent|undefined),
|
||||||
* minZoom: (number|undefined),
|
* minZoom: (number|undefined),
|
||||||
* origin: (ol.Coordinate|undefined),
|
* origin: (ol.Coordinate|undefined),
|
||||||
* origins: (Array.<ol.Coordinate>|undefined),
|
* origins: (Array.<ol.Coordinate>|undefined),
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
|||||||
|
|
||||||
var culture = this.culture_;
|
var culture = this.culture_;
|
||||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid),
|
tileGrid.createTileCoordTransform(),
|
||||||
ol.TileUrlFunction.createFromTileUrlFunctions(
|
ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||||
goog.array.map(
|
goog.array.map(
|
||||||
resource.imageUrlSubdomains,
|
resource.imageUrlSubdomains,
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
|
|||||||
this.tileGrid = tileGrid;
|
this.tileGrid = tileGrid;
|
||||||
|
|
||||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid),
|
tileGrid.createTileCoordTransform(),
|
||||||
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
|
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));
|
||||||
|
|
||||||
if (goog.isDef(tileJSON.attribution) &&
|
if (goog.isDef(tileJSON.attribution) &&
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ ol.source.TileUTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.tileUrlFunction_ = ol.TileUrlFunction.withTileCoordTransform(
|
this.tileUrlFunction_ = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid),
|
tileGrid.createTileCoordTransform(),
|
||||||
ol.TileUrlFunction.createFromTemplates(grids));
|
ol.TileUrlFunction.createFromTemplates(grids));
|
||||||
|
|
||||||
if (goog.isDef(tileJSON.attribution)) {
|
if (goog.isDef(tileJSON.attribution)) {
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ ol.source.XYZ = function(options) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.TileCoordTransformType}
|
* @type {ol.TileCoordTransformType}
|
||||||
*/
|
*/
|
||||||
this.tileCoordTransform_ =
|
this.tileCoordTransform_ = tileGrid.createTileCoordTransform();
|
||||||
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid);
|
|
||||||
|
|
||||||
if (goog.isDef(options.tileUrlFunction)) {
|
if (goog.isDef(options.tileUrlFunction)) {
|
||||||
this.setTileUrlFunction(options.tileUrlFunction);
|
this.setTileUrlFunction(options.tileUrlFunction);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ goog.provide('ol.tilegrid.TileGrid');
|
|||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.functions');
|
||||||
goog.require('goog.math');
|
goog.require('goog.math');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
@@ -69,10 +70,14 @@ ol.tilegrid.TileGrid = function(options) {
|
|||||||
goog.asserts.assert(this.origins_.length == this.resolutions_.length,
|
goog.asserts.assert(this.origins_.length == this.resolutions_.length,
|
||||||
'number of origins and resolutions must be equal');
|
'number of origins and resolutions must be equal');
|
||||||
}
|
}
|
||||||
if (goog.isNull(this.origins_) && goog.isNull(this.origin_) &&
|
|
||||||
goog.isDef(options.extent)) {
|
var extent = options.extent;
|
||||||
this.origin_ = ol.extent.getBottomLeft(options.extent);
|
|
||||||
|
if (goog.isDef(extent) &&
|
||||||
|
goog.isNull(this.origin_) && goog.isNull(this.origins_)) {
|
||||||
|
this.origin_ = ol.extent.getBottomLeft(extent);
|
||||||
}
|
}
|
||||||
|
|
||||||
goog.asserts.assert(
|
goog.asserts.assert(
|
||||||
(goog.isNull(this.origin_) && !goog.isNull(this.origins_)) ||
|
(goog.isNull(this.origin_) && !goog.isNull(this.origins_)) ||
|
||||||
(!goog.isNull(this.origin_) && goog.isNull(this.origins_)),
|
(!goog.isNull(this.origin_) && goog.isNull(this.origins_)),
|
||||||
@@ -101,14 +106,24 @@ ol.tilegrid.TileGrid = function(options) {
|
|||||||
(!goog.isNull(this.tileSize_) && goog.isNull(this.tileSizes_)),
|
(!goog.isNull(this.tileSize_) && goog.isNull(this.tileSizes_)),
|
||||||
'either tileSize or tileSizes must be configured, never both');
|
'either tileSize or tileSizes must be configured, never both');
|
||||||
|
|
||||||
var extent = options.extent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Extent}
|
* @type {ol.Extent}
|
||||||
*/
|
*/
|
||||||
this.extent_ = goog.isDef(extent) ? extent : null;
|
this.extent_ = goog.isDef(extent) ? extent : null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TileCoord transform function for use with this tile grid. Returns unaltered
|
||||||
|
* tile coordinates by default.
|
||||||
|
* @param {{extent: (ol.Extent|undefined)}=} opt_options Options.
|
||||||
|
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
|
||||||
|
* ol.TileCoord} Tile coordinate transform.
|
||||||
|
*/
|
||||||
|
this.createTileCoordTransform = goog.isDef(options.createTileCoordTransform) ?
|
||||||
|
options.createTileCoordTransform :
|
||||||
|
goog.functions.identity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<ol.TileRange>}
|
* @type {Array.<ol.TileRange>}
|
||||||
@@ -133,18 +148,8 @@ ol.tilegrid.TileGrid = function(options) {
|
|||||||
}
|
}
|
||||||
return tileRange;
|
return tileRange;
|
||||||
}, this);
|
}, this);
|
||||||
} else if (goog.isDef(extent)) {
|
} else if (goog.isDefAndNotNull(extent)) {
|
||||||
var extentWidth = ol.extent.getWidth(extent);
|
this.calculateTileRanges_(extent);
|
||||||
var extentHeight = ol.extent.getHeight(extent);
|
|
||||||
var fullTileRanges = new Array(this.resolutions_.length);
|
|
||||||
var tileSize;
|
|
||||||
for (var z = 0, zz = fullTileRanges.length; z < zz; ++z) {
|
|
||||||
tileSize = ol.size.toSize(this.getTileSize(z), this.tmpSize_);
|
|
||||||
fullTileRanges[z] = new ol.TileRange(
|
|
||||||
0, Math.ceil(extentWidth / tileSize[0] / this.resolutions_[z]) - 1,
|
|
||||||
0, Math.ceil(extentHeight / tileSize[1] / this.resolutions_[z]) - 1);
|
|
||||||
}
|
|
||||||
this.fullTileRanges_ = fullTileRanges;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,16 +168,6 @@ ol.tilegrid.TileGrid = function(options) {
|
|||||||
ol.tilegrid.TileGrid.tmpTileCoord_ = [0, 0, 0];
|
ol.tilegrid.TileGrid.tmpTileCoord_ = [0, 0, 0];
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source specific TileCoord transform function. May be implemented by
|
|
||||||
* subclasses.
|
|
||||||
* @param {{extent: (ol.Extent|undefined)}=} opt_options Options.
|
|
||||||
* @return {function(ol.TileCoord, ol.proj.Projection, ol.TileCoord=):
|
|
||||||
* ol.TileCoord} Tile coordinate transform.
|
|
||||||
*/
|
|
||||||
ol.tilegrid.TileGrid.prototype.createTileCoordTransform = goog.abstractMethod;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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.
|
||||||
@@ -505,6 +500,25 @@ ol.tilegrid.TileGrid.prototype.getZForResolution = function(resolution) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {!ol.Extent} extent Extent for this tile grid.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.tilegrid.TileGrid.prototype.calculateTileRanges_ = function(extent) {
|
||||||
|
var extentWidth = ol.extent.getWidth(extent);
|
||||||
|
var extentHeight = ol.extent.getHeight(extent);
|
||||||
|
var fullTileRanges = new Array(this.resolutions_.length);
|
||||||
|
var tileSize;
|
||||||
|
for (var z = 0, zz = fullTileRanges.length; z < zz; ++z) {
|
||||||
|
tileSize = ol.size.toSize(this.getTileSize(z), this.tmpSize_);
|
||||||
|
fullTileRanges[z] = new ol.TileRange(
|
||||||
|
0, Math.ceil(extentWidth / tileSize[0] / this.resolutions_[z]) - 1,
|
||||||
|
0, Math.ceil(extentHeight / tileSize[1] / this.resolutions_[z]) - 1);
|
||||||
|
}
|
||||||
|
this.fullTileRanges_ = fullTileRanges;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.proj.Projection} projection Projection.
|
* @param {ol.proj.Projection} projection Projection.
|
||||||
* @return {ol.tilegrid.TileGrid} Default tile grid for the passed projection.
|
* @return {ol.tilegrid.TileGrid} Default tile grid for the passed projection.
|
||||||
@@ -562,6 +576,17 @@ ol.tilegrid.createXYZ = function(opt_options) {
|
|||||||
options.resolutions = ol.tilegrid.resolutionsFromExtent(
|
options.resolutions = ol.tilegrid.resolutionsFromExtent(
|
||||||
options.extent, options.maxZoom, options.tileSize);
|
options.extent, options.maxZoom, options.tileSize);
|
||||||
delete options.maxZoom;
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
return new ol.tilegrid.TileGrid(options);
|
return new ol.tilegrid.TileGrid(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,61 +19,65 @@ goog.require('ol.tilegrid.TileGrid');
|
|||||||
*/
|
*/
|
||||||
ol.tilegrid.Zoomify = function(opt_options) {
|
ol.tilegrid.Zoomify = function(opt_options) {
|
||||||
var options = goog.isDef(opt_options) ? opt_options : options;
|
var options = goog.isDef(opt_options) ? opt_options : options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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}
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {
|
||||||
|
createTileCoordTransform: createTileCoordTransform,
|
||||||
origin: [0, 0],
|
origin: [0, 0],
|
||||||
resolutions: options.resolutions
|
resolutions: options.resolutions
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.tilegrid.Zoomify, ol.tilegrid.TileGrid);
|
goog.inherits(ol.tilegrid.Zoomify, ol.tilegrid.TileGrid);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.tilegrid.Zoomify.prototype.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
35
test/spec/ol/source/tilevectorsource.test.js
Normal file
35
test/spec/ol/source/tilevectorsource.test.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
goog.provide('ol.test.source.TileVector');
|
||||||
|
|
||||||
|
|
||||||
|
describe('ol.source.TileVector', function() {
|
||||||
|
|
||||||
|
describe('#loadFeatures()', function() {
|
||||||
|
|
||||||
|
it('calls tileUrlFunction with correct tile coords', function() {
|
||||||
|
var tileCoords = [];
|
||||||
|
var source = new ol.source.TileVector({
|
||||||
|
format: new ol.format.TopoJSON(),
|
||||||
|
projection: 'EPSG:3857',
|
||||||
|
tileGrid: ol.tilegrid.createXYZ({
|
||||||
|
maxZoom: 19
|
||||||
|
}),
|
||||||
|
tileUrlFunction: function(tileCoord) {
|
||||||
|
tileCoords.push(tileCoord.slice());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
source.loadFeatures(
|
||||||
|
[-8238854, 4969777, -8237854, 4970777], 4.8, source.getProjection());
|
||||||
|
expect(tileCoords[0]).to.eql([15, 9647, 12320]);
|
||||||
|
expect(tileCoords[1]).to.eql([15, 9647, 12319]);
|
||||||
|
expect(tileCoords[2]).to.eql([15, 9648, 12320]);
|
||||||
|
expect(tileCoords[3]).to.eql([15, 9648, 12319]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
goog.require('ol.format.TopoJSON');
|
||||||
|
goog.require('ol.source.TileVector');
|
||||||
Reference in New Issue
Block a user