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:
+29
-12
@@ -3,7 +3,7 @@ goog.provide('ol.tilecoord');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.math');
|
||||
goog.require('ol.extent');
|
||||
|
||||
|
||||
/**
|
||||
@@ -149,25 +149,42 @@ ol.tilecoord.toString = function(tileCoord) {
|
||||
*/
|
||||
ol.tilecoord.wrapX = function(tileCoord, tileGrid, projection) {
|
||||
var z = tileCoord[0];
|
||||
var x = tileCoord[1];
|
||||
var tileRange = tileGrid.getTileRange(z, projection);
|
||||
if (x < tileRange.minX || x > tileRange.maxX) {
|
||||
x = goog.math.modulo(x, tileRange.getWidth());
|
||||
return [z, x, tileCoord[2]];
|
||||
var center = tileGrid.getTileCoordCenter(tileCoord);
|
||||
var projectionExtent = ol.tilegrid.extentFromProjection(projection);
|
||||
if (!ol.extent.containsCoordinate(projectionExtent, center)) {
|
||||
var worldWidth = ol.extent.getWidth(projectionExtent);
|
||||
var worldsAway = Math.ceil((projectionExtent[0] - center[0]) / worldWidth);
|
||||
center[0] += worldWidth * worldsAway;
|
||||
return tileGrid.getTileCoordForCoordAndZ(center, z);
|
||||
} else {
|
||||
return tileCoord;
|
||||
}
|
||||
return tileCoord;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||
* @return {ol.TileCoord} Tile coordinate.
|
||||
*/
|
||||
ol.tilecoord.clipX = function(tileCoord, tileGrid, projection) {
|
||||
ol.tilecoord.restrictByExtentAndZ = function(tileCoord, tileGrid) {
|
||||
var z = tileCoord[0];
|
||||
var x = tileCoord[1];
|
||||
var tileRange = tileGrid.getTileRange(z, projection);
|
||||
return (x < tileRange.minX || x > tileRange.maxX) ? null : tileCoord;
|
||||
var y = tileCoord[2];
|
||||
|
||||
if (tileGrid.getMinZoom() > z || z > tileGrid.getMaxZoom()) {
|
||||
return null;
|
||||
}
|
||||
var extent = tileGrid.getExtent();
|
||||
var tileRange;
|
||||
if (goog.isNull(extent)) {
|
||||
tileRange = tileGrid.getFullTileRange(z);
|
||||
} else {
|
||||
tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
|
||||
}
|
||||
if (goog.isNull(tileRange)) {
|
||||
return tileCoord;
|
||||
} else {
|
||||
return tileRange.containsXY(x, y) ? tileCoord : null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user