Add message to assertions.

This commit is contained in:
Marc Jansen
2015-03-30 22:50:15 +02:00
parent 2c40d74a15
commit fb9ba22c30
45 changed files with 394 additions and 221 deletions

View File

@@ -98,7 +98,8 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
}
//var copyright = response.copyright; // FIXME do we need to display this?
var resource = response.resourceSets[0].resources[0];
goog.asserts.assert(resource.imageWidth == resource.imageHeight);
goog.asserts.assert(resource.imageWidth == resource.imageHeight,
'resource has imageWidth equal to imageHeight, i.e. is square');
var maxZoom = this.maxZoom_ == -1 ? resource.zoomMax : this.maxZoom_;
var sourceProjection = this.getProjection();
@@ -129,7 +130,8 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
*/
function(tileCoord, pixelRatio, projection) {
goog.asserts.assert(ol.proj.equivalent(
projection, sourceProjection));
projection, sourceProjection),
'projections are equivalent');
if (goog.isNull(tileCoord)) {
return undefined;
} else {

View File

@@ -117,13 +117,14 @@ ol.source.Cluster.prototype.cluster_ = function() {
var feature = features[i];
if (!goog.object.containsKey(clustered, goog.getUid(feature).toString())) {
var geometry = feature.getGeometry();
goog.asserts.assert(geometry instanceof ol.geom.Point);
goog.asserts.assert(geometry instanceof ol.geom.Point,
'feature geometry is a ol.geom.Point instance');
var coordinates = geometry.getCoordinates();
ol.extent.createOrUpdateFromCoordinate(coordinates, extent);
ol.extent.buffer(extent, mapDistance, extent);
var neighbors = this.source_.getFeaturesInExtent(extent);
goog.asserts.assert(neighbors.length >= 1);
goog.asserts.assert(neighbors.length >= 1, 'at least one neighbor found');
neighbors = goog.array.filter(neighbors, function(neighbor) {
var uid = goog.getUid(neighbor).toString();
if (!goog.object.containsKey(clustered, uid)) {
@@ -137,7 +138,8 @@ ol.source.Cluster.prototype.cluster_ = function() {
}
}
goog.asserts.assert(
goog.object.getCount(clustered) == this.source_.getFeatures().length);
goog.object.getCount(clustered) == this.source_.getFeatures().length,
'number of clustered equals number of features in the source');
};
@@ -151,7 +153,8 @@ ol.source.Cluster.prototype.createCluster_ = function(features) {
var centroid = [0, 0];
for (var i = 0; i < length; i++) {
var geometry = features[i].getGeometry();
goog.asserts.assert(geometry instanceof ol.geom.Point);
goog.asserts.assert(geometry instanceof ol.geom.Point,
'feature geometry is a ol.geom.Point instance');
var coordinates = geometry.getCoordinates();
ol.coordinate.add(centroid, coordinates);
}

View File

@@ -75,7 +75,8 @@ ol.source.FormatVector.prototype.loadFeaturesFromURL =
*/
function(event) {
var xhrIo = event.target;
goog.asserts.assertInstanceof(xhrIo, goog.net.XhrIo);
goog.asserts.assertInstanceof(xhrIo, goog.net.XhrIo,
'event.target/xhrIo is an instance of goog.net.XhrIo');
if (xhrIo.isSuccess()) {
var type = this.format.getType();
/** @type {ArrayBuffer|Document|Node|Object|string|undefined} */
@@ -83,7 +84,8 @@ ol.source.FormatVector.prototype.loadFeaturesFromURL =
if (type == ol.format.FormatType.BINARY &&
ol.has.ARRAY_BUFFER) {
source = xhrIo.getResponse();
goog.asserts.assertInstanceof(source, ArrayBuffer);
goog.asserts.assertInstanceof(source, ArrayBuffer,
'source is an instance of ArrayBuffer');
} else if (type == ol.format.FormatType.JSON) {
source = xhrIo.getResponseText();
} else if (type == ol.format.FormatType.TEXT) {
@@ -96,13 +98,13 @@ ol.source.FormatVector.prototype.loadFeaturesFromURL =
source = ol.xml.parse(xhrIo.getResponseText());
}
} else {
goog.asserts.fail();
goog.asserts.fail('unexpected format type');
}
if (goog.isDefAndNotNull(source)) {
success.call(thisArg, this.readFeatures(source));
} else {
this.setState(ol.source.State.ERROR);
goog.asserts.fail();
goog.asserts.fail('undefined or null source');
}
} else {
error.call(thisArg);

View File

@@ -53,7 +53,7 @@ ol.source.Image = function(options) {
goog.array.isSorted(this.resolutions_,
function(a, b) {
return b - a;
}, true));
}, true), 'resolutions must be null or sorted in descending order');
};
goog.inherits(ol.source.Image, ol.source.Source);

View File

@@ -166,7 +166,7 @@ ol.source.ImageVector.prototype.forEachFeatureAtCoordinate = function(
* @return {?} Callback result.
*/
function(feature) {
goog.asserts.assert(goog.isDef(feature));
goog.asserts.assert(goog.isDef(feature), 'passed a feature');
var key = goog.getUid(feature).toString();
if (!(key in features)) {
features[key] = true;

View File

@@ -139,7 +139,8 @@ ol.source.ImageWMS.GETFEATUREINFO_IMAGE_SIZE_ = [101, 101];
ol.source.ImageWMS.prototype.getGetFeatureInfoUrl =
function(coordinate, resolution, projection, params) {
goog.asserts.assert(!('VERSION' in params));
goog.asserts.assert(!('VERSION' in params),
'key VERSION is not allowed in params');
if (!goog.isDef(this.url_)) {
return undefined;
@@ -279,7 +280,7 @@ ol.source.ImageWMS.prototype.getImageLoadFunction = function() {
ol.source.ImageWMS.prototype.getRequestUrl_ =
function(extent, size, pixelRatio, projection, params) {
goog.asserts.assert(goog.isDef(this.url_));
goog.asserts.assert(goog.isDef(this.url_), 'url is defined');
params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
@@ -303,7 +304,7 @@ ol.source.ImageWMS.prototype.getRequestUrl_ =
params['DPI'] = 90 * pixelRatio;
break;
default:
goog.asserts.fail();
goog.asserts.fail('unknown serverType configured');
break;
}
}

View File

@@ -20,7 +20,8 @@ goog.require('ol.source.XYZ');
ol.source.MapQuest = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
goog.asserts.assert(options.layer in ol.source.MapQuestConfig);
goog.asserts.assert(options.layer in ol.source.MapQuestConfig,
'known layer configured');
var layerConfig = ol.source.MapQuestConfig[options.layer];

View File

@@ -91,10 +91,12 @@ ol.source.Stamen = function(options) {
var i = options.layer.indexOf('-');
var provider = i == -1 ? options.layer : options.layer.slice(0, i);
goog.asserts.assert(provider in ol.source.StamenProviderConfig);
goog.asserts.assert(provider in ol.source.StamenProviderConfig,
'known provider configured');
var providerConfig = ol.source.StamenProviderConfig[provider];
goog.asserts.assert(options.layer in ol.source.StamenLayerConfig);
goog.asserts.assert(options.layer in ol.source.StamenLayerConfig,
'known layer configured');
var layerConfig = ol.source.StamenLayerConfig[options.layer];
var root = ol.IS_HTTPS ? 'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' :

View File

@@ -90,7 +90,7 @@ ol.source.TileImage.prototype.getTile =
if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
} else {
goog.asserts.assert(projection);
goog.asserts.assert(projection, 'argument projection is truthy');
var tileCoord = [z, x, y];
var urlTileCoord = this.getWrapXTileCoord(tileCoord, projection);
var tileUrl = goog.isNull(urlTileCoord) ? undefined :

View File

@@ -65,7 +65,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
}
if (goog.isDef(tileJSON.scheme)) {
goog.asserts.assert(tileJSON.scheme == 'xyz');
goog.asserts.assert(tileJSON.scheme == 'xyz', 'tileJSON-scheme is "xyz"');
}
var minZoom = tileJSON.minzoom || 0;
var maxZoom = tileJSON.maxzoom || 22;

View File

@@ -117,7 +117,7 @@ ol.source.TileUTFGrid.prototype.handleTileJSONResponse = function(tileJSON) {
}
if (goog.isDef(tileJSON.scheme)) {
goog.asserts.assert(tileJSON.scheme == 'xyz');
goog.asserts.assert(tileJSON.scheme == 'xyz', 'tileJSON-scheme is "xyz"');
}
var minZoom = tileJSON.minzoom || 0;
var maxZoom = tileJSON.maxzoom || 22;
@@ -175,7 +175,7 @@ ol.source.TileUTFGrid.prototype.getTile =
if (this.tileCache.containsKey(tileCoordKey)) {
return /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
} else {
goog.asserts.assert(projection);
goog.asserts.assert(projection, 'argument projection is truthy');
var tileCoord = [z, x, y];
var tileUrl = this.tileUrlFunction_(tileCoord, pixelRatio, projection);
var tile = new ol.source.TileUTFGridTile_(

View File

@@ -121,7 +121,8 @@ ol.source.TileVector.prototype.forEachFeatureAtCoordinateAndResolution =
for (i = 0, ii = features.length; i < ii; ++i) {
var feature = features[i];
var geometry = feature.getGeometry();
goog.asserts.assert(goog.isDefAndNotNull(geometry));
goog.asserts.assert(goog.isDefAndNotNull(geometry),
'feature geometry is defined and not null');
if (geometry.containsCoordinate(coordinate)) {
var result = callback.call(opt_this, feature);
if (result) {

View File

@@ -129,7 +129,8 @@ goog.inherits(ol.source.TileWMS, ol.source.TileImage);
ol.source.TileWMS.prototype.getGetFeatureInfoUrl =
function(coordinate, resolution, projection, params) {
goog.asserts.assert(!('VERSION' in params));
goog.asserts.assert(!('VERSION' in params),
'key VERSION is not allowed in params');
var projectionObj = ol.proj.get(projection);
@@ -248,7 +249,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ =
params['DPI'] = 90 * pixelRatio;
break;
default:
goog.asserts.fail();
goog.asserts.fail('unknown serverType configured');
break;
}
}

View File

@@ -158,7 +158,8 @@ ol.source.Vector.prototype.addFeatureInternal = function(feature) {
* @private
*/
ol.source.Vector.prototype.setupChangeEvents_ = function(featureKey, feature) {
goog.asserts.assert(!(featureKey in this.featureChangeKeys_));
goog.asserts.assert(!(featureKey in this.featureChangeKeys_),
'key (%s) not yet registered in featurChangeKey', featureKey);
this.featureChangeKeys_[featureKey] = [
goog.events.listen(feature,
goog.events.EventType.CHANGE,
@@ -251,9 +252,12 @@ ol.source.Vector.prototype.clear = function(opt_fast) {
var rmFeatureInternal = this.removeFeatureInternal;
this.rBush_.forEach(rmFeatureInternal, this);
goog.object.forEach(this.nullGeometryFeatures_, rmFeatureInternal, this);
goog.asserts.assert(goog.object.isEmpty(this.featureChangeKeys_));
goog.asserts.assert(goog.object.isEmpty(this.idIndex_));
goog.asserts.assert(goog.object.isEmpty(this.undefIdIndex_));
goog.asserts.assert(goog.object.isEmpty(this.featureChangeKeys_),
'featureChangeKeys is an empty object now');
goog.asserts.assert(goog.object.isEmpty(this.idIndex_),
'idIndex is an empty object now');
goog.asserts.assert(goog.object.isEmpty(this.undefIdIndex_),
'undefIdIndex is an empty object now');
}
this.rBush_.clear();
@@ -300,7 +304,8 @@ ol.source.Vector.prototype.forEachFeatureAtCoordinateDirect =
var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
return this.forEachFeatureInExtent(extent, function(feature) {
var geometry = feature.getGeometry();
goog.asserts.assert(goog.isDefAndNotNull(geometry));
goog.asserts.assert(goog.isDefAndNotNull(geometry),
'feature geometry is defined and not null');
if (geometry.containsCoordinate(coordinate)) {
return callback.call(opt_this, feature);
} else {
@@ -375,7 +380,8 @@ ol.source.Vector.prototype.forEachFeatureIntersectingExtent =
*/
function(feature) {
var geometry = feature.getGeometry();
goog.asserts.assert(goog.isDefAndNotNull(geometry));
goog.asserts.assert(goog.isDefAndNotNull(geometry),
'feature geometry is defined and not null');
if (geometry.intersectsExtent(extent)) {
var result = callback.call(opt_this, feature);
if (result) {
@@ -452,7 +458,8 @@ ol.source.Vector.prototype.getClosestFeatureToCoordinate =
*/
function(feature) {
var geometry = feature.getGeometry();
goog.asserts.assert(goog.isDefAndNotNull(geometry));
goog.asserts.assert(goog.isDefAndNotNull(geometry),
'feature geometry is defined and not null');
var previousMinSquaredDistance = minSquaredDistance;
minSquaredDistance = geometry.closestPointXY(
x, y, closestPoint, minSquaredDistance);
@@ -542,7 +549,8 @@ ol.source.Vector.prototype.handleFeatureChange_ = function(event) {
'Expected feature to be removed from index');
this.undefIdIndex_[featureKey] = feature;
} else {
goog.asserts.assert(this.undefIdIndex_[featureKey] === feature);
goog.asserts.assert(this.undefIdIndex_[featureKey] === feature,
'feature keyed under %s in undefIdKeys', featureKey);
}
}
this.changed();
@@ -594,7 +602,8 @@ ol.source.Vector.prototype.removeFeature = function(feature) {
*/
ol.source.Vector.prototype.removeFeatureInternal = function(feature) {
var featureKey = goog.getUid(feature).toString();
goog.asserts.assert(featureKey in this.featureChangeKeys_);
goog.asserts.assert(featureKey in this.featureChangeKeys_,
'featureKey exists in featureChangeKeys');
goog.array.forEach(this.featureChangeKeys_[featureKey],
goog.events.unlistenByKey);
delete this.featureChangeKeys_[featureKey];

View File

@@ -177,7 +177,8 @@ ol.source.WMTS = function(options) {
* @return {ol.TileCoord} Tile coordinate.
*/
function(tileCoord, projection, opt_tileCoord) {
goog.asserts.assert(!goog.isNull(tileGrid));
goog.asserts.assert(!goog.isNull(tileGrid),
'tileGrid must not be null');
if (tileGrid.getResolutions().length <= tileCoord[0]) {
return null;
}
@@ -328,15 +329,18 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
/* jshint -W069 */
// TODO: add support for TileMatrixLimits
goog.asserts.assert(!goog.isNull(config['layer']));
goog.asserts.assert(!goog.isNull(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));
goog.asserts.assert(!goog.isNull(l),
'found a matching layer in Contents/Layer');
goog.asserts.assert(l['TileMatrixSetLink'].length > 0);
goog.asserts.assert(l['TileMatrixSetLink'].length > 0,
'layer has TileMatrixSetLink');
var idx, matrixSet, wrapX;
if (l['TileMatrixSetLink'].length > 1) {
idx = goog.array.findIndex(l['TileMatrixSetLink'],
@@ -359,7 +363,8 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
matrixSet = /** @type {string} */
(l['TileMatrixSetLink'][idx]['TileMatrixSet']);
goog.asserts.assert(!goog.isNull(matrixSet));
goog.asserts.assert(!goog.isNull(matrixSet),
'TileMatrixSet must not be null');
var wgs84BoundingBox = l['WGS84BoundingBox'];
if (goog.isDef(wgs84BoundingBox)) {
@@ -390,11 +395,12 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
var key = elt['Identifier'];
var value = elt['default'];
if (goog.isDef(value)) {
goog.asserts.assert(goog.array.contains(elt['values'], value));
goog.asserts.assert(goog.array.contains(elt['values'], value),
'default value contained in values');
} else {
value = elt['values'][0];
}
goog.asserts.assert(goog.isDef(value));
goog.asserts.assert(goog.isDef(value), 'value could be found');
dimensions[key] = value;
});
}
@@ -403,7 +409,8 @@ 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(!goog.isNull(matrixSetObj),
'found matrixSet in Contents/TileMatrixSet');
var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
matrixSetObj);
@@ -422,7 +429,9 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
requestEncoding = goog.isDef(requestEncoding) ? requestEncoding : '';
goog.asserts.assert(
goog.array.contains(['REST', 'RESTful', 'KVP', ''], requestEncoding));
goog.array.contains(['REST', 'RESTful', 'KVP', ''], requestEncoding),
'requestEncoding (%s) is one of "REST", "RESTful", "KVP" or ""',
requestEncoding);
if (!wmtsCap['OperationsMetadata'].hasOwnProperty('GetTile') ||
goog.string.startsWith(requestEncoding, 'REST')) {
@@ -448,7 +457,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
}
}
goog.asserts.assert(urls.length > 0);
goog.asserts.assert(urls.length > 0, 'At least one URL found');
return {
urls: urls,