Move wrapX to ol.tilegrid to break circular dependency

This commit is contained in:
Tim Schaub
2016-08-08 13:48:54 -06:00
parent 789aeb1c64
commit 568f0c81bb
3 changed files with 23 additions and 25 deletions
+22
View File
@@ -1,5 +1,6 @@
goog.provide('ol.tilegrid');
goog.require('ol.extent');
goog.require('ol.extent.Corner');
goog.require('ol.obj');
goog.require('ol.proj');
@@ -22,6 +23,27 @@ ol.tilegrid.getForProjection = function(projection) {
};
/**
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.proj.Projection} projection Projection.
* @return {ol.TileCoord} Tile coordinate.
*/
ol.tilegrid.wrapX = function(tileGrid, tileCoord, projection) {
var z = tileCoord[0];
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;
}
};
/**
* @param {ol.Extent} extent Extent.
* @param {number=} opt_maxZoom Maximum zoom level (default is