Skip to content

Commit 48c8f9e

Browse files
committed
Merge pull request #4551 from klokantech/rasterreproj-wrapx
Handle tile coordinate wrapping when reprojecting raster tiles
2 parents c4237c7 + 9f5d85f commit 48c8f9e

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

src/ol/reproj/tile.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ ol.reproj.TileFunctionType;
3333
* @param {ol.tilegrid.TileGrid} sourceTileGrid Source tile grid.
3434
* @param {ol.proj.Projection} targetProj Target projection.
3535
* @param {ol.tilegrid.TileGrid} targetTileGrid Target tile grid.
36-
* @param {number} z Zoom level.
37-
* @param {number} x X.
38-
* @param {number} y Y.
36+
* @param {ol.TileCoord} tileCoord Coordinate of the tile.
37+
* @param {ol.TileCoord} wrappedTileCoord Coordinate of the tile wrapped in X.
3938
* @param {number} pixelRatio Pixel ratio.
4039
* @param {ol.reproj.TileFunctionType} getTileFunction
4140
* Function returning source tiles (z, x, y, pixelRatio).
4241
* @param {number=} opt_errorThreshold Acceptable reprojection error (in px).
4342
* @param {boolean=} opt_renderEdges Render reprojection edges.
4443
*/
4544
ol.reproj.Tile = function(sourceProj, sourceTileGrid,
46-
targetProj, targetTileGrid, z, x, y, pixelRatio, getTileFunction,
45+
targetProj, targetTileGrid, tileCoord, wrappedTileCoord,
46+
pixelRatio, getTileFunction,
4747
opt_errorThreshold,
4848
opt_renderEdges) {
49-
goog.base(this, [z, x, y], ol.TileState.IDLE);
49+
goog.base(this, tileCoord, ol.TileState.IDLE);
5050

5151
/**
5252
* @private
@@ -84,6 +84,12 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
8484
*/
8585
this.targetTileGrid_ = targetTileGrid;
8686

87+
/**
88+
* @private
89+
* @type {ol.TileCoord}
90+
*/
91+
this.wrappedTileCoord_ = wrappedTileCoord ? wrappedTileCoord : tileCoord;
92+
8793
/**
8894
* @private
8995
* @type {!Array.<ol.Tile>}
@@ -102,7 +108,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
102108
*/
103109
this.sourceZ_ = 0;
104110

105-
var targetExtent = targetTileGrid.getTileCoordExtent(this.getTileCoord());
111+
var targetExtent = targetTileGrid.getTileCoordExtent(this.wrappedTileCoord_);
106112
var maxTargetExtent = this.targetTileGrid_.getExtent();
107113
var maxSourceExtent = this.sourceTileGrid_.getExtent();
108114

@@ -126,7 +132,8 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
126132
}
127133
}
128134

129-
var targetResolution = targetTileGrid.getResolution(z);
135+
var targetResolution = targetTileGrid.getResolution(
136+
this.wrappedTileCoord_[0]);
130137

131138
var targetCenter = ol.extent.getCenter(limitedTargetExtent);
132139
var sourceResolution = ol.reproj.calculateSourceResolution(
@@ -248,15 +255,15 @@ ol.reproj.Tile.prototype.reproject_ = function() {
248255
}, this);
249256
this.sourceTiles_.length = 0;
250257

251-
var tileCoord = this.getTileCoord();
252-
var z = tileCoord[0];
258+
var z = this.wrappedTileCoord_[0];
253259
var size = this.targetTileGrid_.getTileSize(z);
254260
var width = goog.isNumber(size) ? size : size[0];
255261
var height = goog.isNumber(size) ? size : size[1];
256262
var targetResolution = this.targetTileGrid_.getResolution(z);
257263
var sourceResolution = this.sourceTileGrid_.getResolution(this.sourceZ_);
258264

