diff --git a/src/ol/assertionerror.js b/src/ol/assertionerror.js
new file mode 100644
index 0000000000..cc3c723885
--- /dev/null
+++ b/src/ol/assertionerror.js
@@ -0,0 +1,36 @@
+goog.provide('ol.AssertionError');
+
+goog.require('ol');
+
+/**
+ * Error object thrown when an assertion failed. This is an ECMA-262 Error,
+ * extended with a `code` property.
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
+ * @constructor
+ * @extends {Error}
+ * @implements {oli.AssertionError}
+ * @param {number} code Error code.
+ */
+ol.AssertionError = function(code) {
+
+ /**
+ * @type {string}
+ */
+ this.message = 'Assertion failed. See ' +
+ (ol.VERSION ? 'http://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') +
+ '/doc/errors/#' + code + ' for details.';
+
+ /**
+ * Error code. The meaning of the code can be found on
+ * {@link http://openlayers.org/en/latest/errors.html} (replace `latest` with
+ * the version found in the OpenLayers script's header comment if a version
+ * other than the latest is used).
+ * @type {number}
+ * @api
+ */
+ this.code = code;
+
+ this.name = 'AssertionError';
+
+};
+ol.inherits(ol.AssertionError, Error);
diff --git a/src/ol/asserts.js b/src/ol/asserts.js
new file mode 100644
index 0000000000..d9cf9c2339
--- /dev/null
+++ b/src/ol/asserts.js
@@ -0,0 +1,15 @@
+goog.provide('ol.asserts');
+
+goog.require('ol');
+goog.require('ol.AssertionError');
+
+
+/**
+ * @param {*} assertion Assertion we expected to be truthy.
+ * @param {number} errorCode Error code.
+ */
+ol.asserts.assert = function(assertion, errorCode) {
+ if (!assertion) {
+ throw new ol.AssertionError(errorCode);
+ }
+};
diff --git a/src/ol/color.js b/src/ol/color.js
index 178bca7521..69a39c4bef 100644
--- a/src/ol/color.js
+++ b/src/ol/color.js
@@ -159,7 +159,7 @@ ol.color.fromStringInternal_ = function(s) {
if (ol.color.hexColorRe_.exec(s)) { // hex
var n = s.length - 1; // number of hex digits
- ol.assert(n == 3 || n == 6, 54); // Hex color should have 3 or 6 digits
+ ol.asserts.assert(n == 3 || n == 6, 54); // Hex color should have 3 or 6 digits
var d = n == 3 ? 1 : 2; // number of digits per channel
r = parseInt(s.substr(1 + 0 * d, d), 16);
g = parseInt(s.substr(1 + 1 * d, d), 16);
@@ -183,7 +183,7 @@ ol.color.fromStringInternal_ = function(s) {
b = Number(match[3]);
color = ol.color.normalize([r, g, b, 1]);
} else {
- ol.assert(false, 14); // Invalid color
+ ol.asserts.assert(false, 14); // Invalid color
}
return /** @type {ol.Color} */ (color);
};
diff --git a/src/ol/control/scaleline.js b/src/ol/control/scaleline.js
index 2b28824552..674eb7aadd 100644
--- a/src/ol/control/scaleline.js
+++ b/src/ol/control/scaleline.js
@@ -245,7 +245,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
pointResolution /= 1609.3472;
}
} else {
- ol.assert(false, 33); // Invalid units
+ ol.asserts.assert(false, 33); // Invalid units
}
var i = 3 * Math.floor(
diff --git a/src/ol/extent.js b/src/ol/extent.js
index f9da4b4605..f7430cef6d 100644
--- a/src/ol/extent.js
+++ b/src/ol/extent.js
@@ -526,7 +526,7 @@ ol.extent.getCorner = function(extent, corner) {
} else if (corner === ol.extent.Corner.TOP_RIGHT) {
coordinate = ol.extent.getTopRight(extent);
} else {
- ol.assert(false, 13); // Invalid corner
+ ol.asserts.assert(false, 13); // Invalid corner
}
return /** @type {!ol.Coordinate} */ (coordinate);
};
diff --git a/src/ol/feature.js b/src/ol/feature.js
index a9f351c2bb..0bb9b6b2c5 100644
--- a/src/ol/feature.js
+++ b/src/ol/feature.js
@@ -301,7 +301,7 @@ ol.Feature.createStyleFunction = function(obj) {
if (Array.isArray(obj)) {
styles = obj;
} else {
- ol.assert(obj instanceof ol.style.Style,
+ ol.asserts.assert(obj instanceof ol.style.Style,
41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
styles = [obj];
}
diff --git a/src/ol/format/esrijson.js b/src/ol/format/esrijson.js
index b183f80b12..97691101c8 100644
--- a/src/ol/format/esrijson.js
+++ b/src/ol/format/esrijson.js
@@ -282,7 +282,7 @@ ol.format.EsriJSON.writePointGeometry_ = function(geometry, opt_options) {
y: coordinates[1]
});
} else {
- ol.assert(false, 34); // Invalid geometry layout
+ ol.asserts.assert(false, 34); // Invalid geometry layout
}
return /** @type {EsriJSONGeometry} */ (esriJSON);
};
diff --git a/src/ol/format/geojson.js b/src/ol/format/geojson.js
index c0342f1495..b5f82272fc 100644
--- a/src/ol/format/geojson.js
+++ b/src/ol/format/geojson.js
@@ -422,7 +422,7 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
opt_options));
}
} else {
- ol.assert(false, 35); // Unknown GeoJSON object type
+ ol.asserts.assert(false, 35); // Unknown GeoJSON object type
}
return /** Array.
*/ (features);
};
@@ -478,7 +478,7 @@ ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) {
// is fixed and widely deployed.
projection = ol.proj.get('EPSG:' + crs.properties.code);
} else {
- ol.assert(false, 36); // Unknown SRS type
+ ol.asserts.assert(false, 36); // Unknown SRS type
}
} else {
projection = this.defaultDataProjection;
diff --git a/src/ol/format/kml.js b/src/ol/format/kml.js
index 1f119b8665..83c0c3b3b1 100644
--- a/src/ol/format/kml.js
+++ b/src/ol/format/kml.js
@@ -981,7 +981,7 @@ ol.format.KML.readMultiGeometry_ = function(node, objectStack) {
} else if (type == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
multiGeometry = new ol.geom.GeometryCollection(geometries);
} else {
- ol.assert(false, 37); // Unknown geometry type found
+ ol.asserts.assert(false, 37); // Unknown geometry type found
}
} else {
multiGeometry = new ol.geom.GeometryCollection(geometries);
@@ -1217,7 +1217,7 @@ ol.format.KML.PlacemarkStyleMapParser_ = function(node, objectStack) {
} else if (typeof styleMapValue === 'string') {
placemarkObject['styleUrl'] = styleMapValue;
} else {
- ol.assert(false, 38); // `styleMapValue` has an unknown type
+ ol.asserts.assert(false, 38); // `styleMapValue` has an unknown type
}
};
@@ -2067,7 +2067,7 @@ ol.format.KML.writeCoordinatesTextNode_ = function(node, coordinates, objectStac
layout == ol.geom.GeometryLayout.XYZM) {
dimension = 3;
} else {
- ol.assert(false, 34); // Invalid geometry layout
+ ol.asserts.assert(false, 34); // Invalid geometry layout
}
var d, i;
@@ -2259,7 +2259,7 @@ ol.format.KML.writeMultiGeometry_ = function(node, geometry, objectStack) {
(/** @type {ol.geom.MultiPolygon} */ (geometry)).getPolygons();
factory = ol.format.KML.POLYGON_NODE_FACTORY_;
} else {
- ol.assert(false, 39); // Unknown geometry type
+ ol.asserts.assert(false, 39); // Unknown geometry type
}
ol.xml.pushSerializeAndPop(context,
ol.format.KML.MULTI_GEOMETRY_SERIALIZERS_, factory,
diff --git a/src/ol/format/polyline.js b/src/ol/format/polyline.js
index b00d2b2216..a7b3a8ad40 100644
--- a/src/ol/format/polyline.js
+++ b/src/ol/format/polyline.js
@@ -355,7 +355,7 @@ ol.format.Polyline.prototype.writeFeatureText = function(feature, opt_options) {
if (geometry) {
return this.writeGeometryText(geometry, opt_options);
} else {
- ol.assert(false, 40); // Expected `feature` to have a geometry
+ ol.asserts.assert(false, 40); // Expected `feature` to have a geometry
return '';
}
};
diff --git a/src/ol/format/wfs.js b/src/ol/format/wfs.js
index b76bbbf747..185e5c97e2 100644
--- a/src/ol/format/wfs.js
+++ b/src/ol/format/wfs.js
@@ -386,7 +386,7 @@ ol.format.WFS.writeOgcFidFilter_ = function(node, fid, objectStack) {
*/
ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
var context = objectStack[objectStack.length - 1];
- ol.assert(feature.getId() !== undefined, 26); // Features must have an id set
+ ol.asserts.assert(feature.getId() !== undefined, 26); // Features must have an id set
var featureType = context['featureType'];
var featurePrefix = context['featurePrefix'];
featurePrefix = featurePrefix ? featurePrefix :
@@ -410,7 +410,7 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
*/
ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
var context = objectStack[objectStack.length - 1];
- ol.assert(feature.getId() !== undefined, 27); // Features must have an id set
+ ol.asserts.assert(feature.getId() !== undefined, 27); // Features must have an id set
var featureType = context['featureType'];
var featurePrefix = context['featurePrefix'];
featurePrefix = featurePrefix ? featurePrefix :
@@ -802,7 +802,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) {
}
filter = options.filter;
if (options.bbox) {
- ol.assert(options.geometryName,
+ ol.asserts.assert(options.geometryName,
12); // `options.geometryName` must also be provided when `options.bbox` is set
var bbox = ol.format.ogc.filter.bbox(
/** @type {string} */ (options.geometryName), options.bbox, options.srsName);
@@ -826,7 +826,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) {
'filter': filter,
'propertyNames': options.propertyNames ? options.propertyNames : []
};
- ol.assert(Array.isArray(options.featureTypes),
+ ol.asserts.assert(Array.isArray(options.featureTypes),
11); // `options.featureTypes` should be an Array
ol.format.WFS.writeGetFeature_(node, /** @type {!Array.} */ (options.featureTypes), [context]);
return node;
diff --git a/src/ol/index.js b/src/ol/index.js
index e195cff740..9004ffdbf0 100644
--- a/src/ol/index.js
+++ b/src/ol/index.js
@@ -303,48 +303,3 @@ if (typeof window !== 'undefined') {
} else if (typeof self !== 'undefined') {
ol.global = self;
}
-
-
-/**
- * Error object thrown when an assertion failed. This is an ECMA-262 Error,
- * extended with a `code` property.
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
- * @constructor
- * @extends {Error}
- * @implements {oli.AssertionError}
- * @param {number} code Error code.
- */
-ol.AssertionError = function(code) {
-
- /**
- * @type {string}
- */
- this.message = 'Assertion failed. See ' +
- (ol.VERSION ? 'http://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') +
- '/doc/errors/#' + code + ' for details.';
-
- /**
- * Error code. The meaning of the code can be found on
- * {@link http://openlayers.org/en/latest/errors.html} (replace `latest` with
- * the version found in the OpenLayers script's header comment if a version
- * other than the latest is used).
- * @type {number}
- * @api
- */
- this.code = code;
-
- this.name = 'AssertionError';
-
-};
-ol.inherits(ol.AssertionError, Error);
-
-
-/**
- * @param {*} assertion Assertion we expected to be truthy.
- * @param {number} errorCode Error code.
- */
-ol.assert = function(assertion, errorCode) {
- if (!assertion) {
- throw new ol.AssertionError(errorCode);
- }
-};
diff --git a/src/ol/interaction/select.js b/src/ol/interaction/select.js
index ef634e00b0..eadcfe787c 100644
--- a/src/ol/interaction/select.js
+++ b/src/ol/interaction/select.js
@@ -225,7 +225,7 @@ ol.interaction.Select.prototype.getFeatures = function() {
* @api
*/
ol.interaction.Select.prototype.getLayer = function(feature) {
- ol.assert(feature instanceof ol.Feature,
+ ol.asserts.assert(feature instanceof ol.Feature,
42); // Expected an `ol.Feature`, but got an `ol.RenderFeature`
var key = ol.getUid(feature);
return /** @type {ol.layer.Vector} */ (this.featureLayerAssociation_[key]);
diff --git a/src/ol/layer/group.js b/src/ol/layer/group.js
index f982001055..4406463e71 100644
--- a/src/ol/layer/group.js
+++ b/src/ol/layer/group.js
@@ -61,7 +61,7 @@ ol.layer.Group = function(opt_options) {
if (Array.isArray(layers)) {
layers = new ol.Collection(layers.slice());
} else {
- ol.assert(layers instanceof ol.Collection,
+ ol.asserts.assert(layers instanceof ol.Collection,
43); // Expected `layers` to be an array or an `ol.Collection`
layers = layers;
}
diff --git a/src/ol/layer/vectortile.js b/src/ol/layer/vectortile.js
index fd84333365..6a3410cb0e 100644
--- a/src/ol/layer/vectortile.js
+++ b/src/ol/layer/vectortile.js
@@ -58,7 +58,7 @@ ol.layer.VectorTile = function(opt_options) {
this.setUseInterimTilesOnError(options.useInterimTilesOnError ?
options.useInterimTilesOnError : true);
- ol.assert(options.renderMode == undefined ||
+ ol.asserts.assert(options.renderMode == undefined ||
options.renderMode == ol.layer.VectorTileRenderType.IMAGE ||
options.renderMode == ol.layer.VectorTileRenderType.HYBRID ||
options.renderMode == ol.layer.VectorTileRenderType.VECTOR,
diff --git a/src/ol/map.js b/src/ol/map.js
index 37d19f6fbc..441c632ff7 100644
--- a/src/ol/map.js
+++ b/src/ol/map.js
@@ -1443,8 +1443,8 @@ ol.Map.createOptionsInternal = function(options) {
} else if (logo instanceof HTMLElement) {
logos[ol.getUid(logo).toString()] = logo;
} else if (logo) {
- ol.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
- ol.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
+ ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
+ ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
logos[logo.src] = logo.href;
}
}
@@ -1473,7 +1473,7 @@ ol.Map.createOptionsInternal = function(options) {
} else if (typeof options.renderer === 'string') {
rendererTypes = [options.renderer];
} else {
- ol.assert(false, 46); // Incorrect format for `renderer` option
+ ol.asserts.assert(false, 46); // Incorrect format for `renderer` option
}
} else {
rendererTypes = ol.DEFAULT_RENDERER_TYPES;
@@ -1506,7 +1506,7 @@ ol.Map.createOptionsInternal = function(options) {
if (Array.isArray(options.controls)) {
controls = new ol.Collection(options.controls.slice());
} else {
- ol.assert(options.controls instanceof ol.Collection,
+ ol.asserts.assert(options.controls instanceof ol.Collection,
47); // Expected `controls` to be an array or an `ol.Collection`
controls = options.controls;
}
@@ -1519,7 +1519,7 @@ ol.Map.createOptionsInternal = function(options) {
if (Array.isArray(options.interactions)) {
interactions = new ol.Collection(options.interactions.slice());
} else {
- ol.assert(options.interactions instanceof ol.Collection,
+ ol.asserts.assert(options.interactions instanceof ol.Collection,
48); // Expected `interactions` to be an array or an `ol.Collection`
interactions = options.interactions;
}
@@ -1532,7 +1532,7 @@ ol.Map.createOptionsInternal = function(options) {
if (Array.isArray(options.overlays)) {
overlays = new ol.Collection(options.overlays.slice());
} else {
- ol.assert(options.overlays instanceof ol.Collection,
+ ol.asserts.assert(options.overlays instanceof ol.Collection,
49); // Expected `overlays` to be an array or an `ol.Collection`
overlays = options.overlays;
}
diff --git a/src/ol/math.js b/src/ol/math.js
index 96892c6818..d5308896b6 100644
--- a/src/ol/math.js
+++ b/src/ol/math.js
@@ -46,7 +46,7 @@ ol.math.cosh = (function() {
* @return {number} The smallest power of two greater than or equal to x.
*/
ol.math.roundUpToPowerOfTwo = function(x) {
- ol.assert(0 < x, 29); // `x` must be greater than `0`
+ ol.asserts.assert(0 < x, 29); // `x` must be greater than `0`
return Math.pow(2, Math.ceil(Math.log(x) / Math.LN2));
};
diff --git a/src/ol/renderer/layer.js b/src/ol/renderer/layer.js
index 341d4f94db..15ff460287 100644
--- a/src/ol/renderer/layer.js
+++ b/src/ol/renderer/layer.js
@@ -221,8 +221,8 @@ ol.renderer.Layer.prototype.updateLogos = function(frameState, source) {
if (typeof logo === 'string') {
frameState.logos[logo] = '';
} else if (logo) {
- ol.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
- ol.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
+ ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
+ ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
frameState.logos[logo.src] = logo.href;
}
}
diff --git a/src/ol/source/cluster.js b/src/ol/source/cluster.js
index 074ce99acd..b49a5978cf 100644
--- a/src/ol/source/cluster.js
+++ b/src/ol/source/cluster.js
@@ -55,7 +55,7 @@ ol.source.Cluster = function(options) {
*/
this.geometryFunction_ = options.geometryFunction || function(feature) {
var geometry = /** @type {ol.geom.Point} */ (feature.getGeometry());
- ol.assert(geometry instanceof ol.geom.Point,
+ ol.asserts.assert(geometry instanceof ol.geom.Point,
10); // The default `geometryFunction` can only handle `ol.geom.Point` geometries
return geometry;
};
diff --git a/src/ol/source/imagearcgisrest.js b/src/ol/source/imagearcgisrest.js
index cae2c0b250..9a5ea2b299 100644
--- a/src/ol/source/imagearcgisrest.js
+++ b/src/ol/source/imagearcgisrest.js
@@ -211,7 +211,7 @@ ol.source.ImageArcGISRest.prototype.getRequestUrl_ = function(extent, size, pixe
.replace(/MapServer\/?$/, 'MapServer/export')
.replace(/ImageServer\/?$/, 'ImageServer/exportImage');
if (modifiedUrl == url) {
- ol.assert(false, 50); // `options.featureTypes` should be an Array
+ ol.asserts.assert(false, 50); // `options.featureTypes` should be an Array
}
return ol.uri.appendParams(modifiedUrl, params);
};
diff --git a/src/ol/source/imagewms.js b/src/ol/source/imagewms.js
index 5b0f1a3e8c..f28dce2897 100644
--- a/src/ol/source/imagewms.js
+++ b/src/ol/source/imagewms.js
@@ -267,7 +267,7 @@ ol.source.ImageWMS.prototype.getImageLoadFunction = function() {
*/
ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio, projection, params) {
- ol.assert(this.url_ !== undefined, 9); // `url` must be configured or set using `#setUrl()`
+ ol.asserts.assert(this.url_ !== undefined, 9); // `url` must be configured or set using `#setUrl()`
params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
@@ -293,7 +293,7 @@ ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio,
params['DPI'] = 90 * pixelRatio;
break;
default:
- ol.assert(false, 8); // Unknown `serverType` configured
+ ol.asserts.assert(false, 8); // Unknown `serverType` configured
break;
}
}
diff --git a/src/ol/source/tilearcgisrest.js b/src/ol/source/tilearcgisrest.js
index ef8f3f0bdb..f8d68389f4 100644
--- a/src/ol/source/tilearcgisrest.js
+++ b/src/ol/source/tilearcgisrest.js
@@ -110,7 +110,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize
.replace(/MapServer\/?$/, 'MapServer/export')
.replace(/ImageServer\/?$/, 'ImageServer/exportImage');
if (modifiedUrl == url) {
- ol.assert(false, 50); // Cannot determine Rest Service from url
+ ol.asserts.assert(false, 50); // Cannot determine Rest Service from url
}
return ol.uri.appendParams(modifiedUrl, params);
};
diff --git a/src/ol/source/tileutfgrid.js b/src/ol/source/tileutfgrid.js
index c11c500345..7111861fdd 100644
--- a/src/ol/source/tileutfgrid.js
+++ b/src/ol/source/tileutfgrid.js
@@ -69,7 +69,7 @@ ol.source.TileUTFGrid = function(options) {
} else if (options.tileJSON) {
this.handleTileJSONResponse(options.tileJSON);
} else {
- ol.assert(false, 51); // Either `url` or `tileJSON` options must be provided
+ ol.asserts.assert(false, 51); // Either `url` or `tileJSON` options must be provided
}
};
ol.inherits(ol.source.TileUTFGrid, ol.source.Tile);
diff --git a/src/ol/source/tilewms.js b/src/ol/source/tilewms.js
index ad8070074d..f4d111f4c4 100644
--- a/src/ol/source/tilewms.js
+++ b/src/ol/source/tilewms.js
@@ -237,7 +237,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileE
params['DPI'] = 90 * pixelRatio;
break;
default:
- ol.assert(false, 52); // Unknown `serverType` configured
+ ol.asserts.assert(false, 52); // Unknown `serverType` configured
break;
}
}
diff --git a/src/ol/source/vector.js b/src/ol/source/vector.js
index dbefbe8352..7cec3a8edc 100644
--- a/src/ol/source/vector.js
+++ b/src/ol/source/vector.js
@@ -101,7 +101,7 @@ ol.source.Vector = function(opt_options) {
if (options.loader !== undefined) {
this.loader_ = options.loader;
} else if (this.url_ !== undefined) {
- ol.assert(this.format_, 7); // `format` must be set when `url` is set
+ ol.asserts.assert(this.format_, 7); // `format` must be set when `url` is set
// create a XHR feature loader for "url" and "format"
this.loader_ = ol.featureloader.xhr(this.url_, /** @type {ol.format.Feature} */ (this.format_));
}
@@ -257,7 +257,7 @@ ol.source.Vector.prototype.addToIndex_ = function(featureKey, feature) {
valid = false;
}
} else {
- ol.assert(!(featureKey in this.undefIdIndex_),
+ ol.asserts.assert(!(featureKey in this.undefIdIndex_),
30); // The passed `feature` was already added to the source
this.undefIdIndex_[featureKey] = feature;
}
diff --git a/src/ol/source/zoomify.js b/src/ol/source/zoomify.js
index cba5e88750..e2311082ce 100644
--- a/src/ol/source/zoomify.js
+++ b/src/ol/source/zoomify.js
@@ -64,7 +64,7 @@ ol.source.Zoomify = function(opt_options) {
}
break;
default:
- ol.assert(false, 53); // Unknown `tierSizeCalculation` configured
+ ol.asserts.assert(false, 53); // Unknown `tierSizeCalculation` configured
break;
}
diff --git a/src/ol/structs/lrucache.js b/src/ol/structs/lrucache.js
index b8735f573b..1614780f2b 100644
--- a/src/ol/structs/lrucache.js
+++ b/src/ol/structs/lrucache.js
@@ -130,7 +130,7 @@ ol.structs.LRUCache.prototype.forEach = function(f, opt_this) {
*/
ol.structs.LRUCache.prototype.get = function(key) {
var entry = this.entries_[key];
- ol.assert(entry !== undefined,
+ ol.asserts.assert(entry !== undefined,
15); // Tried to get a value for a key that does not exist in the cache
if (entry === this.newest_) {
return entry.value_;
@@ -244,7 +244,7 @@ ol.structs.LRUCache.prototype.replace = function(key, value) {
ol.structs.LRUCache.prototype.set = function(key, value) {
goog.DEBUG && console.assert(!(key in {}),
'key is not a standard property of objects (e.g. "__proto__")');
- ol.assert(!(key in this.entries_),
+ ol.asserts.assert(!(key in this.entries_),
16); // Tried to set a value for a key that is used already
var entry = /** @type {ol.LRUCacheEntry} */ ({
key_: key,
diff --git a/src/ol/structs/priorityqueue.js b/src/ol/structs/priorityqueue.js
index dc2dfb9270..2a597ef210 100644
--- a/src/ol/structs/priorityqueue.js
+++ b/src/ol/structs/priorityqueue.js
@@ -125,7 +125,7 @@ ol.structs.PriorityQueue.prototype.dequeue = function() {
* @return {boolean} The element was added to the queue.
*/
ol.structs.PriorityQueue.prototype.enqueue = function(element) {
- ol.assert(!(this.keyFunction_(element) in this.queuedElements_),
+ ol.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_),
31); // Tried to enqueue an `element` that was already added to the queue
var priority = this.priorityFunction_(element);
if (priority != ol.structs.PriorityQueue.DROP) {
diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js
index 5ea231e890..9483d44689 100644
--- a/src/ol/style/icon.js
+++ b/src/ol/style/icon.js
@@ -101,15 +101,15 @@ ol.style.Icon = function(opt_options) {
*/
var src = options.src;
- ol.assert(!(src !== undefined && image),
+ ol.asserts.assert(!(src !== undefined && image),
4); // `image` and `src` cannot be provided at the same time
- ol.assert(!image || (image && imgSize),
+ ol.asserts.assert(!image || (image && imgSize),
5); // `imgSize` must be set when `image` is provided
if ((src === undefined || src.length === 0) && image) {
src = image.src || ol.getUid(image).toString();
}
- ol.assert(src !== undefined && src.length > 0,
+ ol.asserts.assert(src !== undefined && src.length > 0,
6); // A defined and non-empty `src` or `image` must be provided
/**
diff --git a/src/ol/style/style.js b/src/ol/style/style.js
index e19e814963..e0210b3755 100644
--- a/src/ol/style/style.js
+++ b/src/ol/style/style.js
@@ -201,7 +201,7 @@ ol.style.createStyleFunction = function(obj) {
if (Array.isArray(obj)) {
styles = obj;
} else {
- ol.assert(obj instanceof ol.style.Style,
+ ol.asserts.assert(obj instanceof ol.style.Style,
41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
styles = [obj];
}
diff --git a/src/ol/tilegrid/tilegrid.js b/src/ol/tilegrid/tilegrid.js
index 9971bdbdd3..f66b0ece9d 100644
--- a/src/ol/tilegrid/tilegrid.js
+++ b/src/ol/tilegrid/tilegrid.js
@@ -32,7 +32,7 @@ ol.tilegrid.TileGrid = function(options) {
* @type {!Array.}
*/
this.resolutions_ = options.resolutions;
- ol.assert(ol.array.isSorted(this.resolutions_, function(a, b) {
+ ol.asserts.assert(ol.array.isSorted(this.resolutions_, function(a, b) {
return b - a;
}, true), 17); // `resolutions` must be sorted in descending order
@@ -55,7 +55,7 @@ ol.tilegrid.TileGrid = function(options) {
this.origins_ = null;
if (options.origins !== undefined) {
this.origins_ = options.origins;
- ol.assert(this.origins_.length == this.resolutions_.length,
+ ol.asserts.assert(this.origins_.length == this.resolutions_.length,
20); // Number of `origins` and `resolutions` must be equal
}
@@ -66,7 +66,7 @@ ol.tilegrid.TileGrid = function(options) {
this.origin_ = ol.extent.getTopLeft(extent);
}
- ol.assert(
+ ol.asserts.assert(
(!this.origin_ && this.origins_) || (this.origin_ && !this.origins_),
18); // Either `origin` or `origins` must be configured, never both
@@ -77,7 +77,7 @@ ol.tilegrid.TileGrid = function(options) {
this.tileSizes_ = null;
if (options.tileSizes !== undefined) {
this.tileSizes_ = options.tileSizes;
- ol.assert(this.tileSizes_.length == this.resolutions_.length,
+ ol.asserts.assert(this.tileSizes_.length == this.resolutions_.length,
19); // Number of `tileSizes` and `resolutions` must be equal
}
@@ -88,7 +88,7 @@ ol.tilegrid.TileGrid = function(options) {
this.tileSize_ = options.tileSize !== undefined ?
options.tileSize :
!this.tileSizes_ ? ol.DEFAULT_TILE_SIZE : null;
- ol.assert(
+ ol.asserts.assert(
(!this.tileSize_ && this.tileSizes_) ||
(this.tileSize_ && !this.tileSizes_),
22); // Either `tileSize` or `tileSizes` must be configured, never both
@@ -122,7 +122,7 @@ ol.tilegrid.TileGrid = function(options) {
Math.min(0, size[0]), Math.max(size[0] - 1, -1),
Math.min(0, size[1]), Math.max(size[1] - 1, -1));
if (this.minZoom <= z && z <= this.maxZoom && extent !== undefined) {
- ol.assert(tileRange.containsTileRange(
+ ol.asserts.assert(tileRange.containsTileRange(
this.getTileRangeForExtentAndZ(extent, z)),
21); // Tile range for `extent` must not exceed tilegrid width and height
}
diff --git a/src/ol/tilerange.js b/src/ol/tilerange.js
index 727bc08771..9575b6495a 100644
--- a/src/ol/tilerange.js
+++ b/src/ol/tilerange.js
@@ -54,7 +54,7 @@ ol.TileRange.boundingTileRange = function(var_args) {
tileCoordZ = tileCoord[0];
tileCoordX = tileCoord[1];
tileCoordY = tileCoord[2];
- ol.assert(tileCoordZ == tileCoord0Z,
+ ol.asserts.assert(tileCoordZ == tileCoord0Z,
23); // The passed `ol.TileCoord`s must all have the same `z` value
tileRange.minX = Math.min(tileRange.minX, tileCoordX);
tileRange.maxX = Math.max(tileRange.maxX, tileCoordX);
diff --git a/src/ol/tileurlfunction.js b/src/ol/tileurlfunction.js
index f03c4fef19..cbaa718fab 100644
--- a/src/ol/tileurlfunction.js
+++ b/src/ol/tileurlfunction.js
@@ -34,7 +34,7 @@ ol.TileUrlFunction.createFromTemplate = function(template, tileGrid) {
.replace(dashYRegEx, function() {
var z = tileCoord[0];
var range = tileGrid.getFullTileRange(z);
- ol.assert(range, 55); // The {-y} placeholder requires a tile grid with extent
+ ol.asserts.assert(range, 55); // The {-y} placeholder requires a tile grid with extent
var y = range.getHeight() + tileCoord[2];
return y.toString();
});
diff --git a/src/ol/transform.js b/src/ol/transform.js
index ec8dd97147..5bf0e9030d 100644
--- a/src/ol/transform.js
+++ b/src/ol/transform.js
@@ -199,7 +199,7 @@ ol.transform.compose = function(transform, dx1, dy1, sx, sy, angle, dx2, dy2) {
*/
ol.transform.invert = function(transform) {
var det = ol.transform.determinant(transform);
- ol.assert(det !== 0, 32); // Transformation matrix cannot be inverted
+ ol.asserts.assert(det !== 0, 32); // Transformation matrix cannot be inverted
var a = transform[0];
var b = transform[1];
diff --git a/src/ol/view.js b/src/ol/view.js
index afeb8cf404..04f3323b9f 100644
--- a/src/ol/view.js
+++ b/src/ol/view.js
@@ -289,11 +289,11 @@ ol.View.prototype.getHints = function(opt_hints) {
*/
ol.View.prototype.calculateExtent = function(size) {
var center = /** @type {!ol.Coordinate} */ (this.getCenter());
- ol.assert(center, 1); // The view center is not defined
+ ol.asserts.assert(center, 1); // The view center is not defined
var resolution = /** @type {!number} */ (this.getResolution());
- ol.assert(resolution !== undefined, 2); // The view resolution is not defined
+ ol.asserts.assert(resolution !== undefined, 2); // The view resolution is not defined
var rotation = /** @type {!number} */ (this.getRotation());
- ol.assert(rotation !== undefined, 3); // The view rotation is not defined
+ ol.asserts.assert(rotation !== undefined, 3); // The view rotation is not defined
return ol.extent.getForViewAndSize(center, resolution, rotation, size);
};
@@ -492,9 +492,9 @@ ol.View.prototype.getZoom = function() {
*/
ol.View.prototype.fit = function(geometry, size, opt_options) {
if (!(geometry instanceof ol.geom.SimpleGeometry)) {
- ol.assert(Array.isArray(geometry),
+ ol.asserts.assert(Array.isArray(geometry),
24); // Invalid extent or geometry provided as `geometry`
- ol.assert(!ol.extent.isEmpty(geometry),
+ ol.asserts.assert(!ol.extent.isEmpty(geometry),
25); // Cannot fit empty extent provided as `geometry`
geometry = ol.geom.Polygon.fromExtent(geometry);
}
diff --git a/test/spec/ol/assertionerror.test.js b/test/spec/ol/assertionerror.test.js
new file mode 100644
index 0000000000..b81f69264e
--- /dev/null
+++ b/test/spec/ol/assertionerror.test.js
@@ -0,0 +1,26 @@
+goog.provide('ol.AssertionError.test');
+
+goog.require('ol');
+goog.require('ol.AssertionError');
+
+describe('ol.AssertionError', function() {
+ it('generates a message', function() {
+ var error = new ol.AssertionError(42);
+ expect(error.message).to.be('Assertion failed. See /doc/errors/#42 for details.');
+ });
+ it('generates a message with a versioned url', function() {
+ var origVersion = ol.VERSION;
+ ol.VERSION = 'foo';
+ var error = new ol.AssertionError(42);
+ expect(error.message).to.be('Assertion failed. See http://openlayers.org/en/foo/doc/errors/#42 for details.');
+ ol.VERSION = origVersion;
+ });
+ it('has an error code', function() {
+ var error = new ol.AssertionError(42);
+ expect(error.code).to.be(42);
+ });
+ it('has a name', function() {
+ var error = new ol.AssertionError(42);
+ expect(error.name).to.be('AssertionError');
+ });
+});
diff --git a/test/spec/ol/asserts.test.js b/test/spec/ol/asserts.test.js
new file mode 100644
index 0000000000..4e250b3a85
--- /dev/null
+++ b/test/spec/ol/asserts.test.js
@@ -0,0 +1,16 @@
+goog.provide('ol.asserts.asserts.test');
+
+goog.require('ol.asserts');
+
+
+describe('ol.asserts', function() {
+
+ describe('ol.asserts.assert', function() {
+ it('throws an exception', function() {
+ expect(function() {
+ ol.asserts.assert(false, 42);
+ }).to.throwException();
+ });
+ });
+
+});
diff --git a/test/spec/ol/ol.test.js b/test/spec/ol/ol.test.js
deleted file mode 100644
index 8ad3ba3dc6..0000000000
--- a/test/spec/ol/ol.test.js
+++ /dev/null
@@ -1,38 +0,0 @@
-goog.provide('ol.test');
-
-goog.require('ol');
-
-
-describe('ol', function() {
-
- describe('ol.assert', function() {
- it('throws an exception', function() {
- expect(function() {
- ol.assert(false, 42);
- }).to.throwException();
- });
- });
-
- describe('ol.AssertionError', function() {
- it('generates a message', function() {
- var error = new ol.AssertionError(42);
- expect(error.message).to.be('Assertion failed. See /doc/errors/#42 for details.');
- });
- it('generates a message with a versioned url', function() {
- var origVersion = ol.VERSION;
- ol.VERSION = 'foo';
- var error = new ol.AssertionError(42);
- expect(error.message).to.be('Assertion failed. See http://openlayers.org/en/foo/doc/errors/#42 for details.');
- ol.VERSION = origVersion;
- });
- it('has an error code', function() {
- var error = new ol.AssertionError(42);
- expect(error.code).to.be(42);
- });
- it('has a name', function() {
- var error = new ol.AssertionError(42);
- expect(error.name).to.be('AssertionError');
- });
- });
-
-});
diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js
index ba006097fa..2d32a12adb 100644
--- a/test/spec/ol/view.test.js
+++ b/test/spec/ol/view.test.js
@@ -1,5 +1,6 @@
goog.provide('ol.test.View');
+goog.require('ol');
goog.require('ol.View');
goog.require('ol.extent');
goog.require('ol.geom.LineString');