From e1f477ad8cbfdac2d9a38721f400c76091deae78 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Tue, 29 Sep 2015 15:20:51 +0200 Subject: [PATCH] Remove goog.isNull in source classes --- src/ol/source/bingmapssource.js | 2 +- src/ol/source/imagecanvassource.js | 4 +-- src/ol/source/imagemapguidesource.js | 2 +- src/ol/source/imagesource.js | 4 +-- src/ol/source/imagevectorsource.js | 4 +-- src/ol/source/imagewmssource.js | 2 +- src/ol/source/rastersource.js | 2 +- src/ol/source/tilearcgisrestsource.js | 2 +- src/ol/source/tiledebugsource.js | 2 +- src/ol/source/tileimagesource.js | 2 +- src/ol/source/tilejsonsource.js | 3 +- src/ol/source/tilesource.js | 4 +-- src/ol/source/tileutfgridsource.js | 4 +-- src/ol/source/tilevectorsource.js | 9 +++--- src/ol/source/tilewmssource.js | 4 +-- src/ol/source/vectorsource.js | 40 +++++++++++++-------------- src/ol/source/wmtssource.js | 14 ++++------ src/ol/source/zoomifysource.js | 2 +- 18 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/ol/source/bingmapssource.js b/src/ol/source/bingmapssource.js index 90a827e1b1..998d439442 100644 --- a/src/ol/source/bingmapssource.js +++ b/src/ol/source/bingmapssource.js @@ -130,7 +130,7 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse = goog.asserts.assert(ol.proj.equivalent( projection, sourceProjection), 'projections are equivalent'); - if (goog.isNull(tileCoord)) { + if (!tileCoord) { return undefined; } else { ol.tilecoord.createOrUpdate(tileCoord[0], tileCoord[1], diff --git a/src/ol/source/imagecanvassource.js b/src/ol/source/imagecanvassource.js index ba8e8a15f4..8532e8b313 100644 --- a/src/ol/source/imagecanvassource.js +++ b/src/ol/source/imagecanvassource.js @@ -64,7 +64,7 @@ ol.source.ImageCanvas.prototype.getImage = resolution = this.findNearestResolution(resolution); var canvas = this.canvas_; - if (!goog.isNull(canvas) && + if (canvas && this.renderedRevision_ == this.getRevision() && canvas.getResolution() == resolution && canvas.getPixelRatio() == pixelRatio && @@ -80,7 +80,7 @@ ol.source.ImageCanvas.prototype.getImage = var canvasElement = this.canvasFunction_( extent, resolution, pixelRatio, size, projection); - if (!goog.isNull(canvasElement)) { + if (canvasElement) { canvas = new ol.ImageCanvas(extent, resolution, pixelRatio, this.getAttributions(), canvasElement); } diff --git a/src/ol/source/imagemapguidesource.js b/src/ol/source/imagemapguidesource.js index 899d8663d0..031becffb9 100644 --- a/src/ol/source/imagemapguidesource.js +++ b/src/ol/source/imagemapguidesource.js @@ -132,7 +132,7 @@ ol.source.ImageMapGuide.prototype.getImage = pixelRatio = this.hidpi_ ? pixelRatio : 1; var image = this.image_; - if (!goog.isNull(image) && + if (image && this.renderedRevision_ == this.getRevision() && image.getResolution() == resolution && image.getPixelRatio() == pixelRatio && diff --git a/src/ol/source/imagesource.js b/src/ol/source/imagesource.js index 2865fb6511..3bd9afe517 100644 --- a/src/ol/source/imagesource.js +++ b/src/ol/source/imagesource.js @@ -50,7 +50,7 @@ ol.source.Image = function(options) { */ this.resolutions_ = options.resolutions !== undefined ? options.resolutions : null; - goog.asserts.assert(goog.isNull(this.resolutions_) || + goog.asserts.assert(!this.resolutions_ || goog.array.isSorted(this.resolutions_, function(a, b) { return b - a; @@ -75,7 +75,7 @@ ol.source.Image.prototype.getResolutions = function() { */ ol.source.Image.prototype.findNearestResolution = function(resolution) { - if (!goog.isNull(this.resolutions_)) { + if (this.resolutions_) { var idx = ol.array.linearFindNearest(this.resolutions_, resolution, 0); resolution = this.resolutions_[idx]; } diff --git a/src/ol/source/imagevectorsource.js b/src/ol/source/imagevectorsource.js index 4e8dc606f0..c940996abd 100644 --- a/src/ol/source/imagevectorsource.js +++ b/src/ol/source/imagevectorsource.js @@ -154,7 +154,7 @@ ol.source.ImageVector.prototype.canvasFunctionInternal_ = */ ol.source.ImageVector.prototype.forEachFeatureAtCoordinate = function( coordinate, resolution, rotation, skippedFeatureUids, callback) { - if (goog.isNull(this.replayGroup_)) { + if (!this.replayGroup_) { return undefined; } else { /** @type {Object.} */ @@ -292,7 +292,7 @@ ol.source.ImageVector.prototype.renderFeature_ = */ ol.source.ImageVector.prototype.setStyle = function(style) { this.style_ = style !== undefined ? style : ol.style.defaultStyleFunction; - this.styleFunction_ = goog.isNull(style) ? + this.styleFunction_ = !style ? undefined : ol.style.createStyleFunction(this.style_); this.changed(); }; diff --git a/src/ol/source/imagewmssource.js b/src/ol/source/imagewmssource.js index c7e25299d0..e9b49b95fd 100644 --- a/src/ol/source/imagewmssource.js +++ b/src/ol/source/imagewmssource.js @@ -223,7 +223,7 @@ ol.source.ImageWMS.prototype.getImage = extent[3] = centerY + imageResolution * height / 2; var image = this.image_; - if (!goog.isNull(image) && + if (image && this.renderedRevision_ == this.getRevision() && image.getResolution() == resolution && image.getPixelRatio() == pixelRatio && diff --git a/src/ol/source/rastersource.js b/src/ol/source/rastersource.js index bc37f0305c..8121573a69 100644 --- a/src/ol/source/rastersource.js +++ b/src/ol/source/rastersource.js @@ -319,7 +319,7 @@ ol.source.Raster.prototype.onWorkerComplete_ = callback(err); return; } - if (goog.isNull(output)) { + if (!output) { // job aborted return; } diff --git a/src/ol/source/tilearcgisrestsource.js b/src/ol/source/tilearcgisrestsource.js index 97b031056c..3a105fe646 100644 --- a/src/ol/source/tilearcgisrestsource.js +++ b/src/ol/source/tilearcgisrestsource.js @@ -200,7 +200,7 @@ ol.source.TileArcGISRest.prototype.tileUrlFunction_ = function(tileCoord, pixelRatio, projection) { var tileGrid = this.getTileGrid(); - if (goog.isNull(tileGrid)) { + if (!tileGrid) { tileGrid = this.getTileGridForProjection(projection); } diff --git a/src/ol/source/tiledebugsource.js b/src/ol/source/tiledebugsource.js index 41aed6df4a..3bfd917b34 100644 --- a/src/ol/source/tiledebugsource.js +++ b/src/ol/source/tiledebugsource.js @@ -110,7 +110,7 @@ ol.source.TileDebug.prototype.getTile = function(z, x, y) { var tileSize = ol.size.toSize(this.tileGrid.getTileSize(z)); var tileCoord = [z, x, y]; var textTileCoord = this.getTileCoordForTileUrlFunction(tileCoord); - var text = goog.isNull(textTileCoord) ? '' : ol.tilecoord.toString( + var text = !textTileCoord ? '' : ol.tilecoord.toString( this.getTileCoordForTileUrlFunction(textTileCoord)); var tile = new ol.DebugTile_(tileCoord, tileSize, text); this.tileCache.set(tileCoordKey, tile); diff --git a/src/ol/source/tileimagesource.js b/src/ol/source/tileimagesource.js index 1fddb16652..fa92f0671d 100644 --- a/src/ol/source/tileimagesource.js +++ b/src/ol/source/tileimagesource.js @@ -95,7 +95,7 @@ ol.source.TileImage.prototype.getTile = var tileCoord = [z, x, y]; var urlTileCoord = this.getTileCoordForTileUrlFunction( tileCoord, projection); - var tileUrl = goog.isNull(urlTileCoord) ? undefined : + var tileUrl = !urlTileCoord ? undefined : this.tileUrlFunction(urlTileCoord, pixelRatio, projection); var tile = new this.tileClass( tileCoord, diff --git a/src/ol/source/tilejsonsource.js b/src/ol/source/tilejsonsource.js index 2730c7be2b..e1c3f854fc 100644 --- a/src/ol/source/tilejsonsource.js +++ b/src/ol/source/tilejsonsource.js @@ -78,8 +78,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) { this.tileUrlFunction = ol.TileUrlFunction.createFromTemplates(tileJSON.tiles, tileGrid); - if (tileJSON.attribution !== undefined && - goog.isNull(this.getAttributions())) { + if (tileJSON.attribution !== undefined && !this.getAttributions()) { var attributionExtent = extent !== undefined ? extent : epsg4326Projection.getExtent(); /** @type {Object.>} */ diff --git a/src/ol/source/tilesource.js b/src/ol/source/tilesource.js index b9cb312290..111fb6cf18 100644 --- a/src/ol/source/tilesource.js +++ b/src/ol/source/tilesource.js @@ -195,7 +195,7 @@ ol.source.Tile.prototype.getTileGrid = function() { * @return {ol.tilegrid.TileGrid} Tile grid. */ ol.source.Tile.prototype.getTileGridForProjection = function(projection) { - if (goog.isNull(this.tileGrid)) { + if (!this.tileGrid) { return ol.tilegrid.getForProjection(projection); } else { return this.tileGrid; @@ -231,7 +231,7 @@ ol.source.Tile.prototype.getTileCoordForTileUrlFunction = var projection = opt_projection !== undefined ? opt_projection : this.getProjection(); var tileGrid = this.getTileGridForProjection(projection); - goog.asserts.assert(!goog.isNull(tileGrid), 'tile grid needed'); + goog.asserts.assert(tileGrid, 'tile grid needed'); if (this.getWrapX() && projection.isGlobal()) { tileCoord = ol.tilecoord.wrapX(tileCoord, tileGrid, projection); } diff --git a/src/ol/source/tileutfgridsource.js b/src/ol/source/tileutfgridsource.js index a25e568cc7..8862353677 100644 --- a/src/ol/source/tileutfgridsource.js +++ b/src/ol/source/tileutfgridsource.js @@ -81,7 +81,7 @@ ol.source.TileUTFGrid.prototype.getTemplate = function() { */ ol.source.TileUTFGrid.prototype.forDataAtCoordinateAndResolution = function( coordinate, resolution, callback, opt_this, opt_request) { - if (!goog.isNull(this.tileGrid)) { + if (this.tileGrid) { var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution( coordinate, resolution); var tile = /** @type {!ol.source.TileUTFGridTile_} */(this.getTile( @@ -269,7 +269,7 @@ ol.source.TileUTFGridTile_.prototype.getImage = function(opt_context) { * @return {Object} */ ol.source.TileUTFGridTile_.prototype.getData = function(coordinate) { - if (goog.isNull(this.grid_) || goog.isNull(this.keys_) || !this.data_) { + if (!this.grid_ || !this.keys_ || !this.data_) { return null; } var xRelative = (coordinate[0] - this.extent_[0]) / diff --git a/src/ol/source/tilevectorsource.js b/src/ol/source/tilevectorsource.js index d13778c07c..902dafb021 100644 --- a/src/ol/source/tilevectorsource.js +++ b/src/ol/source/tilevectorsource.js @@ -57,8 +57,7 @@ ol.source.TileVector = function(options) { this.tileLoadFunction_ = options.tileLoadFunction !== undefined ? options.tileLoadFunction : null; - goog.asserts.assert(!goog.isNull(this.format_) || - !goog.isNull(this.tileLoadFunction_), + goog.asserts.assert(this.format_ || this.tileLoadFunction_, 'Either format or tileLoadFunction are required'); /** @@ -252,7 +251,7 @@ ol.source.TileVector.prototype.getFeaturesInExtent = goog.abstractMethod; ol.source.TileVector.prototype.getTileCoordForTileUrlFunction = function(tileCoord, projection) { var tileGrid = this.tileGrid_; - goog.asserts.assert(!goog.isNull(tileGrid), 'tile grid needed'); + goog.asserts.assert(tileGrid, 'tile grid needed'); if (this.getWrapX() && projection.isGlobal()) { tileCoord = ol.tilecoord.wrapX(tileCoord, tileGrid, projection); } @@ -302,12 +301,12 @@ ol.source.TileVector.prototype.loadFeatures = tileCoord[2] = y; var urlTileCoord = this.getTileCoordForTileUrlFunction( tileCoord, projection); - var url = goog.isNull(urlTileCoord) ? undefined : + var url = !urlTileCoord ? undefined : tileUrlFunction(urlTileCoord, 1, projection); if (url !== undefined) { tiles[tileKey] = []; var tileSuccess = goog.partial(success, tileKey); - if (!goog.isNull(this.tileLoadFunction_)) { + if (this.tileLoadFunction_) { this.tileLoadFunction_(url, goog.bind(tileSuccess, this)); } else { var loader = ol.featureloader.loadFeaturesXhr(url, diff --git a/src/ol/source/tilewmssource.js b/src/ol/source/tilewmssource.js index 5f015cd07d..e3ad0ed0d3 100644 --- a/src/ol/source/tilewmssource.js +++ b/src/ol/source/tilewmssource.js @@ -135,7 +135,7 @@ ol.source.TileWMS.prototype.getGetFeatureInfoUrl = var projectionObj = ol.proj.get(projection); var tileGrid = this.getTileGrid(); - if (goog.isNull(tileGrid)) { + if (!tileGrid) { tileGrid = this.getTileGridForProjection(projectionObj); } @@ -365,7 +365,7 @@ ol.source.TileWMS.prototype.tileUrlFunction_ = function(tileCoord, pixelRatio, projection) { var tileGrid = this.getTileGrid(); - if (goog.isNull(tileGrid)) { + if (!tileGrid) { tileGrid = this.getTileGridForProjection(projection); } diff --git a/src/ol/source/vectorsource.js b/src/ol/source/vectorsource.js index c562df0eb7..d36696c86f 100644 --- a/src/ol/source/vectorsource.js +++ b/src/ol/source/vectorsource.js @@ -206,7 +206,7 @@ ol.source.Vector.prototype.addFeatureInternal = function(feature) { var geometry = feature.getGeometry(); if (geometry) { var extent = geometry.getExtent(); - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.insert(extent, feature); } } else { @@ -307,7 +307,7 @@ ol.source.Vector.prototype.addFeaturesInternal = function(features) { this.nullGeometryFeatures_[featureKey] = feature; } } - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.load(extents, geometryFeatures); } @@ -323,7 +323,7 @@ ol.source.Vector.prototype.addFeaturesInternal = function(features) { * @private */ ol.source.Vector.prototype.bindFeaturesCollection_ = function(collection) { - goog.asserts.assert(goog.isNull(this.featuresCollection_), + goog.asserts.assert(!this.featuresCollection_, 'bindFeaturesCollection can only be called once'); var modifyingCollection = false; goog.events.listen(this, ol.source.VectorEventType.ADDFEATURE, @@ -377,19 +377,19 @@ ol.source.Vector.prototype.clear = function(opt_fast) { var keys = this.featureChangeKeys_[featureId]; keys.forEach(goog.events.unlistenByKey); } - if (goog.isNull(this.featuresCollection_)) { + if (!this.featuresCollection_) { this.featureChangeKeys_ = {}; this.idIndex_ = {}; this.undefIdIndex_ = {}; } } else { var rmFeatureInternal = this.removeFeatureInternal; - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.forEach(rmFeatureInternal, this); goog.object.forEach(this.nullGeometryFeatures_, rmFeatureInternal, this); } } - if (!goog.isNull(this.featuresCollection_)) { + if (this.featuresCollection_) { this.featuresCollection_.clear(); } goog.asserts.assert(goog.object.isEmpty(this.featureChangeKeys_), @@ -399,7 +399,7 @@ ol.source.Vector.prototype.clear = function(opt_fast) { goog.asserts.assert(goog.object.isEmpty(this.undefIdIndex_), 'undefIdIndex is an empty object now'); - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.clear(); } this.loadedExtentsRtree_.clear(); @@ -424,9 +424,9 @@ ol.source.Vector.prototype.clear = function(opt_fast) { * @api stable */ ol.source.Vector.prototype.forEachFeature = function(callback, opt_this) { - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { return this.featuresRtree_.forEach(callback, opt_this); - } else if (!goog.isNull(this.featuresCollection_)) { + } else if (this.featuresCollection_) { return this.featuresCollection_.forEach(callback, opt_this); } }; @@ -483,9 +483,9 @@ ol.source.Vector.prototype.forEachFeatureAtCoordinateDirect = */ ol.source.Vector.prototype.forEachFeatureInExtent = function(extent, callback, opt_this) { - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { return this.featuresRtree_.forEachInExtent(extent, callback, opt_this); - } else if (!goog.isNull(this.featuresCollection_)) { + } else if (this.featuresCollection_) { return this.featuresCollection_.forEach(callback, opt_this); } }; @@ -563,9 +563,9 @@ ol.source.Vector.prototype.getFeaturesCollection = function() { */ ol.source.Vector.prototype.getFeatures = function() { var features; - if (!goog.isNull(this.featuresCollection_)) { + if (this.featuresCollection_) { features = this.featuresCollection_.getArray(); - } else if (!goog.isNull(this.featuresRtree_)) { + } else if (this.featuresRtree_) { features = this.featuresRtree_.getAll(); if (!goog.object.isEmpty(this.nullGeometryFeatures_)) { goog.array.extend( @@ -605,7 +605,7 @@ ol.source.Vector.prototype.getFeaturesAtCoordinate = function(coordinate) { * @api */ ol.source.Vector.prototype.getFeaturesInExtent = function(extent) { - goog.asserts.assert(!goog.isNull(this.featuresRtree_), + goog.asserts.assert(this.featuresRtree_, 'getFeaturesInExtent does not work when useSpatialIndex is set to false'); return this.featuresRtree_.getInExtent(extent); }; @@ -635,7 +635,7 @@ ol.source.Vector.prototype.getClosestFeatureToCoordinate = var closestPoint = [NaN, NaN]; var minSquaredDistance = Infinity; var extent = [-Infinity, -Infinity, Infinity, Infinity]; - goog.asserts.assert(!goog.isNull(this.featuresRtree_), + goog.asserts.assert(this.featuresRtree_, 'getClosestFeatureToCoordinate does not work with useSpatialIndex set ' + 'to false'); this.featuresRtree_.forEachInExtent(extent, @@ -675,7 +675,7 @@ ol.source.Vector.prototype.getClosestFeatureToCoordinate = * @api stable */ ol.source.Vector.prototype.getExtent = function() { - goog.asserts.assert(!goog.isNull(this.featuresRtree_), + goog.asserts.assert(this.featuresRtree_, 'getExtent does not work when useSpatialIndex is set to false'); return this.featuresRtree_.getExtent(); }; @@ -706,7 +706,7 @@ ol.source.Vector.prototype.handleFeatureChange_ = function(event) { var geometry = feature.getGeometry(); if (!geometry) { if (!(featureKey in this.nullGeometryFeatures_)) { - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.remove(feature); } this.nullGeometryFeatures_[featureKey] = feature; @@ -715,11 +715,11 @@ ol.source.Vector.prototype.handleFeatureChange_ = function(event) { var extent = geometry.getExtent(); if (featureKey in this.nullGeometryFeatures_) { delete this.nullGeometryFeatures_[featureKey]; - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.insert(extent, feature); } } else { - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.update(extent, feature); } } @@ -805,7 +805,7 @@ ol.source.Vector.prototype.removeFeature = function(feature) { if (featureKey in this.nullGeometryFeatures_) { delete this.nullGeometryFeatures_[featureKey]; } else { - if (!goog.isNull(this.featuresRtree_)) { + if (this.featuresRtree_) { this.featuresRtree_.remove(feature); } } diff --git a/src/ol/source/wmtssource.js b/src/ol/source/wmtssource.js index 4bb1dfdeb0..05583563cf 100644 --- a/src/ol/source/wmtssource.js +++ b/src/ol/source/wmtssource.js @@ -154,7 +154,7 @@ ol.source.WMTS = function(options) { * @return {string|undefined} Tile URL. */ function(tileCoord, pixelRatio, projection) { - if (goog.isNull(tileCoord)) { + if (!tileCoord) { return undefined; } else { var localContext = { @@ -341,15 +341,14 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { /* jshint -W069 */ // TODO: add support for TileMatrixLimits - goog.asserts.assert(!goog.isNull(config['layer']), + goog.asserts.assert(config['layer'], 'config "layer" must not be null'); var layers = wmtsCap['Contents']['Layer']; var l = goog.array.find(layers, function(elt, index, array) { return elt['Identifier'] == config['layer']; }); - goog.asserts.assert(!goog.isNull(l), - 'found a matching layer in Contents/Layer'); + goog.asserts.assert(l, 'found a matching layer in Contents/Layer'); goog.asserts.assert(l['TileMatrixSetLink'].length > 0, 'layer has TileMatrixSetLink'); @@ -381,8 +380,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { matrixSet = /** @type {string} */ (l['TileMatrixSetLink'][idx]['TileMatrixSet']); - goog.asserts.assert(!goog.isNull(matrixSet), - 'TileMatrixSet must not be null'); + goog.asserts.assert(matrixSet, 'TileMatrixSet must not be null'); var format = /** @type {string} */ (l['Format'][0]); if ('format' in config) { @@ -420,7 +418,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { var matrixSetObj = goog.array.find(matrixSets, function(elt, index, array) { return elt['Identifier'] == matrixSet; }); - goog.asserts.assert(!goog.isNull(matrixSetObj), + goog.asserts.assert(matrixSetObj, 'found matrixSet in Contents/TileMatrixSet'); var projection; @@ -440,7 +438,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { extent = ol.proj.transformExtent( wgs84BoundingBox, 'EPSG:4326', projection); var projectionExtent = projection.getExtent(); - if (!goog.isNull(projectionExtent)) { + if (projectionExtent) { // If possible, do a sanity check on the extent - it should never be // bigger than the validity extent of the projection of a matrix set. if (!ol.extent.containsExtent(projectionExtent, extent)) { diff --git a/src/ol/source/zoomifysource.js b/src/ol/source/zoomifysource.js index ca2166d101..f9533a74b0 100644 --- a/src/ol/source/zoomifysource.js +++ b/src/ol/source/zoomifysource.js @@ -104,7 +104,7 @@ ol.source.Zoomify = function(opt_options) { * @return {string|undefined} Tile URL. */ function tileUrlFunction(tileCoord, pixelRatio, projection) { - if (goog.isNull(tileCoord)) { + if (!tileCoord) { return undefined; } else { var tileCoordZ = tileCoord[0];