259-
var targetExtent = this.targetTileGrid_.getTileCoordExtent(tileCoord);
265+
var targetExtent = this.targetTileGrid_.getTileCoordExtent(
266+
this.wrappedTileCoord_);
260267
this.canvas_ = ol.reproj.render(width, height, this.pixelRatio_,
261268
sourceResolution, this.sourceTileGrid_.getExtent(),
262269
targetResolution, targetExtent, this.triangulation_, sources,

src/ol/source/tileimagesource.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,20 @@ ol.source.TileImage.prototype.getTile =
204204
return this.getTileInternal(z, x, y, pixelRatio, projection);
205205
} else {
206206
var cache = this.getTileCacheForProjection(projection);
207-
var tileCoordKey = this.getKeyZXY(z, x, y);
207+
var tileCoord = [z, x, y];
208+
var tileCoordKey = this.getKeyZXY.apply(this, tileCoord);
208209
if (cache.containsKey(tileCoordKey)) {
209210
return /** @type {!ol.Tile} */ (cache.get(tileCoordKey));
210211
} else {
211212
var sourceProjection = this.getProjection();
212213
var sourceTileGrid = this.getTileGridForProjection(sourceProjection);
213214
var targetTileGrid = this.getTileGridForProjection(projection);
215+
var wrappedTileCoord =
216+
this.getTileCoordForTileUrlFunction(tileCoord, projection);
214217
var tile = new ol.reproj.Tile(
215218
sourceProjection, sourceTileGrid,
216219
projection, targetTileGrid,
217-
z, x, y, this.getTilePixelRatio(),
220+
tileCoord, wrappedTileCoord, this.getTilePixelRatio(),
218221
goog.bind(function(z, x, y, pixelRatio) {
219222
return this.getTileInternal(z, x, y, pixelRatio, sourceProjection);
220223
}, this), this.reprojectionErrorThreshold_,

test/spec/ol/reproj/tile.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('ol.reproj.Tile', function() {
2121
return new ol.reproj.Tile(
2222
proj3857, ol.tilegrid.createForProjection(proj3857), proj4326,
2323
ol.tilegrid.createForProjection(proj4326, 3, opt_tileSize),
24-
3, 2, -2, pixelRatio, function(z, x, y, pixelRatio) {
24+
[3, 2, -2], null, pixelRatio, function(z, x, y, pixelRatio) {
2525
return new ol.ImageTile([z, x, y], ol.TileState.IDLE,
2626
'data:image/gif;base64,' +
2727
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=', null,
@@ -48,7 +48,7 @@ describe('ol.reproj.Tile', function() {
4848
var tile = new ol.reproj.Tile(
4949
proj3857, ol.tilegrid.createForProjection(proj3857),
5050
proj4326, ol.tilegrid.createForProjection(proj4326),
51-
0, -1, 0, 1, function() {
51+
[0, -1, 0], null, 1, function() {
5252
expect().fail('No tiles should be required');
5353
});
5454
expect(tile.getState()).to.be(ol.TileState.EMPTY);
@@ -60,7 +60,7 @@ describe('ol.reproj.Tile', function() {
6060
var tile = new ol.reproj.Tile(
6161
proj27700, ol.tilegrid.createForProjection(proj27700),
6262
proj4326, ol.tilegrid.createForProjection(proj4326),
63-
3, 2, -2, 1, function() {
63+
[3, 2, -2], null, 1, function() {
6464
expect().fail('No tiles should be required');
6565
});
6666
expect(tile.getState()).to.be(ol.TileState.EMPTY);

test_rendering/spec/ol/reproj/tile.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ describe('ol.rendering.reproj.Tile', function() {
99
var tilesRequested = 0;
1010

1111
var tile = new ol.reproj.Tile(sourceProjection, source.getTileGrid(),
12-
ol.proj.get(targetProjection), targetTileGrid, z, x, y, pixelRatio,
12+
ol.proj.get(targetProjection), targetTileGrid,
13+
[z, x, y], null, pixelRatio,
1314
function(z, x, y, pixelRatio) {
1415
tilesRequested++;
1516
return source.getTile(z, x, y, pixelRatio, sourceProjection);

0 commit comments

Comments
 (0)