Remove goog.asserts.*

This pull requests replaces type check hint assertions with type casts,
library sanity check assertions with conditional console.assert statements
in debug mode, and runtime sanity checks with assertions that throw an
ol.AssertionError with an error code for lookup outside the library.
This commit is contained in:
Andreas Hocevar
2016-07-19 16:39:58 +02:00
parent f50f1f401c
commit 6f5ed17fc5
158 changed files with 1488 additions and 1629 deletions
+10 -12
View File
@@ -1,6 +1,5 @@
goog.provide('ol.format.GML2');
goog.require('goog.asserts');
goog.require('ol.extent');
goog.require('ol.format.GMLBase');
goog.require('ol.format.XSD');
@@ -56,7 +55,6 @@ ol.format.GML2.schemaLocation_ = ol.format.GMLBase.GMLNS +
ol.format.GML2.prototype.readFlatCoordinates_ = function(node, objectStack) {
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
var context = /** @type {ol.XmlNodeStackItem} */ (objectStack[0]);
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var containerSrs = context['srsName'];
var containerDimension = node.parentNode.getAttribute('srsDimension');
var axisOrientation = 'enu';
@@ -101,9 +99,9 @@ ol.format.GML2.prototype.readFlatCoordinates_ = function(node, objectStack) {
* @return {ol.Extent|undefined} Envelope.
*/
ol.format.GML2.prototype.readBox_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'Box', 'localName should be Box');
ol.DEBUG && console.assert(node.localName == 'Box', 'localName should be Box');
/** @type {Array.<number>} */
var flatCoordinates = ol.xml.pushParseAndPop([null],
this.BOX_PARSERS_, node, objectStack, this);
@@ -119,9 +117,9 @@ ol.format.GML2.prototype.readBox_ = function(node, objectStack) {
* @private
*/
ol.format.GML2.prototype.innerBoundaryIsParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'innerBoundaryIs',
ol.DEBUG && console.assert(node.localName == 'innerBoundaryIs',
'localName should be innerBoundaryIs');
/** @type {Array.<number>|undefined} */
var flatLinearRing = ol.xml.pushParseAndPop(undefined,
@@ -129,9 +127,9 @@ ol.format.GML2.prototype.innerBoundaryIsParser_ = function(node, objectStack) {
if (flatLinearRing) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(Array.isArray(flatLinearRings),
ol.DEBUG && console.assert(Array.isArray(flatLinearRings),
'flatLinearRings should be an array');
goog.asserts.assert(flatLinearRings.length > 0,
ol.DEBUG && console.assert(flatLinearRings.length > 0,
'flatLinearRings should have an array length larger than 0');
flatLinearRings.push(flatLinearRing);
}
@@ -144,9 +142,9 @@ ol.format.GML2.prototype.innerBoundaryIsParser_ = function(node, objectStack) {
* @private
*/
ol.format.GML2.prototype.outerBoundaryIsParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'outerBoundaryIs',
ol.DEBUG && console.assert(node.localName == 'outerBoundaryIs',
'localName should be outerBoundaryIs');
/** @type {Array.<number>|undefined} */
var flatLinearRing = ol.xml.pushParseAndPop(undefined,
@@ -154,9 +152,9 @@ ol.format.GML2.prototype.outerBoundaryIsParser_ = function(node, objectStack) {
if (flatLinearRing) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(Array.isArray(flatLinearRings),
ol.DEBUG && console.assert(Array.isArray(flatLinearRings),
'flatLinearRings should be an array');
goog.asserts.assert(flatLinearRings.length > 0,
ol.DEBUG && console.assert(flatLinearRings.length > 0,
'flatLinearRings should have an array length larger than 0');
flatLinearRings[0] = flatLinearRing;
}
+38 -62
View File
@@ -1,7 +1,6 @@
goog.provide('ol.format.GML');
goog.provide('ol.format.GML3');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.array');
goog.require('ol.Feature');
@@ -93,9 +92,9 @@ ol.format.GML3.schemaLocation_ = ol.format.GMLBase.GMLNS +
* @return {ol.geom.MultiLineString|undefined} MultiLineString.
*/
ol.format.GML3.prototype.readMultiCurve_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'MultiCurve',
ol.DEBUG && console.assert(node.localName == 'MultiCurve',
'localName should be MultiCurve');
/** @type {Array.<ol.geom.LineString>} */
var lineStrings = ol.xml.pushParseAndPop([],
@@ -117,9 +116,9 @@ ol.format.GML3.prototype.readMultiCurve_ = function(node, objectStack) {
* @return {ol.geom.MultiPolygon|undefined} MultiPolygon.
*/
ol.format.GML3.prototype.readMultiSurface_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'MultiSurface',
ol.DEBUG && console.assert(node.localName == 'MultiSurface',
'localName should be MultiSurface');
/** @type {Array.<ol.geom.Polygon>} */
var polygons = ol.xml.pushParseAndPop([],
@@ -140,9 +139,9 @@ ol.format.GML3.prototype.readMultiSurface_ = function(node, objectStack) {
* @private
*/
ol.format.GML3.prototype.curveMemberParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'curveMember' ||
ol.DEBUG && console.assert(node.localName == 'curveMember' ||
node.localName == 'curveMembers',
'localName should be curveMember or curveMembers');
ol.xml.parseNode(this.CURVEMEMBER_PARSERS_, node, objectStack, this);
@@ -155,9 +154,9 @@ ol.format.GML3.prototype.curveMemberParser_ = function(node, objectStack) {
* @private
*/
ol.format.GML3.prototype.surfaceMemberParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'surfaceMember' ||
ol.DEBUG && console.assert(node.localName == 'surfaceMember' ||
node.localName == 'surfaceMembers',
'localName should be surfaceMember or surfaceMembers');
ol.xml.parseNode(this.SURFACEMEMBER_PARSERS_,
@@ -172,9 +171,9 @@ ol.format.GML3.prototype.surfaceMemberParser_ = function(node, objectStack) {
* @return {Array.<(Array.<number>)>|undefined} flat coordinates.
*/
ol.format.GML3.prototype.readPatch_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'patches',
ol.DEBUG && console.assert(node.localName == 'patches',
'localName should be patches');
return ol.xml.pushParseAndPop([null],
this.PATCHES_PARSERS_, node, objectStack, this);
@@ -188,9 +187,9 @@ ol.format.GML3.prototype.readPatch_ = function(node, objectStack) {
* @return {Array.<number>|undefined} flat coordinates.
*/
ol.format.GML3.prototype.readSegment_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'segments',
ol.DEBUG && console.assert(node.localName == 'segments',
'localName should be segments');
return ol.xml.pushParseAndPop([null],
this.SEGMENTS_PARSERS_, node, objectStack, this);
@@ -204,9 +203,9 @@ ol.format.GML3.prototype.readSegment_ = function(node, objectStack) {
* @return {Array.<(Array.<number>)>|undefined} flat coordinates.
*/
ol.format.GML3.prototype.readPolygonPatch_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'npde.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'PolygonPatch',
ol.DEBUG && console.assert(node.localName == 'PolygonPatch',
'localName should be PolygonPatch');
return ol.xml.pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
@@ -220,9 +219,9 @@ ol.format.GML3.prototype.readPolygonPatch_ = function(node, objectStack) {
* @return {Array.<number>|undefined} flat coordinates.
*/
ol.format.GML3.prototype.readLineStringSegment_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'LineStringSegment',
ol.DEBUG && console.assert(node.localName == 'LineStringSegment',
'localName should be LineStringSegment');
return ol.xml.pushParseAndPop([null],
this.GEOMETRY_FLAT_COORDINATES_PARSERS_,
@@ -236,9 +235,9 @@ ol.format.GML3.prototype.readLineStringSegment_ = function(node, objectStack) {
* @private
*/
ol.format.GML3.prototype.interiorParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'interior',
ol.DEBUG && console.assert(node.localName == 'interior',
'localName should be interior');
/** @type {Array.<number>|undefined} */
var flatLinearRing = ol.xml.pushParseAndPop(undefined,
@@ -246,9 +245,9 @@ ol.format.GML3.prototype.interiorParser_ = function(node, objectStack) {
if (flatLinearRing) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(Array.isArray(flatLinearRings),
ol.DEBUG && console.assert(Array.isArray(flatLinearRings),
'flatLinearRings should be an array');
goog.asserts.assert(flatLinearRings.length > 0,
ol.DEBUG && console.assert(flatLinearRings.length > 0,
'flatLinearRings should have an array length of 1 or more');
flatLinearRings.push(flatLinearRing);
}
@@ -261,9 +260,9 @@ ol.format.GML3.prototype.interiorParser_ = function(node, objectStack) {
* @private
*/
ol.format.GML3.prototype.exteriorParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'exterior',
ol.DEBUG && console.assert(node.localName == 'exterior',
'localName should be exterior');
/** @type {Array.<number>|undefined} */
var flatLinearRing = ol.xml.pushParseAndPop(undefined,
@@ -271,9 +270,9 @@ ol.format.GML3.prototype.exteriorParser_ = function(node, objectStack) {
if (flatLinearRing) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(Array.isArray(flatLinearRings),
ol.DEBUG && console.assert(Array.isArray(flatLinearRings),
'flatLinearRings should be an array');
goog.asserts.assert(flatLinearRings.length > 0,
ol.DEBUG && console.assert(flatLinearRings.length > 0,
'flatLinearRings should have an array length of 1 or more');
flatLinearRings[0] = flatLinearRing;
}
@@ -287,9 +286,9 @@ ol.format.GML3.prototype.exteriorParser_ = function(node, objectStack) {
* @return {ol.geom.Polygon|undefined} Polygon.
*/
ol.format.GML3.prototype.readSurface_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'Surface',
ol.DEBUG && console.assert(node.localName == 'Surface',
'localName should be Surface');
/** @type {Array.<Array.<number>>} */
var flatLinearRings = ol.xml.pushParseAndPop([null],
@@ -319,9 +318,9 @@ ol.format.GML3.prototype.readSurface_ = function(node, objectStack) {
* @return {ol.geom.LineString|undefined} LineString.
*/
ol.format.GML3.prototype.readCurve_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'Curve', 'localName should be Curve');
ol.DEBUG && console.assert(node.localName == 'Curve', 'localName should be Curve');
/** @type {Array.<number>} */
var flatCoordinates = ol.xml.pushParseAndPop([null],
this.CURVE_PARSERS_, node, objectStack, this);
@@ -342,9 +341,9 @@ ol.format.GML3.prototype.readCurve_ = function(node, objectStack) {
* @return {ol.Extent|undefined} Envelope.
*/
ol.format.GML3.prototype.readEnvelope_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'Envelope',
ol.DEBUG && console.assert(node.localName == 'Envelope',
'localName should be Envelope');
/** @type {Array.<number>} */
var flatCoordinates = ol.xml.pushParseAndPop([null],
@@ -375,7 +374,6 @@ ol.format.GML3.prototype.readFlatPos_ = function(node, objectStack) {
return undefined;
}
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var containerSrs = context['srsName'];
var axisOrientation = 'enu';
if (containerSrs) {
@@ -411,7 +409,6 @@ ol.format.GML3.prototype.readFlatPos_ = function(node, objectStack) {
ol.format.GML3.prototype.readFlatPosList_ = function(node, objectStack) {
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var containerSrs = context['srsName'];
var containerDimension = node.parentNode.getAttribute('srsDimension');
var axisOrientation = 'enu';
@@ -633,7 +630,6 @@ ol.format.GML3.prototype.SEGMENTS_PARSERS_ = {
*/
ol.format.GML3.prototype.writePos_ = function(node, value, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
var axisOrientation = 'enu';
if (srsName) {
@@ -676,7 +672,6 @@ ol.format.GML3.prototype.getCoords_ = function(point, opt_srsName) {
*/
ol.format.GML3.prototype.writePosList_ = function(node, value, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
// only 2d for simple features profile
var points = value.getCoordinates();
@@ -699,7 +694,6 @@ ol.format.GML3.prototype.writePosList_ = function(node, value, objectStack) {
*/
ol.format.GML3.prototype.writePoint_ = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (srsName) {
node.setAttribute('srsName', srsName);
@@ -728,9 +722,8 @@ ol.format.GML3.ENVELOPE_SERIALIZERS_ = {
* @param {Array.<*>} objectStack Node stack.
*/
ol.format.GML3.prototype.writeEnvelope = function(node, extent, objectStack) {
goog.asserts.assert(extent.length == 4, 'extent should have 4 items');
ol.DEBUG && console.assert(extent.length == 4, 'extent should have 4 items');
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (srsName) {
node.setAttribute('srsName', srsName);
@@ -753,7 +746,6 @@ ol.format.GML3.prototype.writeEnvelope = function(node, extent, objectStack) {
*/
ol.format.GML3.prototype.writeLinearRing_ = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (srsName) {
node.setAttribute('srsName', srsName);
@@ -774,7 +766,6 @@ ol.format.GML3.prototype.writeLinearRing_ = function(node, geometry, objectStack
ol.format.GML3.prototype.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
var context = objectStack[objectStack.length - 1];
var parentNode = context.node;
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var exteriorWritten = context['exteriorWritten'];
if (exteriorWritten === undefined) {
context['exteriorWritten'] = true;
@@ -792,7 +783,6 @@ ol.format.GML3.prototype.RING_NODE_FACTORY_ = function(value, objectStack, opt_n
*/
ol.format.GML3.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (node.nodeName !== 'PolygonPatch' && srsName) {
node.setAttribute('srsName', srsName);
@@ -821,7 +811,6 @@ ol.format.GML3.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objec
*/
ol.format.GML3.prototype.writeCurveOrLineString_ = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (node.nodeName !== 'LineStringSegment' && srsName) {
node.setAttribute('srsName', srsName);
@@ -848,7 +837,6 @@ ol.format.GML3.prototype.writeCurveOrLineString_ = function(node, geometry, obje
*/
ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
var surface = context['surface'];
if (srsName) {
@@ -871,7 +859,6 @@ ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry,
ol.format.GML3.prototype.writeMultiPoint_ = function(node, geometry,
objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
if (srsName) {
node.setAttribute('srsName', srsName);
@@ -892,7 +879,6 @@ ol.format.GML3.prototype.writeMultiPoint_ = function(node, geometry,
*/
ol.format.GML3.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var srsName = context['srsName'];
var curve = context['curve'];
if (srsName) {
@@ -927,7 +913,6 @@ ol.format.GML3.prototype.writeRing_ = function(node, ring, objectStack) {
*/
ol.format.GML3.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var child = this.GEOMETRY_NODE_FACTORY_(
polygon, objectStack);
if (child) {
@@ -958,7 +943,6 @@ ol.format.GML3.prototype.writePointMember_ = function(node, point, objectStack)
*/
ol.format.GML3.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var child = this.GEOMETRY_NODE_FACTORY_(line, objectStack);
if (child) {
node.appendChild(child);
@@ -1000,8 +984,7 @@ ol.format.GML3.prototype.writeCurveSegments_ = function(node, line, objectStack)
* @param {Array.<*>} objectStack Node stack.
*/
ol.format.GML3.prototype.writeGeometryElement = function(node, geometry, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var context = /** @type {olx.format.WriteOptions} */ (objectStack[objectStack.length - 1]);
var item = ol.object.assign({}, context);
item.node = node;
var value;
@@ -1013,10 +996,8 @@ ol.format.GML3.prototype.writeGeometryElement = function(node, geometry, objectS
value = geometry;
}
} else {
goog.asserts.assertInstanceof(geometry, ol.geom.Geometry,
'geometry should be an ol.geom.Geometry');
value =
ol.format.Feature.transformWithOptions(geometry, true, context);
ol.format.Feature.transformWithOptions(/** @type {ol.geom.Geometry} */ (geometry), true, context);
}
ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */
(item), ol.format.GML3.GEOMETRY_SERIALIZERS_,
@@ -1035,8 +1016,7 @@ ol.format.GML3.prototype.writeFeatureElement = function(node, feature, objectSta
if (fid) {
node.setAttribute('fid', fid);
}
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
var featureNS = context['featureNS'];
var geometryName = feature.getGeometryName();
if (!context.serializers) {
@@ -1080,8 +1060,7 @@ ol.format.GML3.prototype.writeFeatureElement = function(node, feature, objectSta
* @private
*/
ol.format.GML3.prototype.writeFeatureMembers_ = function(node, features, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
var featureType = context['featureType'];
var featureNS = context['featureNS'];
var serializers = {};
@@ -1206,7 +1185,7 @@ ol.format.GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
*/
ol.format.GML3.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
var parentNode = objectStack[objectStack.length - 1].node;
goog.asserts.assert(ol.xml.isNode(parentNode),
ol.DEBUG && console.assert(ol.xml.isNode(parentNode),
'parentNode should be a node');
return ol.xml.createElementNS('http://www.opengis.net/gml',
ol.format.GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]);
@@ -1223,19 +1202,16 @@ ol.format.GML3.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, ob
*/
ol.format.GML3.prototype.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var multiSurface = context['multiSurface'];
var surface = context['surface'];
var curve = context['curve'];
var multiCurve = context['multiCurve'];
var parentNode = objectStack[objectStack.length - 1].node;
goog.asserts.assert(ol.xml.isNode(parentNode),
ol.DEBUG && console.assert(ol.xml.isNode(parentNode),
'parentNode should be a node');
var nodeName;
if (!Array.isArray(value)) {
goog.asserts.assertInstanceof(value, ol.geom.Geometry,
'value should be an ol.geom.Geometry');
nodeName = value.getType();
nodeName = /** @type {ol.geom.Geometry} */ (value).getType();
if (nodeName === 'MultiPolygon' && multiSurface === true) {
nodeName = 'MultiSurface';
} else if (nodeName === 'Polygon' && surface === true) {
+26 -29
View File
@@ -3,7 +3,6 @@
// envelopes/extents, only geometries!
goog.provide('ol.format.GMLBase');
goog.require('goog.asserts');
goog.require('ol.array');
goog.require('ol.Feature');
goog.require('ol.format.Feature');
@@ -108,7 +107,7 @@ ol.format.GMLBase.ONLY_WHITESPACE_RE_ = /^[\s\xa0]*$/;
* @return {Array.<ol.Feature> | undefined} Features.
*/
ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
var localName = node.localName;
var features = null;
@@ -124,7 +123,6 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
}
} else if (localName == 'featureMembers' || localName == 'featureMember') {
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var featureType = context['featureType'];
var featureNS = context['featureNS'];
var i, ii, prefix = 'p', defaultPrefix = 'p0';
@@ -199,8 +197,7 @@ ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
* @return {ol.geom.Geometry|undefined} Geometry.
*/
ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) {
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
var context = /** @type {Object} */ (objectStack[0]);
context['srsName'] = node.firstElementChild.getAttribute('srsName');
/** @type {ol.geom.Geometry} */
var geometry = ol.xml.pushParseAndPop(null,
@@ -262,14 +259,14 @@ ol.format.GMLBase.prototype.readFeatureElement = function(node, objectStack) {
* @return {ol.geom.Point|undefined} Point.
*/
ol.format.GMLBase.prototype.readPoint = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'Point', 'localName should be Point');
ol.DEBUG && console.assert(node.localName == 'Point', 'localName should be Point');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (flatCoordinates) {
var point = new ol.geom.Point(null);
goog.asserts.assert(flatCoordinates.length == 3,
ol.DEBUG && console.assert(flatCoordinates.length == 3,
'flatCoordinates should have a length of 3');
point.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
return point;
@@ -283,9 +280,9 @@ ol.format.GMLBase.prototype.readPoint = function(node, objectStack) {
* @return {ol.geom.MultiPoint|undefined} MultiPoint.
*/
ol.format.GMLBase.prototype.readMultiPoint = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'MultiPoint',
ol.DEBUG && console.assert(node.localName == 'MultiPoint',
'localName should be MultiPoint');
/** @type {Array.<Array.<number>>} */
var coordinates = ol.xml.pushParseAndPop([],
@@ -304,9 +301,9 @@ ol.format.GMLBase.prototype.readMultiPoint = function(node, objectStack) {
* @return {ol.geom.MultiLineString|undefined} MultiLineString.
*/
ol.format.GMLBase.prototype.readMultiLineString = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'MultiLineString',
ol.DEBUG && console.assert(node.localName == 'MultiLineString',
'localName should be MultiLineString');
/** @type {Array.<ol.geom.LineString>} */
var lineStrings = ol.xml.pushParseAndPop([],
@@ -327,9 +324,9 @@ ol.format.GMLBase.prototype.readMultiLineString = function(node, objectStack) {
* @return {ol.geom.MultiPolygon|undefined} MultiPolygon.
*/
ol.format.GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'MultiPolygon',
ol.DEBUG && console.assert(node.localName == 'MultiPolygon',
'localName should be MultiPolygon');
/** @type {Array.<ol.geom.Polygon>} */
var polygons = ol.xml.pushParseAndPop([],
@@ -350,9 +347,9 @@ ol.format.GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
* @private
*/
ol.format.GMLBase.prototype.pointMemberParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'pointMember' ||
ol.DEBUG && console.assert(node.localName == 'pointMember' ||
node.localName == 'pointMembers',
'localName should be pointMember or pointMembers');
ol.xml.parseNode(this.POINTMEMBER_PARSERS_,
@@ -366,9 +363,9 @@ ol.format.GMLBase.prototype.pointMemberParser_ = function(node, objectStack) {
* @private
*/
ol.format.GMLBase.prototype.lineStringMemberParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'lineStringMember' ||
ol.DEBUG && console.assert(node.localName == 'lineStringMember' ||
node.localName == 'lineStringMembers',
'localName should be LineStringMember or LineStringMembers');
ol.xml.parseNode(this.LINESTRINGMEMBER_PARSERS_,
@@ -382,9 +379,9 @@ ol.format.GMLBase.prototype.lineStringMemberParser_ = function(node, objectStack
* @private
*/
ol.format.GMLBase.prototype.polygonMemberParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'polygonMember' ||
ol.DEBUG && console.assert(node.localName == 'polygonMember' ||
node.localName == 'polygonMembers',
'localName should be polygonMember or polygonMembers');
ol.xml.parseNode(this.POLYGONMEMBER_PARSERS_, node,
@@ -398,9 +395,9 @@ ol.format.GMLBase.prototype.polygonMemberParser_ = function(node, objectStack) {
* @return {ol.geom.LineString|undefined} LineString.
*/
ol.format.GMLBase.prototype.readLineString = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'LineString',
ol.DEBUG && console.assert(node.localName == 'LineString',
'localName should be LineString');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
@@ -421,9 +418,9 @@ ol.format.GMLBase.prototype.readLineString = function(node, objectStack) {
* @return {Array.<number>|undefined} LinearRing flat coordinates.
*/
ol.format.GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'LinearRing',
ol.DEBUG && console.assert(node.localName == 'LinearRing',
'localName should be LinearRing');
var ring = ol.xml.pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
@@ -442,9 +439,9 @@ ol.format.GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
* @return {ol.geom.LinearRing|undefined} LinearRing.
*/
ol.format.GMLBase.prototype.readLinearRing = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'LinearRing',
ol.DEBUG && console.assert(node.localName == 'LinearRing',
'localName should be LinearRing');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
@@ -464,9 +461,9 @@ ol.format.GMLBase.prototype.readLinearRing = function(node, objectStack) {
* @return {ol.geom.Polygon|undefined} Polygon.
*/
ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
goog.asserts.assert(node.localName == 'Polygon',
ol.DEBUG && console.assert(node.localName == 'Polygon',
'localName should be Polygon');
/** @type {Array.<Array.<number>>} */
var flatLinearRings = ol.xml.pushParseAndPop([null],
@@ -496,7 +493,7 @@ ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) {
* @return {Array.<number>} Flat coordinates.
*/
ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == Node.ELEMENT_NODE,
ol.DEBUG && console.assert(node.nodeType == Node.ELEMENT_NODE,
'node.nodeType should be ELEMENT');
return ol.xml.pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,