Respect the tile grid's extent

By adding a getTileCoordForTileUrlFuction method like for ol.source.Tile,
we can now properly handle extent and resolution restrictions, and reuse
tiles on wrapped worlds. Also adds the missing wrapX option to
ol.source.TileVector.
This commit is contained in:
Andreas Hocevar
2015-06-15 11:15:25 +02:00
parent e848acd806
commit 2bcb10c973
3 changed files with 93 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ goog.require('ol.TileUrlFunction');
goog.require('ol.featureloader');
goog.require('ol.source.State');
goog.require('ol.source.Vector');
goog.require('ol.tilecoord');
goog.require('ol.tilegrid.TileGrid');
@@ -27,7 +28,8 @@ ol.source.TileVector = function(options) {
attributions: options.attributions,
logo: options.logo,
projection: undefined,
state: ol.source.State.READY
state: ol.source.State.READY,
wrapX: options.wrapX
});
/**
@@ -230,6 +232,28 @@ ol.source.TileVector.prototype.getFeaturesAtCoordinateAndResolution =
ol.source.TileVector.prototype.getFeaturesInExtent = goog.abstractMethod;
/**
* 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} projection Projection.
* @return {ol.TileCoord} Tile coordinate to be passed to the tileUrlFunction or
* null if no tile URL should be created for the passed `tileCoord`.
*/
ol.source.TileVector.prototype.getTileCoordForTileUrlFunction =
function(tileCoord, projection) {
var tileGrid = this.tileGrid_;
goog.asserts.assert(!goog.isNull(tileGrid), 'tile grid needed');
if (this.getWrapX()) {
tileCoord = ol.tilecoord.wrapX(tileCoord, tileGrid, projection);
}
return ol.tilecoord.withinExtentAndZ(tileCoord, tileGrid) ?
tileGrid.transformTileCoord(tileCoord) : null;
};
/**
* @param {number} z Z.
* @param {number} x X.
@@ -267,11 +291,12 @@ ol.source.TileVector.prototype.loadFeatures =
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
var tileKey = this.getTileKeyZXY_(z, x, y);
if (!(tileKey in tiles)) {
tileCoord[0] = z;
tileCoord[1] = x;
tileCoord[2] = y;
tileGrid.transformTileCoord(tileCoord, tileCoord);
var url = tileUrlFunction(tileCoord, 1, projection);
var urlTileCoord = this.getTileCoordForTileUrlFunction(
tileCoord, projection);
var url = goog.isNull(urlTileCoord) ? undefined :
tileUrlFunction(urlTileCoord, 1, projection);
if (goog.isDef(url)) {
tiles[tileKey] = [];
var loader = ol.featureloader.loadFeaturesXhr(url, this.format_,