Remove usage of various goog.* functions

goog.isNull, goog.isDefAndNotNull and goog.array.*
This commit is contained in:
Petr Sloup
2015-10-14 11:06:19 +02:00
parent f3d5d16a82
commit 8fb1d1f244
7 changed files with 68 additions and 68 deletions

View File

@@ -43,8 +43,8 @@ ol.reproj.Image = function(sourceProj, targetProj,
this.maxSourceExtent_ = sourceProj.getExtent();
var maxTargetExtent = targetProj.getExtent();
var limitedTargetExtent = goog.isNull(maxTargetExtent) ?
targetExtent : ol.extent.getIntersection(targetExtent, maxTargetExtent);
var limitedTargetExtent = maxTargetExtent ?
ol.extent.getIntersection(targetExtent, maxTargetExtent) : targetExtent;
var targetCenter = ol.extent.getCenter(limitedTargetExtent);
var sourceResolution = ol.reproj.calculateSourceResolution(
@@ -84,8 +84,7 @@ ol.reproj.Image = function(sourceProj, targetProj,
* @private
* @type {number}
*/
this.srcPixelRatio_ =
!goog.isNull(this.srcImage_) ? this.srcImage_.getPixelRatio() : 1;
this.srcPixelRatio_ = this.srcImage_ ? this.srcImage_.getPixelRatio() : 1;
/**
* @private
@@ -103,7 +102,7 @@ ol.reproj.Image = function(sourceProj, targetProj,
var state = ol.ImageState.LOADED;
var attributions = [];
if (!goog.isNull(this.srcImage_)) {
if (this.srcImage_) {
state = ol.ImageState.IDLE;
attributions = this.srcImage_.getAttributions();
}
@@ -195,7 +194,7 @@ ol.reproj.Image.prototype.load = function() {
* @private
*/
ol.reproj.Image.prototype.unlistenSource_ = function() {
goog.asserts.assert(!goog.isNull(this.sourceListenerKey_),
goog.asserts.assert(this.sourceListenerKey_,
'this.sourceListenerKey_ should not be null');
goog.events.unlistenByKey(this.sourceListenerKey_);
this.sourceListenerKey_ = null;

View File

@@ -1,6 +1,5 @@
goog.provide('ol.reproj');
goog.require('goog.array');
goog.require('goog.labs.userAgent.browser');
goog.require('goog.labs.userAgent.platform');
goog.require('goog.math');
@@ -117,8 +116,7 @@ ol.reproj.render = function(width, height, pixelRatio,
context.scale(pixelRatio, pixelRatio);
var wrapXShiftDistance = !goog.isNull(sourceExtent) ?
ol.extent.getWidth(sourceExtent) : 0;
var wrapXShiftDistance = sourceExtent ? ol.extent.getWidth(sourceExtent) : 0;
var wrapXType = ol.reproj.WrapXRendering_.NONE;
@@ -137,7 +135,7 @@ ol.reproj.render = function(width, height, pixelRatio,
}
var srcDataExtent = ol.extent.createEmpty();
goog.array.forEach(sources, function(src, i, arr) {
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);
@@ -147,7 +145,7 @@ ol.reproj.render = function(width, height, pixelRatio,
ol.extent.extend(srcDataExtent, src.extent);
}
});
if (!goog.isNull(sourceExtent)) {
if (sourceExtent) {
if (wrapXType == ol.reproj.WrapXRendering_.NONE) {
srcDataExtent[0] = ol.math.clamp(
srcDataExtent[0], sourceExtent[0], sourceExtent[2]);
@@ -177,7 +175,7 @@ ol.reproj.render = function(width, height, pixelRatio,
pixelRatio / sourceResolution);
stitchContext.translate(-srcDataExtent[0], srcDataExtent[3]);
goog.array.forEach(sources, function(src, i, arr) {
sources.forEach(function(src, i, arr) {
var xPos = src.extent[0];
var yPos = -src.extent[3];
var srcWidth = ol.extent.getWidth(src.extent);
@@ -196,7 +194,7 @@ ol.reproj.render = function(width, height, pixelRatio,
var targetTL = ol.extent.getTopLeft(targetExtent);
goog.array.forEach(triangulation.getTriangles(), function(tri, i, arr) {
triangulation.getTriangles().forEach(function(tri, i, arr) {
context.save();
/* Calculate affine transform (src -> dst)
@@ -263,7 +261,7 @@ ol.reproj.render = function(width, height, pixelRatio,
[0, 0, x2, y2, v2 - v0]
];
var coefs = ol.math.solveLinearSystem(augmentedMatrix);
if (goog.isNull(coefs)) {
if (!coefs) {
return;
}
@@ -303,8 +301,7 @@ ol.reproj.render = function(width, height, pixelRatio,
context.strokeStyle = 'black';
context.lineWidth = 1;
goog.array.forEach(triangulation.getTriangles(), function(tri, i, arr) {
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;

View File

@@ -1,6 +1,5 @@
goog.provide('ol.reproj.Tile');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.events');
goog.require('goog.events.EventType');
@@ -99,8 +98,8 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
var maxTargetExtent = this.targetTileGrid_.getExtent();
var maxSourceExtent = this.sourceTileGrid_.getExtent();
var limitedTargetExtent = goog.isNull(maxTargetExtent) ?
targetExtent : ol.extent.getIntersection(targetExtent, maxTargetExtent);
var limitedTargetExtent = maxTargetExtent ?
ol.extent.getIntersection(targetExtent, maxTargetExtent) : targetExtent;
if (ol.extent.getArea(limitedTargetExtent) === 0) {
// Tile is completely outside range -> EMPTY
@@ -110,8 +109,8 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
}
var sourceProjExtent = sourceProj.getExtent();
if (!goog.isNull(sourceProjExtent)) {
if (goog.isNull(maxSourceExtent)) {
if (sourceProjExtent) {
if (!maxSourceExtent) {
maxSourceExtent = sourceProjExtent;
} else {
maxSourceExtent = ol.extent.getIntersection(
@@ -152,7 +151,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
this.srcZ_ = sourceTileGrid.getZForResolution(sourceResolution);
var srcExtent = this.triangulation_.calculateSourceExtent();
if (!goog.isNull(maxSourceExtent) &&
if (maxSourceExtent &&
!this.triangulation_.getWrapsXInSource() &&
!ol.extent.intersects(maxSourceExtent, srcExtent)) {
this.state = ol.TileState.EMPTY;
@@ -160,25 +159,31 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
var srcRange = sourceTileGrid.getTileRangeForExtentAndZ(
srcExtent, this.srcZ_);
var xRange;
var xRange = [];
var srcFullRange = sourceTileGrid.getFullTileRange(this.srcZ_);
if (!goog.isNull(srcFullRange)) {
if (srcFullRange) {
srcRange.minY = Math.max(srcRange.minY, srcFullRange.minY);
srcRange.maxY = Math.min(srcRange.maxY, srcFullRange.maxY);
if (srcRange.minX > srcRange.maxX) {
xRange = goog.array.concat(
goog.array.range(srcRange.minX, srcFullRange.maxX + 1),
goog.array.range(srcFullRange.minX, srcRange.maxX + 1)
);
} else {
xRange = goog.array.range(
Math.max(srcRange.minX, srcFullRange.minX),
Math.min(srcRange.maxX, srcFullRange.maxX) + 1
);
var i;
for (i = srcRange.minX; i <= srcFullRange.maxX; i++) {
xRange.push(i);
}
for (i = srcFullRange.minX; i <= srcRange.maxX; i++) {
xRange.push(i);
}
} else {
xRange = goog.array.range(srcRange.minX, srcRange.maxX + 1);
var first = Math.max(srcRange.minX, srcFullRange.minX);
var last = Math.min(srcRange.maxX, srcFullRange.maxX);
for (var j = first; j <= last; j++) {
xRange.push(j);
}
}
} else {
for (var k = srcRange.minX; k <= srcRange.maxX; k++) {
xRange.push(k);
}
}
var tilesRequired = xRange.length * srcRange.getHeight();
@@ -187,7 +192,7 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid,
this.state = ol.TileState.ERROR;
return;
}
goog.array.forEach(xRange, function(srcX, i, arr) {
xRange.forEach(function(srcX, i, arr) {
for (var srcY = srcRange.minY; srcY <= srcRange.maxY; srcY++) {
var tile = getTileFunction(this.srcZ_, srcX, srcY, pixelRatio);
if (tile) {
@@ -242,7 +247,7 @@ ol.reproj.Tile.prototype.getImage = function(opt_context) {
*/
ol.reproj.Tile.prototype.reproject_ = function() {
var sources = [];
goog.array.forEach(this.srcTiles_, function(tile, i, arr) {
this.srcTiles_.forEach(function(tile, i, arr) {
if (tile && tile.getState() == ol.TileState.LOADED) {
sources.push({
extent: this.sourceTileGrid_.getTileCoordExtent(tile.tileCoord),
@@ -280,11 +285,11 @@ ol.reproj.Tile.prototype.load = function() {
var leftToLoad = 0;
goog.asserts.assert(goog.isNull(this.sourcesListenerKeys_),
goog.asserts.assert(!this.sourcesListenerKeys_,
'this.sourcesListenerKeys_ should be null');
this.sourcesListenerKeys_ = [];
goog.array.forEach(this.srcTiles_, function(tile, i, arr) {
this.srcTiles_.forEach(function(tile, i, arr) {
var state = tile.getState();
if (state == ol.TileState.IDLE || state == ol.TileState.LOADING) {
leftToLoad++;
@@ -310,7 +315,7 @@ ol.reproj.Tile.prototype.load = function() {
}
}, this);
goog.array.forEach(this.srcTiles_, function(tile, i, arr) {
this.srcTiles_.forEach(function(tile, i, arr) {
var state = tile.getState();
if (state == ol.TileState.IDLE) {
tile.load();
@@ -328,8 +333,8 @@ ol.reproj.Tile.prototype.load = function() {
* @private
*/
ol.reproj.Tile.prototype.unlistenSources_ = function() {
goog.asserts.assert(!goog.isNull(this.sourcesListenerKeys_),
goog.asserts.assert(this.sourcesListenerKeys_,
'this.sourcesListenerKeys_ should not be null');
goog.array.forEach(this.sourcesListenerKeys_, goog.events.unlistenByKey);
this.sourcesListenerKeys_.forEach(goog.events.unlistenByKey);
this.sourcesListenerKeys_ = null;
};

View File

@@ -1,6 +1,5 @@
goog.provide('ol.reproj.Triangulation');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.math');
goog.require('ol.extent');
@@ -96,8 +95,8 @@ ol.reproj.Triangulation = function(sourceProj, targetProj, targetExtent,
* @private
*/
this.canWrapXInSource_ = this.sourceProj_.canWrapX() &&
!goog.isNull(maxSourceExtent) &&
!goog.isNull(this.sourceProj_.getExtent()) &&
!!maxSourceExtent &&
!!this.sourceProj_.getExtent() &&
(ol.extent.getWidth(maxSourceExtent) ==
ol.extent.getWidth(this.sourceProj_.getExtent()));
@@ -105,14 +104,14 @@ ol.reproj.Triangulation = function(sourceProj, targetProj, targetExtent,
* @type {?number}
* @private
*/
this.sourceWorldWidth_ = !goog.isNull(this.sourceProj_.getExtent()) ?
this.sourceWorldWidth_ = this.sourceProj_.getExtent() ?
ol.extent.getWidth(this.sourceProj_.getExtent()) : null;
/**
* @type {?number}
* @private
*/
this.targetWorldWidth_ = !goog.isNull(this.targetProj_.getExtent()) ?
this.targetWorldWidth_ = this.targetProj_.getExtent() ?
ol.extent.getWidth(this.targetProj_.getExtent()) : null;
var tlDst = ol.extent.getTopLeft(targetExtent);
@@ -171,7 +170,7 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
aSrc, bSrc, cSrc, dSrc, maxSubdiv) {
var srcQuadExtent = ol.extent.boundingExtent([aSrc, bSrc, cSrc, dSrc]);
var srcCoverageX = !goog.isNull(this.sourceWorldWidth_) ?
var srcCoverageX = this.sourceWorldWidth_ ?
ol.extent.getWidth(srcQuadExtent) / this.sourceWorldWidth_ : null;
// when the quad is wrapped in the source projection
@@ -182,18 +181,18 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
var needsSubdivision = false;
if (maxSubdiv > 0) {
if (this.targetProj_.isGlobal() && !goog.isNull(this.targetWorldWidth_)) {
if (this.targetProj_.isGlobal() && this.targetWorldWidth_) {
var tgtQuadExtent = ol.extent.boundingExtent([a, b, c, d]);
var tgtCoverageX =
ol.extent.getWidth(tgtQuadExtent) / this.targetWorldWidth_;
needsSubdivision |= tgtCoverageX > ol.RASTER_REPROJ_MAX_TRIANGLE_WIDTH;
}
if (!wrapsX && this.sourceProj_.isGlobal() && !goog.isNull(srcCoverageX)) {
if (!wrapsX && this.sourceProj_.isGlobal() && srcCoverageX) {
needsSubdivision |= srcCoverageX > ol.RASTER_REPROJ_MAX_TRIANGLE_WIDTH;
}
}
if (!needsSubdivision && !goog.isNull(this.maxSourceExtent_)) {
if (!needsSubdivision && this.maxSourceExtent_) {
if (!ol.extent.intersects(srcQuadExtent, this.maxSourceExtent_)) {
// whole quad outside source projection extent -> ignore
return;
@@ -220,7 +219,7 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
var dx;
if (wrapsX) {
goog.asserts.assert(!goog.isNull(this.sourceWorldWidth_));
goog.asserts.assert(this.sourceWorldWidth_);
var centerSrcEstimX =
(goog.math.modulo(aSrc[0], this.sourceWorldWidth_) +
goog.math.modulo(cSrc[0], this.sourceWorldWidth_)) / 2;
@@ -278,7 +277,7 @@ ol.reproj.Triangulation.prototype.addQuad_ = function(a, b, c, d,
* @return {ol.Extent} Calculated extent.
*/
ol.reproj.Triangulation.prototype.calculateSourceExtent = function() {
if (!goog.isNull(this.trianglesSourceExtent_)) {
if (this.trianglesSourceExtent_) {
return this.trianglesSourceExtent_;
}
@@ -289,8 +288,8 @@ ol.reproj.Triangulation.prototype.calculateSourceExtent = function() {
// all coordinates need to be "shifted" to be positive
// to properly calculate the extent (and then possibly shifted back)
goog.array.forEach(this.triangles_, function(triangle, i, arr) {
goog.asserts.assert(!goog.isNull(this.sourceWorldWidth_));
this.triangles_.forEach(function(triangle, i, arr) {
goog.asserts.assert(this.sourceWorldWidth_);
var src = triangle.source;
ol.extent.extendCoordinate(extent,
[goog.math.modulo(src[0][0], this.sourceWorldWidth_), src[0][1]]);
@@ -309,7 +308,7 @@ ol.reproj.Triangulation.prototype.calculateSourceExtent = function() {
extent[2] -= this.sourceWorldWidth_;
}
} else {
goog.array.forEach(this.triangles_, function(triangle, i, arr) {
this.triangles_.forEach(function(triangle, i, arr) {
var src = triangle.source;
ol.extent.extendCoordinate(extent, src[0]);
ol.extent.extendCoordinate(extent, src[1]);

View File

@@ -110,15 +110,15 @@ ol.source.Image.prototype.getImage =
function(extent, resolution, pixelRatio, projection) {
var sourceProjection = this.getProjection();
if (!ol.ENABLE_RASTER_REPROJECTION ||
!goog.isDefAndNotNull(sourceProjection) ||
!goog.isDefAndNotNull(projection) ||
!sourceProjection ||
!projection ||
ol.proj.equivalent(sourceProjection, projection)) {
if (!goog.isNull(sourceProjection)) {
if (sourceProjection) {
projection = sourceProjection;
}
return this.getImageInternal(extent, resolution, pixelRatio, projection);
} else {
if (!goog.isNull(this.reprojectedImage_)) {
if (this.reprojectedImage_) {
if (this.reprojectedRevision_ == this.getRevision() &&
ol.proj.equivalent(
this.reprojectedImage_.getProjection(), projection) &&

View File

@@ -152,8 +152,8 @@ ol.source.TileImage.prototype.getTileGridForProjection = function(projection) {
return goog.base(this, 'getTileGridForProjection', projection);
}
var thisProj = this.getProjection();
if (!goog.isNull(this.tileGrid) &&
(goog.isNull(thisProj) || ol.proj.equivalent(thisProj, projection))) {
if (this.tileGrid &&
(!thisProj || ol.proj.equivalent(thisProj, projection))) {
return this.tileGrid;
} else {
var projKey = goog.getUid(projection).toString();
@@ -174,7 +174,7 @@ ol.source.TileImage.prototype.getTileCacheForProjection = function(projection) {
return goog.base(this, 'getTileCacheForProjection', projection);
}
var thisProj = this.getProjection();
if (goog.isNull(thisProj) || ol.proj.equivalent(thisProj, projection)) {
if (!thisProj || ol.proj.equivalent(thisProj, projection)) {
return this.tileCache;
} else {
var projKey = goog.getUid(projection).toString();
@@ -192,8 +192,8 @@ ol.source.TileImage.prototype.getTileCacheForProjection = function(projection) {
ol.source.TileImage.prototype.getTile =
function(z, x, y, pixelRatio, projection) {
if (!ol.ENABLE_RASTER_REPROJECTION ||
!goog.isDefAndNotNull(this.getProjection()) ||
!goog.isDefAndNotNull(projection) ||
!this.getProjection() ||
!projection ||
ol.proj.equivalent(this.getProjection(), projection)) {
return this.getTileInternal(z, x, y, pixelRatio, projection);
} else {
@@ -335,7 +335,7 @@ ol.source.TileImage.prototype.setTileGridForProjection =
function(projection, tilegrid) {
if (ol.ENABLE_RASTER_REPROJECTION) {
var proj = ol.proj.get(projection);
if (!goog.isNull(proj)) {
if (proj) {
var projKey = goog.getUid(proj).toString();
if (!(projKey in this.tileGridForProjection)) {
this.tileGridForProjection[projKey] = tilegrid;
@@ -380,7 +380,7 @@ ol.source.TileImage.prototype.setTileUrlFunction = function(tileUrlFunction) {
ol.source.TileImage.prototype.useTile = function(z, x, y, projection) {
var tileCache = this.getTileCacheForProjection(projection);
var tileCoordKey = this.getKeyZXY(z, x, y);
if (!goog.isNull(tileCache) && tileCache.containsKey(tileCoordKey)) {
if (tileCache && tileCache.containsKey(tileCoordKey)) {
tileCache.get(tileCoordKey);
}
};

View File

@@ -103,7 +103,7 @@ ol.source.Tile.prototype.canExpireCache = function() {
*/
ol.source.Tile.prototype.expireCache = function(projection, usedTiles) {
var tileCache = this.getTileCacheForProjection(projection);
if (!goog.isNull(tileCache)) {
if (tileCache) {
tileCache.expireCache(usedTiles);
}
};
@@ -121,7 +121,7 @@ ol.source.Tile.prototype.expireCache = function(projection, usedTiles) {
ol.source.Tile.prototype.forEachLoadedTile =
function(projection, z, tileRange, callback) {
var tileCache = this.getTileCacheForProjection(projection);
if (goog.isNull(tileCache)) {
if (!tileCache) {
return false;
}
@@ -222,7 +222,7 @@ ol.source.Tile.prototype.getTileGridForProjection = function(projection) {
*/
ol.source.Tile.prototype.getTileCacheForProjection = function(projection) {
var thisProj = this.getProjection();
if (!goog.isNull(thisProj) && !ol.proj.equivalent(thisProj, projection)) {
if (thisProj && !ol.proj.equivalent(thisProj, projection)) {
return null;
} else {
return this.tileCache;