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

View File

@@ -282,7 +282,7 @@ ol.source.Tile.prototype.getTileCoordForTileUrlFunction = function(tileCoord, op
opt_projection : this.getProjection(); opt_projection : this.getProjection();
var tileGrid = this.getTileGridForProjection(projection); var tileGrid = this.getTileGridForProjection(projection);
if (this.getWrapX() && projection.isGlobal()) { if (this.getWrapX() && projection.isGlobal()) {
tileCoord = ol.tilecoord.wrapX(tileCoord, tileGrid, projection); tileCoord = ol.tilegrid.wrapX(tileGrid, tileCoord, projection);
} }
return ol.tilecoord.withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null; return ol.tilecoord.withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
}; };

View File

@@ -1,8 +1,5 @@
goog.provide('ol.tilecoord'); goog.provide('ol.tilecoord');
goog.require('ol.extent');
goog.require('ol.tilegrid');
/** /**
* @enum {number} * @enum {number}
@@ -93,27 +90,6 @@ ol.tilecoord.quadKey = function(tileCoord) {
}; };
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @param {ol.proj.Projection} projection Projection.
* @return {ol.TileCoord} Tile coordinate.
*/
ol.tilecoord.wrapX = function(tileCoord, tileGrid, 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.TileCoord} tileCoord Tile coordinate. * @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {!ol.tilegrid.TileGrid} tileGrid Tile grid. * @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.

View File

@@ -1,5 +1,6 @@
goog.provide('ol.tilegrid'); goog.provide('ol.tilegrid');
goog.require('ol.extent');
goog.require('ol.extent.Corner'); goog.require('ol.extent.Corner');
goog.require('ol.obj'); goog.require('ol.obj');
goog.require('ol.proj'); 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 {ol.Extent} extent Extent.
* @param {number=} opt_maxZoom Maximum zoom level (default is * @param {number=} opt_maxZoom Maximum zoom level (default is