Correctly reproject projections with undefined units

This commit is contained in:
Petr Sloup
2015-08-25 17:35:07 +02:00
parent aad5f94556
commit 14e20e23a0
3 changed files with 27 additions and 32 deletions

View File

@@ -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}

View File

@@ -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

View File

@@ -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();