Allow extents to restrict tile ranges requested from the server
The addition of full extent tile ranges also allows us to simplify wrapX handling for tile layers. By limiting wrapX to true and false as possible values, we can remove a lot of guessing logic.
This commit is contained in:
@@ -75,9 +75,9 @@ ol.source.Source = function(options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean|undefined}
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.wrapX_ = options.wrapX;
|
||||
this.wrapX_ = goog.isDef(options.wrapX) ? options.wrapX : false;
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.Source, ol.Object);
|
||||
|
||||
@@ -93,7 +93,8 @@ ol.source.TileImage.prototype.getTile =
|
||||
} else {
|
||||
goog.asserts.assert(projection, 'argument projection is truthy');
|
||||
var tileCoord = [z, x, y];
|
||||
var urlTileCoord = this.getWrapXTileCoord(tileCoord, projection);
|
||||
var urlTileCoord = this.getTileCoordForTileUrlFunction(
|
||||
tileCoord, projection);
|
||||
var tileUrl = goog.isNull(urlTileCoord) ? undefined :
|
||||
this.tileUrlFunction(urlTileCoord, pixelRatio, projection);
|
||||
var tile = new this.tileClass(
|
||||
|
||||
+10
-14
@@ -2,6 +2,7 @@ goog.provide('ol.source.Tile');
|
||||
goog.provide('ol.source.TileEvent');
|
||||
goog.provide('ol.source.TileOptions');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Extent');
|
||||
@@ -216,28 +217,23 @@ ol.source.Tile.prototype.getTilePixelSize =
|
||||
|
||||
|
||||
/**
|
||||
* Handles x-axis wrapping. When `wrapX` is `undefined` or the projection is not
|
||||
* a global projection, `tileCoord` will be returned unaltered. When `wrapX` is
|
||||
* `true`, the tile coordinate will be wrapped horizontally.
|
||||
* When `wrapX` is `false`, `null` will be returned for tiles that are
|
||||
* outside the projection extent.
|
||||
* Handles x-axis wrapping and returns a tile coordinate when it is within
|
||||
* the resolution and extent range.
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {ol.proj.Projection=} opt_projection Projection.
|
||||
* @return {ol.TileCoord} Tile coordinate.
|
||||
* @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.Tile.prototype.getWrapXTileCoord =
|
||||
ol.source.Tile.prototype.getTileCoordForTileUrlFunction =
|
||||
function(tileCoord, opt_projection) {
|
||||
var projection = goog.isDef(opt_projection) ?
|
||||
opt_projection : this.getProjection();
|
||||
var tileGrid = this.getTileGridForProjection(projection);
|
||||
var wrapX = this.getWrapX();
|
||||
if (goog.isDef(wrapX) && tileGrid.isGlobal(tileCoord[0], projection)) {
|
||||
return wrapX ?
|
||||
ol.tilecoord.wrapX(tileCoord, tileGrid, projection) :
|
||||
ol.tilecoord.clipX(tileCoord, tileGrid, projection);
|
||||
} else {
|
||||
return tileCoord;
|
||||
goog.asserts.assert(!goog.isNull(tileGrid), 'tile grid needed');
|
||||
if (this.getWrapX()) {
|
||||
tileCoord = ol.tilecoord.wrapX(tileCoord, tileGrid, projection);
|
||||
}
|
||||
return ol.tilecoord.restrictByExtentAndZ(tileCoord, tileGrid);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ ol.source.TileWMS = function(opt_options) {
|
||||
tileGrid: options.tileGrid,
|
||||
tileLoadFunction: options.tileLoadFunction,
|
||||
tileUrlFunction: goog.bind(this.tileUrlFunction_, this),
|
||||
wrapX: options.wrapX
|
||||
wrapX: goog.isDef(options.wrapX) ? options.wrapX : true
|
||||
});
|
||||
|
||||
var urls = options.urls;
|
||||
|
||||
+14
-28
@@ -11,7 +11,6 @@ goog.require('ol.TileUrlFunctionType');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.TileImage');
|
||||
goog.require('ol.tilecoord');
|
||||
goog.require('ol.tilegrid.WMTS');
|
||||
|
||||
|
||||
@@ -181,31 +180,8 @@ ol.source.WMTS = function(options) {
|
||||
goog.array.map(this.urls_, createFromWMTSTemplate)) :
|
||||
ol.TileUrlFunction.nullTileUrlFunction;
|
||||
|
||||
var tmpExtent = ol.extent.createEmpty();
|
||||
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @param {ol.TileCoord=} opt_tileCoord Tile coordinate.
|
||||
* @return {ol.TileCoord} Tile coordinate.
|
||||
*/
|
||||
function(tileCoord, projection, opt_tileCoord) {
|
||||
goog.asserts.assert(!goog.isNull(tileGrid),
|
||||
'tileGrid must not be null');
|
||||
if (tileGrid.getResolutions().length <= tileCoord[0]) {
|
||||
return null;
|
||||
}
|
||||
var x = tileCoord[1];
|
||||
var y = -tileCoord[2] - 1;
|
||||
var tileExtent = tileGrid.getTileCoordExtent(tileCoord, tmpExtent);
|
||||
var extent = projection.getExtent();
|
||||
|
||||
if (!ol.extent.intersects(tileExtent, extent) ||
|
||||
ol.extent.touches(tileExtent, extent)) {
|
||||
return null;
|
||||
}
|
||||
return ol.tilecoord.createOrUpdate(tileCoord[0], x, y, opt_tileCoord);
|
||||
},
|
||||
ol.tilegrid.createOriginTopLeftTileCoordTransform(tileGrid),
|
||||
tileUrlFunction);
|
||||
|
||||
goog.base(this, {
|
||||
@@ -450,9 +426,6 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
|
||||
goog.asserts.assert(!goog.isNull(matrixSetObj),
|
||||
'found matrixSet in Contents/TileMatrixSet');
|
||||
|
||||
var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
|
||||
matrixSetObj);
|
||||
|
||||
var projection;
|
||||
if (goog.isDef(config['projection'])) {
|
||||
projection = ol.proj.get(config['projection']);
|
||||
@@ -461,6 +434,19 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
|
||||
/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3'));
|
||||
}
|
||||
|
||||
var projectionExtent = projection.getExtent();
|
||||
var extent;
|
||||
if (!goog.isNull(projectionExtent)) {
|
||||
var projectionExtentWgs84 = ol.proj.transformExtent(
|
||||
projectionExtent, projection, 'EPSG:4326');
|
||||
if (ol.extent.containsExtent(projectionExtentWgs84, wgs84BoundingBox)) {
|
||||
extent = ol.proj.transformExtent(
|
||||
wgs84BoundingBox, 'EPSG:4326', projection);
|
||||
}
|
||||
}
|
||||
var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
|
||||
matrixSetObj, extent);
|
||||
|
||||
/** @type {!Array.<string>} */
|
||||
var urls = [];
|
||||
var requestEncoding = config['requestEncoding'];
|
||||
|
||||
Reference in New Issue
Block a user