Rename some private/local variables to increase readability
This commit is contained in:
@@ -72,19 +72,21 @@ ol.reproj.Image = function(sourceProj, targetProj,
|
||||
*/
|
||||
this.targetExtent_ = targetExtent;
|
||||
|
||||
var srcExtent = this.triangulation_.calculateSourceExtent();
|
||||
var sourceExtent = this.triangulation_.calculateSourceExtent();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.ImageBase}
|
||||
*/
|
||||
this.srcImage_ = getImageFunction(srcExtent, sourceResolution, pixelRatio);
|
||||
this.sourceImage_ =
|
||||
getImageFunction(sourceExtent, sourceResolution, pixelRatio);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.srcPixelRatio_ = this.srcImage_ ? this.srcImage_.getPixelRatio() : 1;
|
||||
this.sourcePixelRatio_ =
|
||||
this.sourceImage_ ? this.sourceImage_.getPixelRatio() : 1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -102,12 +104,12 @@ ol.reproj.Image = function(sourceProj, targetProj,
|
||||
var state = ol.ImageState.LOADED;
|
||||
var attributions = [];
|
||||
|
||||
if (this.srcImage_) {
|
||||
if (this.sourceImage_) {
|
||||
state = ol.ImageState.IDLE;
|
||||
attributions = this.srcImage_.getAttributions();
|
||||
attributions = this.sourceImage_.getAttributions();
|
||||
}
|
||||
|
||||
goog.base(this, targetExtent, targetResolution, this.srcPixelRatio_,
|
||||
goog.base(this, targetExtent, targetResolution, this.sourcePixelRatio_,
|
||||
state, attributions);
|
||||
};
|
||||
goog.inherits(ol.reproj.Image, ol.ImageBase);
|
||||
@@ -144,20 +146,20 @@ ol.reproj.Image.prototype.getProjection = function() {
|
||||
* @private
|
||||
*/
|
||||
ol.reproj.Image.prototype.reproject_ = function() {
|
||||
var srcState = this.srcImage_.getState();
|
||||
if (srcState == ol.ImageState.LOADED) {
|
||||
var sourceState = this.sourceImage_.getState();
|
||||
if (sourceState == ol.ImageState.LOADED) {
|
||||
var width = ol.extent.getWidth(this.targetExtent_) / this.targetResolution_;
|
||||
var height =
|
||||
ol.extent.getHeight(this.targetExtent_) / this.targetResolution_;
|
||||
|
||||
this.canvas_ = ol.reproj.render(width, height, this.srcPixelRatio_,
|
||||
this.srcImage_.getResolution(), this.maxSourceExtent_,
|
||||
this.canvas_ = ol.reproj.render(width, height, this.sourcePixelRatio_,
|
||||
this.sourceImage_.getResolution(), this.maxSourceExtent_,
|
||||
this.targetResolution_, this.targetExtent_, this.triangulation_, [{
|
||||
extent: this.srcImage_.getExtent(),
|
||||
image: this.srcImage_.getImage()
|
||||
extent: this.sourceImage_.getExtent(),
|
||||
image: this.sourceImage_.getImage()
|
||||
}]);
|
||||
}
|
||||
this.state = srcState;
|
||||
this.state = sourceState;
|
||||
this.changed();
|
||||
};
|
||||
|
||||
@@ -170,21 +172,21 @@ ol.reproj.Image.prototype.load = function() {
|
||||
this.state = ol.ImageState.LOADING;
|
||||
this.changed();
|
||||
|
||||
var srcState = this.srcImage_.getState();
|
||||
if (srcState == ol.ImageState.LOADED ||
|
||||
srcState == ol.ImageState.ERROR) {
|
||||
var sourceState = this.sourceImage_.getState();
|
||||
if (sourceState == ol.ImageState.LOADED ||
|
||||
sourceState == ol.ImageState.ERROR) {
|
||||
this.reproject_();
|
||||
} else {
|
||||
this.sourceListenerKey_ = this.srcImage_.listen(
|
||||
this.sourceListenerKey_ = this.sourceImage_.listen(
|
||||
goog.events.EventType.CHANGE, function(e) {
|
||||
var srcState = this.srcImage_.getState();
|
||||
if (srcState == ol.ImageState.LOADED ||
|
||||
srcState == ol.ImageState.ERROR) {
|
||||
var sourceState = this.sourceImage_.getState();
|
||||
if (sourceState == ol.ImageState.LOADED ||
|
||||
sourceState == ol.ImageState.ERROR) {
|
||||
this.unlistenSource_();
|
||||
this.reproject_();
|
||||
}
|
||||
}, false, this);
|
||||
this.srcImage_.load();
|
||||
this.sourceImage_.load();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -44,13 +44,13 @@ ol.reproj.calculateSourceResolution = function(sourceProj, targetProj,
|
||||
var sourceResolution =
|
||||
targetProj.getPointResolution(targetResolution, targetCenter);
|
||||
|
||||
var targetMPU = targetProj.getMetersPerUnit();
|
||||
if (targetMPU !== undefined) {
|
||||
sourceResolution *= targetMPU;
|
||||
var targetMetersPerUnit = targetProj.getMetersPerUnit();
|
||||
if (targetMetersPerUnit !== undefined) {
|
||||
sourceResolution *= targetMetersPerUnit;
|
||||
}
|
||||
var sourceMPU = sourceProj.getMetersPerUnit();
|
||||
if (sourceMPU !== undefined) {
|
||||
sourceResolution /= sourceMPU;
|
||||
var sourceMetersPerUnit = sourceProj.getMetersPerUnit();
|
||||
if (sourceMetersPerUnit !== undefined) {
|
||||
sourceResolution /= sourceMetersPerUnit;
|
||||
}
|
||||
|
||||
// Based on the projection properties, the point resolution at the specified
|
||||
@@ -134,46 +134,45 @@ ol.reproj.render = function(width, height, pixelRatio,
|
||||
}
|
||||
}
|
||||
|
||||
var srcDataExtent = ol.extent.createEmpty();
|
||||
var sourceDataExtent = ol.extent.createEmpty();
|
||||
sources.forEach(function(src, i, arr) {
|
||||
if (wrapXType == ol.reproj.WrapXRendering_.STITCH_SHIFT) {
|
||||
var srcW = src.extent[2] - src.extent[0];
|
||||
var srcX = goog.math.modulo(src.extent[0], wrapXShiftDistance);
|
||||
ol.extent.extend(srcDataExtent, [srcX, src.extent[1],
|
||||
srcX + srcW, src.extent[3]]);
|
||||
ol.extent.extend(sourceDataExtent, [srcX, src.extent[1],
|
||||
srcX + srcW, src.extent[3]]);
|
||||
} else {
|
||||
ol.extent.extend(srcDataExtent, src.extent);
|
||||
ol.extent.extend(sourceDataExtent, src.extent);
|
||||
}
|
||||
});
|
||||
if (sourceExtent) {
|
||||
if (wrapXType == ol.reproj.WrapXRendering_.NONE) {
|
||||
srcDataExtent[0] = ol.math.clamp(
|
||||
srcDataExtent[0], sourceExtent[0], sourceExtent[2]);
|
||||
srcDataExtent[2] = ol.math.clamp(
|
||||
srcDataExtent[2], sourceExtent[0], sourceExtent[2]);
|
||||
sourceDataExtent[0] = ol.math.clamp(
|
||||
sourceDataExtent[0], sourceExtent[0], sourceExtent[2]);
|
||||
sourceDataExtent[2] = ol.math.clamp(
|
||||
sourceDataExtent[2], sourceExtent[0], sourceExtent[2]);
|
||||
}
|
||||
srcDataExtent[1] = ol.math.clamp(
|
||||
srcDataExtent[1], sourceExtent[1], sourceExtent[3]);
|
||||
srcDataExtent[3] = ol.math.clamp(
|
||||
srcDataExtent[3], sourceExtent[1], sourceExtent[3]);
|
||||
sourceDataExtent[1] = ol.math.clamp(
|
||||
sourceDataExtent[1], sourceExtent[1], sourceExtent[3]);
|
||||
sourceDataExtent[3] = ol.math.clamp(
|
||||
sourceDataExtent[3], sourceExtent[1], sourceExtent[3]);
|
||||
}
|
||||
|
||||
var srcDataWidth = ol.extent.getWidth(srcDataExtent);
|
||||
var srcDataHeight = ol.extent.getHeight(srcDataExtent);
|
||||
var canvasWidthInUnits;
|
||||
if (wrapXType == ol.reproj.WrapXRendering_.STITCH_EXTENDED) {
|
||||
canvasWidthInUnits = 2 * wrapXShiftDistance;
|
||||
} else {
|
||||
canvasWidthInUnits = srcDataWidth;
|
||||
canvasWidthInUnits = ol.extent.getWidth(sourceDataExtent);
|
||||
}
|
||||
|
||||
var canvasHeightInUnits = ol.extent.getHeight(sourceDataExtent);
|
||||
var stitchContext = ol.dom.createCanvasContext2D(
|
||||
Math.round(pixelRatio * canvasWidthInUnits / sourceResolution),
|
||||
Math.round(pixelRatio * srcDataHeight / sourceResolution));
|
||||
Math.round(pixelRatio * canvasHeightInUnits / sourceResolution));
|
||||
|
||||
stitchContext.scale(pixelRatio / sourceResolution,
|
||||
pixelRatio / sourceResolution);
|
||||
stitchContext.translate(-srcDataExtent[0], srcDataExtent[3]);
|
||||
stitchContext.translate(-sourceDataExtent[0], sourceDataExtent[3]);
|
||||
|
||||
sources.forEach(function(src, i, arr) {
|
||||
var xPos = src.extent[0];
|
||||
@@ -192,9 +191,9 @@ ol.reproj.render = function(width, height, pixelRatio,
|
||||
}
|
||||
});
|
||||
|
||||
var targetTL = ol.extent.getTopLeft(targetExtent);
|
||||
var targetTopLeft = ol.extent.getTopLeft(targetExtent);
|
||||
|
||||
triangulation.getTriangles().forEach(function(tri, i, arr) {
|
||||
triangulation.getTriangles().forEach(function(triangle, i, arr) {
|
||||
context.save();
|
||||
|
||||
/* Calculate affine transform (src -> dst)
|
||||
@@ -217,16 +216,16 @@ ol.reproj.render = function(width, height, pixelRatio,
|
||||
* | 0 0 0 x1 y1 1 | |a11| |v1|
|
||||
* | 0 0 0 x2 y2 1 | |a12| |v2|
|
||||
*/
|
||||
var src = tri.source, tgt = tri.target;
|
||||
var x0 = src[0][0], y0 = src[0][1],
|
||||
x1 = src[1][0], y1 = src[1][1],
|
||||
x2 = src[2][0], y2 = src[2][1];
|
||||
var u0 = (tgt[0][0] - targetTL[0]) / targetResolution,
|
||||
v0 = -(tgt[0][1] - targetTL[1]) / targetResolution;
|
||||
var u1 = (tgt[1][0] - targetTL[0]) / targetResolution,
|
||||
v1 = -(tgt[1][1] - targetTL[1]) / targetResolution;
|
||||
var u2 = (tgt[2][0] - targetTL[0]) / targetResolution,
|
||||
v2 = -(tgt[2][1] - targetTL[1]) / targetResolution;
|
||||
var source = triangle.source, target = triangle.target;
|
||||
var x0 = source[0][0], y0 = source[0][1],
|
||||
x1 = source[1][0], y1 = source[1][1],
|
||||
x2 = source[2][0], y2 = source[2][1];
|
||||
var u0 = (target[0][0] - targetTopLeft[0]) / targetResolution,
|
||||
v0 = -(target[0][1] - targetTopLeft[1]) / targetResolution;
|
||||
var u1 = (target[1][0] - targetTopLeft[0]) / targetResolution,
|
||||
v1 = -(target[1][1] - targetTopLeft[1]) / targetResolution;
|
||||
var u2 = (target[2][0] - targetTopLeft[0]) / targetResolution,
|
||||
v2 = -(target[2][1] - targetTopLeft[1]) / targetResolution;
|
||||
|
||||
var performWrapXShift = wrapXType == ol.reproj.WrapXRendering_.STITCH_SHIFT;
|
||||
if (wrapXType == ol.reproj.WrapXRendering_.STITCH_EXTENDED) {
|
||||
@@ -246,13 +245,13 @@ ol.reproj.render = function(width, height, pixelRatio,
|
||||
// Shift all the source points to improve numerical stability
|
||||
// of all the subsequent calculations. The [x0, y0] is used here.
|
||||
// This is also used to simplify the linear system.
|
||||
var srcNumericalShiftX = x0, srcNumericalShiftY = y0;
|
||||
var sourceNumericalShiftX = x0, sourceNumericalShiftY = y0;
|
||||
x0 = 0;
|
||||
y0 = 0;
|
||||
x1 -= srcNumericalShiftX;
|
||||
y1 -= srcNumericalShiftY;
|
||||
x2 -= srcNumericalShiftX;
|
||||
y2 -= srcNumericalShiftY;
|
||||
x1 -= sourceNumericalShiftX;
|
||||
y1 -= sourceNumericalShiftY;
|
||||
x2 -= sourceNumericalShiftX;
|
||||
y2 -= sourceNumericalShiftY;
|
||||
|
||||
var augmentedMatrix = [
|
||||
[x1, y1, 0, 0, u1 - u0],
|
||||
@@ -260,8 +259,8 @@ ol.reproj.render = function(width, height, pixelRatio,
|
||||
[0, 0, x1, y1, v1 - v0],
|
||||
[0, 0, x2, y2, v2 - v0]
|
||||
];
|
||||
var coefs = ol.math.solveLinearSystem(augmentedMatrix);
|
||||
if (!coefs) {
|
||||
var affineCoefs = ol.math.solveLinearSystem(augmentedMatrix);
|
||||
if (!affineCoefs) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -283,10 +282,11 @@ ol.reproj.render = function(width, height, pixelRatio,
|
||||
context.closePath();
|
||||
context.clip();
|
||||
|
||||
context.transform(coefs[0], coefs[2], coefs[1], coefs[3], u0, v0);
|
||||
context.transform(
|
||||
affineCoefs[0], affineCoefs[2], affineCoefs[1], affineCoefs[3], u0, v0);
|
||||
|
||||
context.translate(srcDataExtent[0] - srcNumericalShiftX,
|
||||
srcDataExtent[3] - srcNumericalShiftY);
|
||||
context.translate(sourceDataExtent[0] - sourceNumericalShiftX,
|
||||
sourceDataExtent[3] - sourceNumericalShiftY);
|
||||
|
||||
context.scale(sourceResolution / pixelRatio,
|
||||
-sourceResolution / pixelRatio);
|
||||
@@ -301,14 +301,14 @@ ol.reproj.render = function(width, height, pixelRatio,
|
||||
context.strokeStyle = 'black';
|
||||
context.lineWidth = 1;
|
||||
|
||||
triangulation.getTriangles().forEach(function(tri, i, arr) {
|
||||
var tgt = tri.target;
|
||||
var u0 = (tgt[0][0] - targetTL[0]) / targetResolution,
|
||||
v0 = -(tgt[0][1] - targetTL[1]) / targetResolution;
|
||||
var u1 = (tgt[1][0] - targetTL[0]) / targetResolution,
|
||||
v1 = -(tgt[1][1] - targetTL[1]) / targetResolution;
|
||||
var u2 = (tgt[2][0] - targetTL[0]) / targetResolution,
|
||||
v2 = -(tgt[2][1] - targetTL[1]) / targetResolution;
|
||||
triangulation.getTriangles().forEach(function(triangle, i, arr) {
|
||||
var target = triangle.target;
|
||||
var u0 = (target[0][0] - targetTopLeft[0]) / targetResolution,
|
||||
v0 = -(target[0][1] - targetTopLeft[1]) / targetResolution;
|
||||
var u1 = (target[1][0] - targetTopLeft[0]) / targetResolution,
|
||||
v1 = -(target[1][1] - targetTopLeft[1]) / targetResolution;
|
||||
var u2 = (target[2][0] - targetTopLeft[0]) / targetResolution,
|
||||
v2 = -(target[2][1] - targetTopLeft[1]) / targetResolution;
|
||||
|
||||
context.beginPath();
|
||||
context.moveTo(u0, v0);
|
||||
|
||||
@@ -80,7 +80,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
|
||||
* @private
|
||||
* @type {!Array.<ol.Tile>}
|
||||
*/
|
||||
this.srcTiles_ = [];
|
||||
this.sourceTiles_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -92,7 +92,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.srcZ_ = 0;
|
||||
this.sourceZ_ = 0;
|
||||
|
||||
var targetExtent = targetTileGrid.getTileCoordExtent(this.getTileCoord());
|
||||
var maxTargetExtent = this.targetTileGrid_.getExtent();
|
||||
@@ -148,45 +148,45 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
|
||||
return;
|
||||
}
|
||||
|
||||
this.srcZ_ = sourceTileGrid.getZForResolution(sourceResolution);
|
||||
var srcExtent = this.triangulation_.calculateSourceExtent();
|
||||
this.sourceZ_ = sourceTileGrid.getZForResolution(sourceResolution);
|
||||
var sourceExtent = this.triangulation_.calculateSourceExtent();
|
||||
|
||||
if (maxSourceExtent &&
|
||||
!this.triangulation_.getWrapsXInSource() &&
|
||||
!ol.extent.intersects(maxSourceExtent, srcExtent)) {
|
||||
!ol.extent.intersects(maxSourceExtent, sourceExtent)) {
|
||||
this.state = ol.TileState.EMPTY;
|
||||
} else {
|
||||
var srcRange = sourceTileGrid.getTileRangeForExtentAndZ(
|
||||
srcExtent, this.srcZ_);
|
||||
var sourceRange = sourceTileGrid.getTileRangeForExtentAndZ(
|
||||
sourceExtent, this.sourceZ_);
|
||||
|
||||
var xRange = [];
|
||||
var srcFullRange = sourceTileGrid.getFullTileRange(this.srcZ_);
|
||||
if (srcFullRange) {
|
||||
srcRange.minY = Math.max(srcRange.minY, srcFullRange.minY);
|
||||
srcRange.maxY = Math.min(srcRange.maxY, srcFullRange.maxY);
|
||||
var sourceFullRange = sourceTileGrid.getFullTileRange(this.sourceZ_);
|
||||
if (sourceFullRange) {
|
||||
sourceRange.minY = Math.max(sourceRange.minY, sourceFullRange.minY);
|
||||
sourceRange.maxY = Math.min(sourceRange.maxY, sourceFullRange.maxY);
|
||||
|
||||
if (srcRange.minX > srcRange.maxX) {
|
||||
if (sourceRange.minX > sourceRange.maxX) {
|
||||
var i;
|
||||
for (i = srcRange.minX; i <= srcFullRange.maxX; i++) {
|
||||
for (i = sourceRange.minX; i <= sourceFullRange.maxX; i++) {
|
||||
xRange.push(i);
|
||||
}
|
||||
for (i = srcFullRange.minX; i <= srcRange.maxX; i++) {
|
||||
for (i = sourceFullRange.minX; i <= sourceRange.maxX; i++) {
|
||||
xRange.push(i);
|
||||
}
|
||||
} else {
|
||||
var first = Math.max(srcRange.minX, srcFullRange.minX);
|
||||
var last = Math.min(srcRange.maxX, srcFullRange.maxX);
|
||||
var first = Math.max(sourceRange.minX, sourceFullRange.minX);
|
||||
var last = Math.min(sourceRange.maxX, sourceFullRange.maxX);
|
||||
for (var j = first; j <= last; j++) {
|
||||
xRange.push(j);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var k = srcRange.minX; k <= srcRange.maxX; k++) {
|
||||
for (var k = sourceRange.minX; k <= sourceRange.maxX; k++) {
|
||||
xRange.push(k);
|
||||
}
|
||||
}
|
||||
|
||||
var tilesRequired = xRange.length * srcRange.getHeight();
|
||||
var tilesRequired = xRange.length * sourceRange.getHeight();
|
||||
if (!goog.asserts.assert(
|
||||
tilesRequired < ol.RASTER_REPROJECTION_MAX_SOURCE_TILES,
|
||||
'reasonable number of tiles is required')) {
|
||||
@@ -194,15 +194,15 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
|
||||
return;
|
||||
}
|
||||
xRange.forEach(function(srcX, i, arr) {
|
||||
for (var srcY = srcRange.minY; srcY <= srcRange.maxY; srcY++) {
|
||||
var tile = getTileFunction(this.srcZ_, srcX, srcY, pixelRatio);
|
||||
for (var srcY = sourceRange.minY; srcY <= sourceRange.maxY; srcY++) {
|
||||
var tile = getTileFunction(this.sourceZ_, srcX, srcY, pixelRatio);
|
||||
if (tile) {
|
||||
this.srcTiles_.push(tile);
|
||||
this.sourceTiles_.push(tile);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
if (this.srcTiles_.length === 0) {
|
||||
if (this.sourceTiles_.length === 0) {
|
||||
this.state = ol.TileState.EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ ol.reproj.Tile.prototype.getImage = function(opt_context) {
|
||||
*/
|
||||
ol.reproj.Tile.prototype.reproject_ = function() {
|
||||
var sources = [];
|
||||
this.srcTiles_.forEach(function(tile, i, arr) {
|
||||
this.sourceTiles_.forEach(function(tile, i, arr) {
|
||||
if (tile && tile.getState() == ol.TileState.LOADED) {
|
||||
sources.push({
|
||||
extent: this.sourceTileGrid_.getTileCoordExtent(tile.tileCoord),
|
||||
@@ -256,7 +256,7 @@ ol.reproj.Tile.prototype.reproject_ = function() {
|
||||
});
|
||||
}
|
||||
}, this);
|
||||
this.srcTiles_.length = 0;
|
||||
this.sourceTiles_.length = 0;
|
||||
|
||||
var tileCoord = this.getTileCoord();
|
||||
var z = tileCoord[0];
|
||||
@@ -264,7 +264,7 @@ ol.reproj.Tile.prototype.reproject_ = function() {
|
||||
var width = goog.isNumber(size) ? size : size[0];
|
||||
var height = goog.isNumber(size) ? size : size[1];
|
||||
var targetResolution = this.targetTileGrid_.getResolution(z);
|
||||
var sourceResolution = this.sourceTileGrid_.getResolution(this.srcZ_);
|
||||
var sourceResolution = this.sourceTileGrid_.getResolution(this.sourceZ_);
|
||||
|
||||
var targetExtent = this.targetTileGrid_.getTileCoordExtent(tileCoord);
|
||||
this.canvas_ = ol.reproj.render(width, height, this.pixelRatio_,
|
||||
@@ -291,7 +291,7 @@ ol.reproj.Tile.prototype.load = function() {
|
||||
'this.sourcesListenerKeys_ should be null');
|
||||
|
||||
this.sourcesListenerKeys_ = [];
|
||||
this.srcTiles_.forEach(function(tile, i, arr) {
|
||||
this.sourceTiles_.forEach(function(tile, i, arr) {
|
||||
var state = tile.getState();
|
||||
if (state == ol.TileState.IDLE || state == ol.TileState.LOADING) {
|
||||
leftToLoad++;
|
||||
@@ -317,7 +317,7 @@ ol.reproj.Tile.prototype.load = function() {
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.srcTiles_.forEach(function(tile, i, arr) {
|
||||
this.sourceTiles_.forEach(function(tile, i, arr) {
|
||||
var state = tile.getState();
|
||||
if (state == ol.TileState.IDLE) {
|
||||
tile.load();
|
||||
|
||||
@@ -114,18 +114,20 @@ ol.reproj.Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
this.targetWorldWidth_ = this.targetProj_.getExtent() ?
|
||||
ol.extent.getWidth(this.targetProj_.getExtent()) : null;
|
||||
|
||||
var tlDst = ol.extent.getTopLeft(targetExtent);
|
||||
var trDst = ol.extent.getTopRight(targetExtent);
|
||||
var brDst = ol.extent.getBottomRight(targetExtent);
|
||||
var blDst = ol.extent.getBottomLeft(targetExtent);
|
||||
var tlDstSrc = this.transformInv_(tlDst);
|
||||
var trDstSrc = this.transformInv_(trDst);
|
||||
var brDstSrc = this.transformInv_(brDst);
|
||||
var blDstSrc = this.transformInv_(blDst);
|
||||
var destinationTopLeft = ol.extent.getTopLeft(targetExtent);
|
||||
var destinationTopRight = ol.extent.getTopRight(targetExtent);
|
||||
var destinationBottomRight = ol.extent.getBottomRight(targetExtent);
|
||||
var destinationBottomLeft = ol.extent.getBottomLeft(targetExtent);
|
||||
var sourceTopLeft = this.transformInv_(destinationTopLeft);
|
||||
var sourceTopRight = this.transformInv_(destinationTopRight);
|
||||
var sourceBottomRight = this.transformInv_(destinationBottomRight);
|
||||
var sourceBottomLeft = this.transformInv_(destinationBottomLeft);
|
||||
|
||||
this.addQuad_(tlDst, trDst, brDst, blDst,
|
||||
tlDstSrc, trDstSrc, brDstSrc, blDstSrc,
|
||||
ol.RASTER_REPROJECTION_MAX_SUBDIVISION);
|
||||
this.addQuad_(
|
||||
destinationTopLeft, destinationTopRight,
|
||||
destinationBottomRight, destinationBottomLeft,
|
||||
sourceTopLeft, sourceTopRight, sourceBottomRight, sourceBottomLeft,
|
||||
ol.RASTER_REPROJECTION_MAX_SUBDIVISION);
|
||||
|
||||
transformInvCache = {};
|
||||
};
|
||||
@@ -163,39 +165,39 @@ ol.reproj.Triangulation.prototype.addTriangle_ = function(a, b, c,
|
||||
* @param {ol.Coordinate} bSrc
|
||||
* @param {ol.Coordinate} cSrc
|
||||
* @param {ol.Coordinate} dSrc
|
||||
* @param {number} maxSubdiv Maximal allowed subdivision of the quad.
|
||||
* @param {number} maxSubdivision Maximal allowed subdivision of the quad.
|
||||
* @private
|
||||
*/
|
||||
ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
aSrc, bSrc, cSrc, dSrc, maxSubdiv) {
|
||||
aSrc, bSrc, cSrc, dSrc, maxSubdivision) {
|
||||
|
||||
var srcQuadExtent = ol.extent.boundingExtent([aSrc, bSrc, cSrc, dSrc]);
|
||||
var srcCoverageX = this.sourceWorldWidth_ ?
|
||||
ol.extent.getWidth(srcQuadExtent) / this.sourceWorldWidth_ : null;
|
||||
var sourceQuadExtent = ol.extent.boundingExtent([aSrc, bSrc, cSrc, dSrc]);
|
||||
var sourceCoverageX = this.sourceWorldWidth_ ?
|
||||
ol.extent.getWidth(sourceQuadExtent) / this.sourceWorldWidth_ : null;
|
||||
|
||||
// when the quad is wrapped in the source projection
|
||||
// it covers most of the projection extent, but not fully
|
||||
var wrapsX = this.sourceProj_.canWrapX() &&
|
||||
srcCoverageX > 0.5 && srcCoverageX < 1;
|
||||
sourceCoverageX > 0.5 && sourceCoverageX < 1;
|
||||
|
||||
var needsSubdivision = false;
|
||||
|
||||
if (maxSubdiv > 0) {
|
||||
if (maxSubdivision > 0) {
|
||||
if (this.targetProj_.isGlobal() && this.targetWorldWidth_) {
|
||||
var tgtQuadExtent = ol.extent.boundingExtent([a, b, c, d]);
|
||||
var tgtCoverageX =
|
||||
ol.extent.getWidth(tgtQuadExtent) / this.targetWorldWidth_;
|
||||
var targetQuadExtent = ol.extent.boundingExtent([a, b, c, d]);
|
||||
var targetCoverageX =
|
||||
ol.extent.getWidth(targetQuadExtent) / this.targetWorldWidth_;
|
||||
needsSubdivision |=
|
||||
tgtCoverageX > ol.RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH;
|
||||
targetCoverageX > ol.RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH;
|
||||
}
|
||||
if (!wrapsX && this.sourceProj_.isGlobal() && srcCoverageX) {
|
||||
if (!wrapsX && this.sourceProj_.isGlobal() && sourceCoverageX) {
|
||||
needsSubdivision |=
|
||||
srcCoverageX > ol.RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH;
|
||||
sourceCoverageX > ol.RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
if (!needsSubdivision && this.maxSourceExtent_) {
|
||||
if (!ol.extent.intersects(srcQuadExtent, this.maxSourceExtent_)) {
|
||||
if (!ol.extent.intersects(sourceQuadExtent, this.maxSourceExtent_)) {
|
||||
// whole quad outside source projection extent -> ignore
|
||||
return;
|
||||
}
|
||||
@@ -206,7 +208,7 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
!isFinite(bSrc[0]) || !isFinite(bSrc[1]) ||
|
||||
!isFinite(cSrc[0]) || !isFinite(cSrc[1]) ||
|
||||
!isFinite(dSrc[0]) || !isFinite(dSrc[1])) {
|
||||
if (maxSubdiv > 0) {
|
||||
if (maxSubdivision > 0) {
|
||||
needsSubdivision = true;
|
||||
} else {
|
||||
return;
|
||||
@@ -214,7 +216,7 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
}
|
||||
}
|
||||
|
||||
if (maxSubdiv > 0) {
|
||||
if (maxSubdivision > 0) {
|
||||
if (!needsSubdivision) {
|
||||
var center = [(a[0] + c[0]) / 2, (a[1] + c[1]) / 2];
|
||||
var centerSrc = this.transformInv_(center);
|
||||
@@ -242,8 +244,10 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
var da = [(d[0] + a[0]) / 2, (d[1] + a[1]) / 2];
|
||||
var daSrc = this.transformInv_(da);
|
||||
|
||||
this.addQuad_(a, b, bc, da, aSrc, bSrc, bcSrc, daSrc, maxSubdiv - 1);
|
||||
this.addQuad_(da, bc, c, d, daSrc, bcSrc, cSrc, dSrc, maxSubdiv - 1);
|
||||
this.addQuad_(
|
||||
a, b, bc, da, aSrc, bSrc, bcSrc, daSrc, maxSubdivision - 1);
|
||||
this.addQuad_(
|
||||
da, bc, c, d, daSrc, bcSrc, cSrc, dSrc, maxSubdivision - 1);
|
||||
} else {
|
||||
// split vertically (left & right)
|
||||
var ab = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
|
||||
@@ -251,8 +255,10 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
var cd = [(c[0] + d[0]) / 2, (c[1] + d[1]) / 2];
|
||||
var cdSrc = this.transformInv_(cd);
|
||||
|
||||
this.addQuad_(a, ab, cd, d, aSrc, abSrc, cdSrc, dSrc, maxSubdiv - 1);
|
||||
this.addQuad_(ab, b, c, cd, abSrc, bSrc, cSrc, cdSrc, maxSubdiv - 1);
|
||||
this.addQuad_(
|
||||
a, ab, cd, d, aSrc, abSrc, cdSrc, dSrc, maxSubdivision - 1);
|
||||
this.addQuad_(
|
||||
ab, b, c, cd, abSrc, bSrc, cSrc, cdSrc, maxSubdivision - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user