Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
+28
-28
@@ -26,8 +26,8 @@ import Triangulation from '../reproj/Triangulation.js';
|
||||
* @param {ol.ReprojImageFunctionType} getImageFunction
|
||||
* Function returning source images (extent, resolution, pixelRatio).
|
||||
*/
|
||||
var ReprojImage = function(sourceProj, targetProj,
|
||||
targetExtent, targetResolution, pixelRatio, getImageFunction) {
|
||||
const ReprojImage = function(sourceProj, targetProj,
|
||||
targetExtent, targetResolution, pixelRatio, getImageFunction) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -40,24 +40,24 @@ var ReprojImage = function(sourceProj, targetProj,
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.maxSourceExtent_ = sourceProj.getExtent();
|
||||
var maxTargetExtent = targetProj.getExtent();
|
||||
const maxTargetExtent = targetProj.getExtent();
|
||||
|
||||
var limitedTargetExtent = maxTargetExtent ?
|
||||
const limitedTargetExtent = maxTargetExtent ?
|
||||
getIntersection(targetExtent, maxTargetExtent) : targetExtent;
|
||||
|
||||
var targetCenter = getCenter(limitedTargetExtent);
|
||||
var sourceResolution = _ol_reproj_.calculateSourceResolution(
|
||||
sourceProj, targetProj, targetCenter, targetResolution);
|
||||
const targetCenter = getCenter(limitedTargetExtent);
|
||||
const sourceResolution = _ol_reproj_.calculateSourceResolution(
|
||||
sourceProj, targetProj, targetCenter, targetResolution);
|
||||
|
||||
var errorThresholdInPixels = ERROR_THRESHOLD;
|
||||
const errorThresholdInPixels = ERROR_THRESHOLD;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!ol.reproj.Triangulation}
|
||||
*/
|
||||
this.triangulation_ = new Triangulation(
|
||||
sourceProj, targetProj, limitedTargetExtent, this.maxSourceExtent_,
|
||||
sourceResolution * errorThresholdInPixels);
|
||||
sourceProj, targetProj, limitedTargetExtent, this.maxSourceExtent_,
|
||||
sourceResolution * errorThresholdInPixels);
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -71,7 +71,7 @@ var ReprojImage = function(sourceProj, targetProj,
|
||||
*/
|
||||
this.targetExtent_ = targetExtent;
|
||||
|
||||
var sourceExtent = this.triangulation_.calculateSourceExtent();
|
||||
const sourceExtent = this.triangulation_.calculateSourceExtent();
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -100,7 +100,7 @@ var ReprojImage = function(sourceProj, targetProj,
|
||||
this.sourceListenerKey_ = null;
|
||||
|
||||
|
||||
var state = ImageState.LOADED;
|
||||
let state = ImageState.LOADED;
|
||||
|
||||
if (this.sourceImage_) {
|
||||
state = ImageState.IDLE;
|
||||
@@ -143,17 +143,17 @@ ReprojImage.prototype.getProjection = function() {
|
||||
* @private
|
||||
*/
|
||||
ReprojImage.prototype.reproject_ = function() {
|
||||
var sourceState = this.sourceImage_.getState();
|
||||
const sourceState = this.sourceImage_.getState();
|
||||
if (sourceState == ImageState.LOADED) {
|
||||
var width = getWidth(this.targetExtent_) / this.targetResolution_;
|
||||
var height = getHeight(this.targetExtent_) / this.targetResolution_;
|
||||
const width = getWidth(this.targetExtent_) / this.targetResolution_;
|
||||
const height = getHeight(this.targetExtent_) / this.targetResolution_;
|
||||
|
||||
this.canvas_ = _ol_reproj_.render(width, height, this.sourcePixelRatio_,
|
||||
this.sourceImage_.getResolution(), this.maxSourceExtent_,
|
||||
this.targetResolution_, this.targetExtent_, this.triangulation_, [{
|
||||
extent: this.sourceImage_.getExtent(),
|
||||
image: this.sourceImage_.getImage()
|
||||
}], 0);
|
||||
this.sourceImage_.getResolution(), this.maxSourceExtent_,
|
||||
this.targetResolution_, this.targetExtent_, this.triangulation_, [{
|
||||
extent: this.sourceImage_.getExtent(),
|
||||
image: this.sourceImage_.getImage()
|
||||
}], 0);
|
||||
}
|
||||
this.state = sourceState;
|
||||
this.changed();
|
||||
@@ -168,18 +168,18 @@ ReprojImage.prototype.load = function() {
|
||||
this.state = ImageState.LOADING;
|
||||
this.changed();
|
||||
|
||||
var sourceState = this.sourceImage_.getState();
|
||||
const sourceState = this.sourceImage_.getState();
|
||||
if (sourceState == ImageState.LOADED || sourceState == ImageState.ERROR) {
|
||||
this.reproject_();
|
||||
} else {
|
||||
this.sourceListenerKey_ = _ol_events_.listen(this.sourceImage_,
|
||||
EventType.CHANGE, function(e) {
|
||||
var sourceState = this.sourceImage_.getState();
|
||||
if (sourceState == ImageState.LOADED || sourceState == ImageState.ERROR) {
|
||||
this.unlistenSource_();
|
||||
this.reproject_();
|
||||
}
|
||||
}, this);
|
||||
EventType.CHANGE, function(e) {
|
||||
const sourceState = this.sourceImage_.getState();
|
||||
if (sourceState == ImageState.LOADED || sourceState == ImageState.ERROR) {
|
||||
this.unlistenSource_();
|
||||
this.reproject_();
|
||||
}
|
||||
}, this);
|
||||
this.sourceImage_.load();
|
||||
}
|
||||
}
|
||||
|
||||
+51
-52
@@ -32,10 +32,10 @@ import Triangulation from '../reproj/Triangulation.js';
|
||||
* @param {number=} opt_errorThreshold Acceptable reprojection error (in px).
|
||||
* @param {boolean=} opt_renderEdges Render reprojection edges.
|
||||
*/
|
||||
var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
targetProj, targetTileGrid, tileCoord, wrappedTileCoord,
|
||||
pixelRatio, gutter, getTileFunction,
|
||||
opt_errorThreshold, opt_renderEdges) {
|
||||
const ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
targetProj, targetTileGrid, tileCoord, wrappedTileCoord,
|
||||
pixelRatio, gutter, getTileFunction,
|
||||
opt_errorThreshold, opt_renderEdges) {
|
||||
Tile.call(this, tileCoord, TileState.IDLE);
|
||||
|
||||
/**
|
||||
@@ -98,11 +98,11 @@ var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
*/
|
||||
this.sourceZ_ = 0;
|
||||
|
||||
var targetExtent = targetTileGrid.getTileCoordExtent(this.wrappedTileCoord_);
|
||||
var maxTargetExtent = this.targetTileGrid_.getExtent();
|
||||
var maxSourceExtent = this.sourceTileGrid_.getExtent();
|
||||
const targetExtent = targetTileGrid.getTileCoordExtent(this.wrappedTileCoord_);
|
||||
const maxTargetExtent = this.targetTileGrid_.getExtent();
|
||||
let maxSourceExtent = this.sourceTileGrid_.getExtent();
|
||||
|
||||
var limitedTargetExtent = maxTargetExtent ?
|
||||
const limitedTargetExtent = maxTargetExtent ?
|
||||
getIntersection(targetExtent, maxTargetExtent) : targetExtent;
|
||||
|
||||
if (getArea(limitedTargetExtent) === 0) {
|
||||
@@ -112,7 +112,7 @@ var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
return;
|
||||
}
|
||||
|
||||
var sourceProjExtent = sourceProj.getExtent();
|
||||
const sourceProjExtent = sourceProj.getExtent();
|
||||
if (sourceProjExtent) {
|
||||
if (!maxSourceExtent) {
|
||||
maxSourceExtent = sourceProjExtent;
|
||||
@@ -121,12 +121,12 @@ var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
}
|
||||
}
|
||||
|
||||
var targetResolution = targetTileGrid.getResolution(
|
||||
this.wrappedTileCoord_[0]);
|
||||
const targetResolution = targetTileGrid.getResolution(
|
||||
this.wrappedTileCoord_[0]);
|
||||
|
||||
var targetCenter = getCenter(limitedTargetExtent);
|
||||
var sourceResolution = _ol_reproj_.calculateSourceResolution(
|
||||
sourceProj, targetProj, targetCenter, targetResolution);
|
||||
const targetCenter = getCenter(limitedTargetExtent);
|
||||
const sourceResolution = _ol_reproj_.calculateSourceResolution(
|
||||
sourceProj, targetProj, targetCenter, targetResolution);
|
||||
|
||||
if (!isFinite(sourceResolution) || sourceResolution <= 0) {
|
||||
// invalid sourceResolution -> EMPTY
|
||||
@@ -135,7 +135,7 @@ var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
return;
|
||||
}
|
||||
|
||||
var errorThresholdInPixels = opt_errorThreshold !== undefined ?
|
||||
const errorThresholdInPixels = opt_errorThreshold !== undefined ?
|
||||
opt_errorThreshold : ERROR_THRESHOLD;
|
||||
|
||||
/**
|
||||
@@ -143,8 +143,8 @@ var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
* @type {!ol.reproj.Triangulation}
|
||||
*/
|
||||
this.triangulation_ = new Triangulation(
|
||||
sourceProj, targetProj, limitedTargetExtent, maxSourceExtent,
|
||||
sourceResolution * errorThresholdInPixels);
|
||||
sourceProj, targetProj, limitedTargetExtent, maxSourceExtent,
|
||||
sourceResolution * errorThresholdInPixels);
|
||||
|
||||
if (this.triangulation_.getTriangles().length === 0) {
|
||||
// no valid triangles -> EMPTY
|
||||
@@ -153,14 +153,14 @@ var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
}
|
||||
|
||||
this.sourceZ_ = sourceTileGrid.getZForResolution(sourceResolution);
|
||||
var sourceExtent = this.triangulation_.calculateSourceExtent();
|
||||
let sourceExtent = this.triangulation_.calculateSourceExtent();
|
||||
|
||||
if (maxSourceExtent) {
|
||||
if (sourceProj.canWrapX()) {
|
||||
sourceExtent[1] = clamp(
|
||||
sourceExtent[1], maxSourceExtent[1], maxSourceExtent[3]);
|
||||
sourceExtent[1], maxSourceExtent[1], maxSourceExtent[3]);
|
||||
sourceExtent[3] = clamp(
|
||||
sourceExtent[3], maxSourceExtent[1], maxSourceExtent[3]);
|
||||
sourceExtent[3], maxSourceExtent[1], maxSourceExtent[3]);
|
||||
} else {
|
||||
sourceExtent = getIntersection(sourceExtent, maxSourceExtent);
|
||||
}
|
||||
@@ -169,12 +169,12 @@ var ReprojTile = function(sourceProj, sourceTileGrid,
|
||||
if (!getArea(sourceExtent)) {
|
||||
this.state = TileState.EMPTY;
|
||||
} else {
|
||||
var sourceRange = sourceTileGrid.getTileRangeForExtentAndZ(
|
||||
sourceExtent, this.sourceZ_);
|
||||
const sourceRange = sourceTileGrid.getTileRangeForExtentAndZ(
|
||||
sourceExtent, this.sourceZ_);
|
||||
|
||||
for (var srcX = sourceRange.minX; srcX <= sourceRange.maxX; srcX++) {
|
||||
for (var srcY = sourceRange.minY; srcY <= sourceRange.maxY; srcY++) {
|
||||
var tile = getTileFunction(this.sourceZ_, srcX, srcY, pixelRatio);
|
||||
for (let srcX = sourceRange.minX; srcX <= sourceRange.maxX; srcX++) {
|
||||
for (let srcY = sourceRange.minY; srcY <= sourceRange.maxY; srcY++) {
|
||||
const tile = getTileFunction(this.sourceZ_, srcX, srcY, pixelRatio);
|
||||
if (tile) {
|
||||
this.sourceTiles_.push(tile);
|
||||
}
|
||||
@@ -214,7 +214,7 @@ ReprojTile.prototype.getImage = function() {
|
||||
* @private
|
||||
*/
|
||||
ReprojTile.prototype.reproject_ = function() {
|
||||
var sources = [];
|
||||
const sources = [];
|
||||
this.sourceTiles_.forEach(function(tile, i, arr) {
|
||||
if (tile && tile.getState() == TileState.LOADED) {
|
||||
sources.push({
|
||||
@@ -228,19 +228,19 @@ ReprojTile.prototype.reproject_ = function() {
|
||||
if (sources.length === 0) {
|
||||
this.state = TileState.ERROR;
|
||||
} else {
|
||||
var z = this.wrappedTileCoord_[0];
|
||||
var size = this.targetTileGrid_.getTileSize(z);
|
||||
var width = typeof size === 'number' ? size : size[0];
|
||||
var height = typeof size === 'number' ? size : size[1];
|
||||
var targetResolution = this.targetTileGrid_.getResolution(z);
|
||||
var sourceResolution = this.sourceTileGrid_.getResolution(this.sourceZ_);
|
||||
const z = this.wrappedTileCoord_[0];
|
||||
const size = this.targetTileGrid_.getTileSize(z);
|
||||
const width = typeof size === 'number' ? size : size[0];
|
||||
const height = typeof size === 'number' ? size : size[1];
|
||||
const targetResolution = this.targetTileGrid_.getResolution(z);
|
||||
const sourceResolution = this.sourceTileGrid_.getResolution(this.sourceZ_);
|
||||
|
||||
var targetExtent = this.targetTileGrid_.getTileCoordExtent(
|
||||
this.wrappedTileCoord_);
|
||||
const targetExtent = this.targetTileGrid_.getTileCoordExtent(
|
||||
this.wrappedTileCoord_);
|
||||
this.canvas_ = _ol_reproj_.render(width, height, this.pixelRatio_,
|
||||
sourceResolution, this.sourceTileGrid_.getExtent(),
|
||||
targetResolution, targetExtent, this.triangulation_, sources,
|
||||
this.gutter_, this.renderEdges_);
|
||||
sourceResolution, this.sourceTileGrid_.getExtent(),
|
||||
targetResolution, targetExtent, this.triangulation_, sources,
|
||||
this.gutter_, this.renderEdges_);
|
||||
|
||||
this.state = TileState.LOADED;
|
||||
}
|
||||
@@ -256,35 +256,34 @@ ReprojTile.prototype.load = function() {
|
||||
this.state = TileState.LOADING;
|
||||
this.changed();
|
||||
|
||||
var leftToLoad = 0;
|
||||
let leftToLoad = 0;
|
||||
|
||||
this.sourcesListenerKeys_ = [];
|
||||
this.sourceTiles_.forEach(function(tile, i, arr) {
|
||||
var state = tile.getState();
|
||||
const state = tile.getState();
|
||||
if (state == TileState.IDLE || state == TileState.LOADING) {
|
||||
leftToLoad++;
|
||||
|
||||
var sourceListenKey;
|
||||
sourceListenKey = _ol_events_.listen(tile, EventType.CHANGE,
|
||||
function(e) {
|
||||
var state = tile.getState();
|
||||
if (state == TileState.LOADED ||
|
||||
const sourceListenKey = _ol_events_.listen(tile, EventType.CHANGE,
|
||||
function(e) {
|
||||
const state = tile.getState();
|
||||
if (state == TileState.LOADED ||
|
||||
state == TileState.ERROR ||
|
||||
state == TileState.EMPTY) {
|
||||
_ol_events_.unlistenByKey(sourceListenKey);
|
||||
leftToLoad--;
|
||||
if (leftToLoad === 0) {
|
||||
this.unlistenSources_();
|
||||
this.reproject_();
|
||||
}
|
||||
_ol_events_.unlistenByKey(sourceListenKey);
|
||||
leftToLoad--;
|
||||
if (leftToLoad === 0) {
|
||||
this.unlistenSources_();
|
||||
this.reproject_();
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
}, this);
|
||||
this.sourcesListenerKeys_.push(sourceListenKey);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
this.sourceTiles_.forEach(function(tile, i, arr) {
|
||||
var state = tile.getState();
|
||||
const state = tile.getState();
|
||||
if (state == TileState.IDLE) {
|
||||
tile.load();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {getTransform} from '../proj.js';
|
||||
* At most `2*(2^this)` triangles are created for each triangulated
|
||||
* extent (tile/image).
|
||||
*/
|
||||
var MAX_SUBDIVISION = 10;
|
||||
const MAX_SUBDIVISION = 10;
|
||||
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ var MAX_SUBDIVISION = 10;
|
||||
* subdivison is forced (up to `MAX_SUBDIVISION`).
|
||||
* Default is `0.25`.
|
||||
*/
|
||||
var MAX_TRIANGLE_WIDTH = 0.25;
|
||||
const MAX_TRIANGLE_WIDTH = 0.25;
|
||||
|
||||
|
||||
/**
|
||||
@@ -41,8 +41,8 @@ var MAX_TRIANGLE_WIDTH = 0.25;
|
||||
* @param {number} errorThreshold Acceptable error (in source units).
|
||||
* @constructor
|
||||
*/
|
||||
var Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
maxSourceExtent, errorThreshold) {
|
||||
const Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
maxSourceExtent, errorThreshold) {
|
||||
|
||||
/**
|
||||
* @type {ol.proj.Projection}
|
||||
@@ -57,8 +57,8 @@ var Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
this.targetProj_ = targetProj;
|
||||
|
||||
/** @type {!Object.<string, ol.Coordinate>} */
|
||||
var transformInvCache = {};
|
||||
var transformInv = getTransform(this.targetProj_, this.sourceProj_);
|
||||
let transformInvCache = {};
|
||||
const transformInv = getTransform(this.targetProj_, this.sourceProj_);
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} c A coordinate.
|
||||
@@ -66,7 +66,7 @@ var Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
* @private
|
||||
*/
|
||||
this.transformInv_ = function(c) {
|
||||
var key = c[0] + '/' + c[1];
|
||||
const key = c[0] + '/' + c[1];
|
||||
if (!transformInvCache[key]) {
|
||||
transformInvCache[key] = transformInv(c);
|
||||
}
|
||||
@@ -121,34 +121,34 @@ var Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
this.targetWorldWidth_ = this.targetProj_.getExtent() ?
|
||||
getWidth(this.targetProj_.getExtent()) : null;
|
||||
|
||||
var destinationTopLeft = getTopLeft(targetExtent);
|
||||
var destinationTopRight = getTopRight(targetExtent);
|
||||
var destinationBottomRight = getBottomRight(targetExtent);
|
||||
var destinationBottomLeft = getBottomLeft(targetExtent);
|
||||
var sourceTopLeft = this.transformInv_(destinationTopLeft);
|
||||
var sourceTopRight = this.transformInv_(destinationTopRight);
|
||||
var sourceBottomRight = this.transformInv_(destinationBottomRight);
|
||||
var sourceBottomLeft = this.transformInv_(destinationBottomLeft);
|
||||
const destinationTopLeft = getTopLeft(targetExtent);
|
||||
const destinationTopRight = getTopRight(targetExtent);
|
||||
const destinationBottomRight = getBottomRight(targetExtent);
|
||||
const destinationBottomLeft = getBottomLeft(targetExtent);
|
||||
const sourceTopLeft = this.transformInv_(destinationTopLeft);
|
||||
const sourceTopRight = this.transformInv_(destinationTopRight);
|
||||
const sourceBottomRight = this.transformInv_(destinationBottomRight);
|
||||
const sourceBottomLeft = this.transformInv_(destinationBottomLeft);
|
||||
|
||||
this.addQuad_(
|
||||
destinationTopLeft, destinationTopRight,
|
||||
destinationBottomRight, destinationBottomLeft,
|
||||
sourceTopLeft, sourceTopRight, sourceBottomRight, sourceBottomLeft,
|
||||
MAX_SUBDIVISION);
|
||||
destinationTopLeft, destinationTopRight,
|
||||
destinationBottomRight, destinationBottomLeft,
|
||||
sourceTopLeft, sourceTopRight, sourceBottomRight, sourceBottomLeft,
|
||||
MAX_SUBDIVISION);
|
||||
|
||||
if (this.wrapsXInSource_) {
|
||||
var leftBound = Infinity;
|
||||
let leftBound = Infinity;
|
||||
this.triangles_.forEach(function(triangle, i, arr) {
|
||||
leftBound = Math.min(leftBound,
|
||||
triangle.source[0][0], triangle.source[1][0], triangle.source[2][0]);
|
||||
triangle.source[0][0], triangle.source[1][0], triangle.source[2][0]);
|
||||
});
|
||||
|
||||
// Shift triangles to be as close to `leftBound` as possible
|
||||
// (if the distance is more than `worldWidth / 2` it can be closer.
|
||||
this.triangles_.forEach(function(triangle) {
|
||||
if (Math.max(triangle.source[0][0], triangle.source[1][0],
|
||||
triangle.source[2][0]) - leftBound > this.sourceWorldWidth_ / 2) {
|
||||
var newTriangle = [[triangle.source[0][0], triangle.source[0][1]],
|
||||
triangle.source[2][0]) - leftBound > this.sourceWorldWidth_ / 2) {
|
||||
const newTriangle = [[triangle.source[0][0], triangle.source[0][1]],
|
||||
[triangle.source[1][0], triangle.source[1][1]],
|
||||
[triangle.source[2][0], triangle.source[2][1]]];
|
||||
if ((newTriangle[0][0] - leftBound) > this.sourceWorldWidth_ / 2) {
|
||||
@@ -164,10 +164,10 @@ var Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
// Rarely (if the extent contains both the dateline and prime meridian)
|
||||
// the shift can in turn break some triangles.
|
||||
// Detect this here and don't shift in such cases.
|
||||
var minX = Math.min(
|
||||
newTriangle[0][0], newTriangle[1][0], newTriangle[2][0]);
|
||||
var maxX = Math.max(
|
||||
newTriangle[0][0], newTriangle[1][0], newTriangle[2][0]);
|
||||
const minX = Math.min(
|
||||
newTriangle[0][0], newTriangle[1][0], newTriangle[2][0]);
|
||||
const maxX = Math.max(
|
||||
newTriangle[0][0], newTriangle[1][0], newTriangle[2][0]);
|
||||
if ((maxX - minX) < this.sourceWorldWidth_ / 2) {
|
||||
triangle.source = newTriangle;
|
||||
}
|
||||
@@ -190,7 +190,7 @@ var Triangulation = function(sourceProj, targetProj, targetExtent,
|
||||
* @private
|
||||
*/
|
||||
Triangulation.prototype.addTriangle_ = function(a, b, c,
|
||||
aSrc, bSrc, cSrc) {
|
||||
aSrc, bSrc, cSrc) {
|
||||
this.triangles_.push({
|
||||
source: [aSrc, bSrc, cSrc],
|
||||
target: [a, b, c]
|
||||
@@ -215,24 +215,24 @@ Triangulation.prototype.addTriangle_ = function(a, b, c,
|
||||
* @private
|
||||
*/
|
||||
Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
aSrc, bSrc, cSrc, dSrc, maxSubdivision) {
|
||||
aSrc, bSrc, cSrc, dSrc, maxSubdivision) {
|
||||
|
||||
var sourceQuadExtent = boundingExtent([aSrc, bSrc, cSrc, dSrc]);
|
||||
var sourceCoverageX = this.sourceWorldWidth_ ?
|
||||
const sourceQuadExtent = boundingExtent([aSrc, bSrc, cSrc, dSrc]);
|
||||
const sourceCoverageX = this.sourceWorldWidth_ ?
|
||||
getWidth(sourceQuadExtent) / this.sourceWorldWidth_ : null;
|
||||
var sourceWorldWidth = /** @type {number} */ (this.sourceWorldWidth_);
|
||||
const sourceWorldWidth = /** @type {number} */ (this.sourceWorldWidth_);
|
||||
|
||||
// when the quad is wrapped in the source projection
|
||||
// it covers most of the projection extent, but not fully
|
||||
var wrapsX = this.sourceProj_.canWrapX() &&
|
||||
const wrapsX = this.sourceProj_.canWrapX() &&
|
||||
sourceCoverageX > 0.5 && sourceCoverageX < 1;
|
||||
|
||||
var needsSubdivision = false;
|
||||
let needsSubdivision = false;
|
||||
|
||||
if (maxSubdivision > 0) {
|
||||
if (this.targetProj_.isGlobal() && this.targetWorldWidth_) {
|
||||
var targetQuadExtent = boundingExtent([a, b, c, d]);
|
||||
var targetCoverageX = getWidth(targetQuadExtent) / this.targetWorldWidth_;
|
||||
const targetQuadExtent = boundingExtent([a, b, c, d]);
|
||||
const targetCoverageX = getWidth(targetQuadExtent) / this.targetWorldWidth_;
|
||||
needsSubdivision |=
|
||||
targetCoverageX > MAX_TRIANGLE_WIDTH;
|
||||
}
|
||||
@@ -264,12 +264,12 @@ Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
|
||||
if (maxSubdivision > 0) {
|
||||
if (!needsSubdivision) {
|
||||
var center = [(a[0] + c[0]) / 2, (a[1] + c[1]) / 2];
|
||||
var centerSrc = this.transformInv_(center);
|
||||
const center = [(a[0] + c[0]) / 2, (a[1] + c[1]) / 2];
|
||||
const centerSrc = this.transformInv_(center);
|
||||
|
||||
var dx;
|
||||
let dx;
|
||||
if (wrapsX) {
|
||||
var centerSrcEstimX =
|
||||
const centerSrcEstimX =
|
||||
(modulo(aSrc[0], sourceWorldWidth) +
|
||||
modulo(cSrc[0], sourceWorldWidth)) / 2;
|
||||
dx = centerSrcEstimX -
|
||||
@@ -277,33 +277,33 @@ Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
} else {
|
||||
dx = (aSrc[0] + cSrc[0]) / 2 - centerSrc[0];
|
||||
}
|
||||
var dy = (aSrc[1] + cSrc[1]) / 2 - centerSrc[1];
|
||||
var centerSrcErrorSquared = dx * dx + dy * dy;
|
||||
const dy = (aSrc[1] + cSrc[1]) / 2 - centerSrc[1];
|
||||
const centerSrcErrorSquared = dx * dx + dy * dy;
|
||||
needsSubdivision = centerSrcErrorSquared > this.errorThresholdSquared_;
|
||||
}
|
||||
if (needsSubdivision) {
|
||||
if (Math.abs(a[0] - c[0]) <= Math.abs(a[1] - c[1])) {
|
||||
// split horizontally (top & bottom)
|
||||
var bc = [(b[0] + c[0]) / 2, (b[1] + c[1]) / 2];
|
||||
var bcSrc = this.transformInv_(bc);
|
||||
var da = [(d[0] + a[0]) / 2, (d[1] + a[1]) / 2];
|
||||
var daSrc = this.transformInv_(da);
|
||||
const bc = [(b[0] + c[0]) / 2, (b[1] + c[1]) / 2];
|
||||
const bcSrc = this.transformInv_(bc);
|
||||
const da = [(d[0] + a[0]) / 2, (d[1] + a[1]) / 2];
|
||||
const daSrc = this.transformInv_(da);
|
||||
|
||||
this.addQuad_(
|
||||
a, b, bc, da, aSrc, bSrc, bcSrc, daSrc, maxSubdivision - 1);
|
||||
a, b, bc, da, aSrc, bSrc, bcSrc, daSrc, maxSubdivision - 1);
|
||||
this.addQuad_(
|
||||
da, bc, c, d, daSrc, bcSrc, cSrc, dSrc, maxSubdivision - 1);
|
||||
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];
|
||||
var abSrc = this.transformInv_(ab);
|
||||
var cd = [(c[0] + d[0]) / 2, (c[1] + d[1]) / 2];
|
||||
var cdSrc = this.transformInv_(cd);
|
||||
const ab = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
|
||||
const abSrc = this.transformInv_(ab);
|
||||
const cd = [(c[0] + d[0]) / 2, (c[1] + d[1]) / 2];
|
||||
const cdSrc = this.transformInv_(cd);
|
||||
|
||||
this.addQuad_(
|
||||
a, ab, cd, d, aSrc, abSrc, cdSrc, dSrc, maxSubdivision - 1);
|
||||
a, ab, cd, d, aSrc, abSrc, cdSrc, dSrc, maxSubdivision - 1);
|
||||
this.addQuad_(
|
||||
ab, b, c, cd, abSrc, bSrc, cSrc, cdSrc, maxSubdivision - 1);
|
||||
ab, b, c, cd, abSrc, bSrc, cSrc, cdSrc, maxSubdivision - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -327,10 +327,10 @@ Triangulation.prototype.addQuad_ = function(a, b, c, d,
|
||||
* @return {ol.Extent} Calculated extent.
|
||||
*/
|
||||
Triangulation.prototype.calculateSourceExtent = function() {
|
||||
var extent = createEmpty();
|
||||
const extent = createEmpty();
|
||||
|
||||
this.triangles_.forEach(function(triangle, i, arr) {
|
||||
var src = triangle.source;
|
||||
const src = triangle.source;
|
||||
extendCoordinate(extent, src[0]);
|
||||
extendCoordinate(extent, src[1]);
|
||||
extendCoordinate(extent, src[2]);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
* @type {number} Default maximum allowed threshold (in pixels) for
|
||||
* reprojection triangulation.
|
||||
*/
|
||||
export var ERROR_THRESHOLD = 0.5;
|
||||
export const ERROR_THRESHOLD = 0.5;
|
||||
|
||||
/**
|
||||
* TODO: decide if we want to expose this as a build flag or remove it
|
||||
* @type {boolean} Enable automatic reprojection of raster sources. Default is
|
||||
* `true`.
|
||||
*/
|
||||
export var ENABLE_RASTER_REPROJECTION = true;
|
||||
export const ENABLE_RASTER_REPROJECTION = true;
|
||||
|
||||
Reference in New Issue
Block a user