From 14e20e23a00adb9533a36ecece15806ed0d4b294 Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Tue, 25 Aug 2015 17:35:07 +0200 Subject: [PATCH] Correctly reproject projections with undefined units --- src/ol/reproj/image.js | 13 ++++--------- src/ol/reproj/reproj.js | 8 ++++++-- src/ol/reproj/tile.js | 38 +++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/ol/reproj/image.js b/src/ol/reproj/image.js index 6841372bbe..af9e266afd 100644 --- a/src/ol/reproj/image.js +++ b/src/ol/reproj/image.js @@ -36,20 +36,19 @@ ol.reproj.Image = function(sourceProj, targetProj, var limitedTargetExtent = ol.extent.getIntersection( targetExtent, maxTargetExtent); + var targetCenter = ol.extent.getCenter(limitedTargetExtent); + var sourceResolution = ol.reproj.calculateSourceResolution( + sourceProj, targetProj, targetCenter, targetResolution); var errorThresholdInPixels = ol.DEFAULT_RASTER_REPROJ_ERROR_THRESHOLD; - // in source units - var errorThreshold = targetResolution * errorThresholdInPixels * - targetProj.getMetersPerUnit() / sourceProj.getMetersPerUnit(); - /** * @private * @type {!ol.reproj.Triangulation} */ this.triangulation_ = new ol.reproj.Triangulation( sourceProj, targetProj, limitedTargetExtent, this.maxSourceExtent_, - errorThreshold); + sourceResolution * errorThresholdInPixels); /** * @private @@ -65,10 +64,6 @@ ol.reproj.Image = function(sourceProj, targetProj, var srcExtent = this.triangulation_.calculateSourceExtent(); - var targetCenter = ol.extent.getCenter(targetExtent); - var sourceResolution = ol.reproj.calculateSourceResolution( - sourceProj, targetProj, targetCenter, targetResolution); - /** * @private * @type {ol.ImageBase} diff --git a/src/ol/reproj/reproj.js b/src/ol/reproj/reproj.js index 6dc5e90325..db42c15f68 100644 --- a/src/ol/reproj/reproj.js +++ b/src/ol/reproj/reproj.js @@ -27,10 +27,14 @@ ol.reproj.calculateSourceResolution = function(sourceProj, targetProj, var sourceCenter = ol.proj.transform(targetCenter, targetProj, sourceProj); + var targetMPU = targetProj.getMetersPerUnit(); + var sourceMPU = sourceProj.getMetersPerUnit(); + // calculate the ideal resolution of the source data var sourceResolution = - targetProj.getPointResolution(targetResolution, targetCenter) * - targetProj.getMetersPerUnit() / sourceProj.getMetersPerUnit(); + targetProj.getPointResolution(targetResolution, targetCenter); + if (goog.isDef(targetMPU)) sourceResolution *= targetMPU; + if (goog.isDef(sourceMPU)) sourceResolution /= sourceMPU; // based on the projection properties, the point resolution at the specified // coordinates may be slightly different. We need to reverse-compensate this diff --git a/src/ol/reproj/tile.js b/src/ol/reproj/tile.js index a6472e30f6..17ed887718 100644 --- a/src/ol/reproj/tile.js +++ b/src/ol/reproj/tile.js @@ -117,27 +117,6 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, var targetResolution = targetTileGrid.getResolution(z); - var errorThresholdInPixels = goog.isDef(opt_errorThreshold) ? - opt_errorThreshold : ol.DEFAULT_RASTER_REPROJ_ERROR_THRESHOLD; - - // in source units - var errorThreshold = targetResolution * errorThresholdInPixels * - targetProj.getMetersPerUnit() / sourceProj.getMetersPerUnit(); - - /** - * @private - * @type {!ol.reproj.Triangulation} - */ - this.triangulation_ = new ol.reproj.Triangulation( - sourceProj, targetProj, limitedTargetExtent, maxSourceExtent, - errorThreshold); - - if (this.triangulation_.getTriangles().length === 0) { - // no valid triangles -> EMPTY - this.state = ol.TileState.EMPTY; - return; - } - var targetCenter = ol.extent.getCenter(limitedTargetExtent); var sourceResolution = ol.reproj.calculateSourceResolution( sourceProj, targetProj, targetCenter, targetResolution); @@ -149,6 +128,23 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, return; } + var errorThresholdInPixels = goog.isDef(opt_errorThreshold) ? + opt_errorThreshold : ol.DEFAULT_RASTER_REPROJ_ERROR_THRESHOLD; + + /** + * @private + * @type {!ol.reproj.Triangulation} + */ + this.triangulation_ = new ol.reproj.Triangulation( + sourceProj, targetProj, limitedTargetExtent, maxSourceExtent, + sourceResolution * errorThresholdInPixels); + + if (this.triangulation_.getTriangles().length === 0) { + // no valid triangles -> EMPTY + this.state = ol.TileState.EMPTY; + return; + } + this.srcZ_ = sourceTileGrid.getZForResolution(sourceResolution); var srcExtent = this.triangulation_.calculateSourceExtent();