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