From f5e5419cb61a0af69ded07a288269b26c5352ff4 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Thu, 18 Sep 2014 14:30:18 +0200 Subject: [PATCH 01/31] Move gmlformat.js to gml/base.js --- src/ol/format/{gmlformat.js => gml/base.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/ol/format/{gmlformat.js => gml/base.js} (100%) diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gml/base.js similarity index 100% rename from src/ol/format/gmlformat.js rename to src/ol/format/gml/base.js From 42b58cddbdd075251c8cf3f2eba23f9d6d0f37ce Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 10:56:40 +0200 Subject: [PATCH 02/31] Move all method declarations into ol.format.GML.prototype --- src/ol/format/gml/base.js | 116 +++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index 9f7e2dc6d9..2d84131e0d 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -116,7 +116,7 @@ ol.format.GML.schemaLocation_ = 'http://www.opengis.net/gml ' + * @return {Array.} Features. * @private */ -ol.format.GML.readFeatures_ = function(node, objectStack) { +ol.format.GML.prototype.readFeatures_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); var localName = ol.xml.getLocalName(node); var features; @@ -164,7 +164,7 @@ ol.format.GML.FEATURE_COLLECTION_PARSERS = { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.Geometry|undefined} Geometry. */ -ol.format.GML.readGeometry = function(node, objectStack) { +ol.format.GML.prototype.readGeometryElement = function(node, objectStack) { var context = objectStack[0]; goog.asserts.assert(goog.isObject(context)); goog.object.set(context, 'srsName', @@ -186,7 +186,7 @@ ol.format.GML.readGeometry = function(node, objectStack) { * @return {ol.Feature} Feature. * @private */ -ol.format.GML.readFeature_ = function(node, objectStack) { +ol.format.GML.prototype.readFeature_ = function(node, objectStack) { var n; var fid = node.getAttribute('fid') || ol.xml.getAttributeNS(node, 'http://www.opengis.net/gml', 'id'); @@ -225,7 +225,7 @@ ol.format.GML.readFeature_ = function(node, objectStack) { * @private * @return {ol.geom.Point|undefined} Point. */ -ol.format.GML.readPoint_ = function(node, objectStack) { +ol.format.GML.prototype.readPoint_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Point'); var flatCoordinates = @@ -245,7 +245,7 @@ ol.format.GML.readPoint_ = function(node, objectStack) { * @private * @return {ol.geom.MultiPoint|undefined} MultiPoint. */ -ol.format.GML.readMultiPoint_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiPoint_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiPoint'); var coordinates = ol.xml.pushParseAndPop( @@ -265,7 +265,7 @@ ol.format.GML.readMultiPoint_ = function(node, objectStack) { * @private * @return {ol.geom.MultiLineString|undefined} MultiLineString. */ -ol.format.GML.readMultiLineString_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiLineString_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiLineString'); var lineStrings = ol.xml.pushParseAndPop( @@ -287,7 +287,7 @@ ol.format.GML.readMultiLineString_ = function(node, objectStack) { * @private * @return {ol.geom.MultiLineString|undefined} MultiLineString. */ -ol.format.GML.readMultiCurve_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiCurve_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiCurve'); var lineStrings = ol.xml.pushParseAndPop( @@ -309,7 +309,7 @@ ol.format.GML.readMultiCurve_ = function(node, objectStack) { * @private * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. */ -ol.format.GML.readMultiSurface_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiSurface_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiSurface'); var polygons = ol.xml.pushParseAndPop( @@ -331,7 +331,7 @@ ol.format.GML.readMultiSurface_ = function(node, objectStack) { * @private * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. */ -ol.format.GML.readMultiPolygon_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiPolygon_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiPolygon'); var polygons = ol.xml.pushParseAndPop( @@ -352,7 +352,7 @@ ol.format.GML.readMultiPolygon_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.pointMemberParser_ = function(node, objectStack) { +ol.format.GML.prototype.pointMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'pointMember' || node.localName == 'pointMembers'); @@ -365,7 +365,7 @@ ol.format.GML.pointMemberParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.lineStringMemberParser_ = function(node, objectStack) { +ol.format.GML.prototype.lineStringMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'lineStringMember' || node.localName == 'lineStringMembers'); @@ -378,7 +378,7 @@ ol.format.GML.lineStringMemberParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.curveMemberParser_ = function(node, objectStack) { +ol.format.GML.prototype.curveMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'curveMember' || node.localName == 'curveMembers'); @@ -391,7 +391,7 @@ ol.format.GML.curveMemberParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.surfaceMemberParser_ = function(node, objectStack) { +ol.format.GML.prototype.surfaceMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'surfaceMember' || node.localName == 'surfaceMembers'); @@ -404,7 +404,7 @@ ol.format.GML.surfaceMemberParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.polygonMemberParser_ = function(node, objectStack) { +ol.format.GML.prototype.polygonMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'polygonMember' || node.localName == 'polygonMembers'); @@ -418,7 +418,7 @@ ol.format.GML.polygonMemberParser_ = function(node, objectStack) { * @private * @return {ol.geom.LineString|undefined} LineString. */ -ol.format.GML.readLineString_ = function(node, objectStack) { +ol.format.GML.prototype.readLineString_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LineString'); var flatCoordinates = @@ -439,7 +439,7 @@ ol.format.GML.readLineString_ = function(node, objectStack) { * @private * @return {Array.<(Array.)>|undefined} flat coordinates. */ -ol.format.GML.readPatch_ = function(node, objectStack) { +ol.format.GML.prototype.readPatch_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'patches'); return ol.xml.pushParseAndPop( @@ -454,7 +454,7 @@ ol.format.GML.readPatch_ = function(node, objectStack) { * @private * @return {Array.|undefined} flat coordinates. */ -ol.format.GML.readSegment_ = function(node, objectStack) { +ol.format.GML.prototype.readSegment_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'segments'); return ol.xml.pushParseAndPop( @@ -469,7 +469,7 @@ ol.format.GML.readSegment_ = function(node, objectStack) { * @private * @return {Array.<(Array.)>|undefined} flat coordinates. */ -ol.format.GML.readPolygonPatch_ = function(node, objectStack) { +ol.format.GML.prototype.readPolygonPatch_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'PolygonPatch'); return ol.xml.pushParseAndPop( @@ -484,7 +484,7 @@ ol.format.GML.readPolygonPatch_ = function(node, objectStack) { * @private * @return {Array.|undefined} flat coordinates. */ -ol.format.GML.readLineStringSegment_ = function(node, objectStack) { +ol.format.GML.prototype.readLineStringSegment_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LineStringSegment'); return ol.xml.pushParseAndPop( @@ -498,7 +498,7 @@ ol.format.GML.readLineStringSegment_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.interiorParser_ = function(node, objectStack) { +ol.format.GML.prototype.interiorParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'interior'); var flatLinearRing = ol.xml.pushParseAndPop( @@ -519,7 +519,7 @@ ol.format.GML.interiorParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.exteriorParser_ = function(node, objectStack) { +ol.format.GML.prototype.exteriorParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'exterior'); var flatLinearRing = ol.xml.pushParseAndPop( @@ -541,7 +541,7 @@ ol.format.GML.exteriorParser_ = function(node, objectStack) { * @private * @return {Array.|undefined} LinearRing flat coordinates. */ -ol.format.GML.readFlatLinearRing_ = function(node, objectStack) { +ol.format.GML.prototype.readFlatLinearRing_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var ring = ol.xml.pushParseAndPop(/** @type {Array.} */(null), @@ -560,7 +560,7 @@ ol.format.GML.readFlatLinearRing_ = function(node, objectStack) { * @private * @return {ol.geom.LinearRing|undefined} LinearRing. */ -ol.format.GML.readLinearRing_ = function(node, objectStack) { +ol.format.GML.prototype.readLinearRing_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var flatCoordinates = @@ -581,7 +581,7 @@ ol.format.GML.readLinearRing_ = function(node, objectStack) { * @private * @return {ol.geom.Polygon|undefined} Polygon. */ -ol.format.GML.readPolygon_ = function(node, objectStack) { +ol.format.GML.prototype.readPolygon_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Polygon'); var flatLinearRings = ol.xml.pushParseAndPop( @@ -612,7 +612,7 @@ ol.format.GML.readPolygon_ = function(node, objectStack) { * @private * @return {ol.geom.Polygon|undefined} Polygon. */ -ol.format.GML.readSurface_ = function(node, objectStack) { +ol.format.GML.prototype.readSurface_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Surface'); var flatLinearRings = ol.xml.pushParseAndPop( @@ -643,7 +643,7 @@ ol.format.GML.readSurface_ = function(node, objectStack) { * @private * @return {ol.geom.LineString|undefined} LineString. */ -ol.format.GML.readCurve_ = function(node, objectStack) { +ol.format.GML.prototype.readCurve_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Curve'); var flatCoordinates = ol.xml.pushParseAndPop( @@ -665,7 +665,7 @@ ol.format.GML.readCurve_ = function(node, objectStack) { * @private * @return {ol.Extent|undefined} Envelope. */ -ol.format.GML.readEnvelope_ = function(node, objectStack) { +ol.format.GML.prototype.readEnvelope_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Envelope'); var flatCoordinates = ol.xml.pushParseAndPop( @@ -683,7 +683,8 @@ ol.format.GML.readEnvelope_ = function(node, objectStack) { * @private * @return {Array.} Flat coordinates. */ -ol.format.GML.readFlatCoordinatesFromNode_ = function(node, objectStack) { +ol.format.GML.prototype.readFlatCoordinatesFromNode_ = function(node, + objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); return /** @type {Array.} */ (ol.xml.pushParseAndPop( null, @@ -697,7 +698,7 @@ ol.format.GML.readFlatCoordinatesFromNode_ = function(node, objectStack) { * @private * @return {Array.|undefined} Flat coordinates. */ -ol.format.GML.readFlatPos_ = function(node, objectStack) { +ol.format.GML.prototype.readFlatPos_ = function(node, objectStack) { var s = ol.xml.getAllTextContent(node, false); var re = /^\s*([+\-]?\d*\.?\d+(?:[eE][+\-]?\d+)?)\s*/; /** @type {Array.} */ @@ -744,7 +745,7 @@ ol.format.GML.readFlatPos_ = function(node, objectStack) { * @private * @return {Array.|undefined} Flat coordinates. */ -ol.format.GML.readFlatPosList_ = function(node, objectStack) { +ol.format.GML.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)); @@ -1097,7 +1098,7 @@ ol.format.GML.prototype.readProjectionFromNode = function(node) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writePos_ = function(node, value, objectStack) { +ol.format.GML.prototype.writePos_ = function(node, value, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -1123,7 +1124,7 @@ ol.format.GML.writePos_ = function(node, value, objectStack) { * @return {string} * @private */ -ol.format.GML.getCoords_ = function(point, opt_srsName) { +ol.format.GML.prototype.getCoords_ = function(point, opt_srsName) { var axisOrientation = 'enu'; if (goog.isDefAndNotNull(opt_srsName)) { axisOrientation = ol.proj.get(opt_srsName).getAxisOrientation(); @@ -1140,7 +1141,7 @@ ol.format.GML.getCoords_ = function(point, opt_srsName) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writePosList_ = function(node, value, objectStack) { +ol.format.GML.prototype.writePosList_ = function(node, value, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -1163,7 +1164,7 @@ ol.format.GML.writePosList_ = function(node, value, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writePoint_ = function(node, geometry, objectStack) { +ol.format.GML.prototype.writePoint_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -1193,7 +1194,7 @@ ol.format.GML.ENVELOPE_SERIALIZERS_ = { * @param {ol.Extent} extent Extent. * @param {Array.<*>} objectStack Node stack. */ -ol.format.GML.writeEnvelope = function(node, extent, objectStack) { +ol.format.GML.prototype.writeEnvelope = function(node, extent, objectStack) { goog.asserts.assert(extent.length == 4); var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1217,7 +1218,8 @@ ol.format.GML.writeEnvelope = function(node, extent, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeLinearRing_ = function(node, geometry, objectStack) { +ol.format.GML.prototype.writeLinearRing_ = + function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -1237,7 +1239,8 @@ ol.format.GML.writeLinearRing_ = function(node, geometry, objectStack) { * @return {Node} Node. * @private */ -ol.format.GML.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) { +ol.format.GML.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)); @@ -1256,7 +1259,8 @@ ol.format.GML.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) { +ol.format.GML.prototype.writeSurfaceOrPolygon_ = + function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -1283,7 +1287,8 @@ ol.format.GML.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeCurveOrLineString_ = function(node, geometry, objectStack) { +ol.format.GML.prototype.writeCurveOrLineString_ = + function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -1308,7 +1313,7 @@ ol.format.GML.writeCurveOrLineString_ = function(node, geometry, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeMultiSurfaceOrPolygon_ = function(node, geometry, +ol.format.GML.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1331,7 +1336,7 @@ ol.format.GML.writeMultiSurfaceOrPolygon_ = function(node, geometry, * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeMultiPoint_ = function(node, geometry, +ol.format.GML.prototype.writeMultiPoint_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1353,7 +1358,7 @@ ol.format.GML.writeMultiPoint_ = function(node, geometry, * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeMultiCurveOrLineString_ = function(node, geometry, +ol.format.GML.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1376,7 +1381,7 @@ ol.format.GML.writeMultiCurveOrLineString_ = function(node, geometry, * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeRing_ = function(node, ring, objectStack) { +ol.format.GML.prototype.writeRing_ = function(node, ring, objectStack) { var linearRing = ol.xml.createElementNS(node.namespaceURI, 'LinearRing'); node.appendChild(linearRing); ol.format.GML.writeLinearRing_(linearRing, ring, objectStack); @@ -1389,7 +1394,7 @@ ol.format.GML.writeRing_ = function(node, ring, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeSurfaceOrPolygonMember_ = function(node, polygon, +ol.format.GML.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1407,7 +1412,7 @@ ol.format.GML.writeSurfaceOrPolygonMember_ = function(node, polygon, * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writePointMember_ = function(node, point, objectStack) { +ol.format.GML.prototype.writePointMember_ = function(node, point, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'Point'); node.appendChild(child); ol.format.GML.writePoint_(child, point, objectStack); @@ -1420,7 +1425,7 @@ ol.format.GML.writePointMember_ = function(node, point, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeLineStringOrCurveMember_ = function(node, line, +ol.format.GML.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1438,7 +1443,8 @@ ol.format.GML.writeLineStringOrCurveMember_ = function(node, line, * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeSurfacePatches_ = function(node, polygon, objectStack) { +ol.format.GML.prototype.writeSurfacePatches_ = + function(node, polygon, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'PolygonPatch'); node.appendChild(child); ol.format.GML.writeSurfaceOrPolygon_(child, polygon, objectStack); @@ -1451,7 +1457,8 @@ ol.format.GML.writeSurfacePatches_ = function(node, polygon, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeCurveSegments_ = function(node, line, objectStack) { +ol.format.GML.prototype.writeCurveSegments_ = + function(node, line, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'LineStringSegment'); node.appendChild(child); ol.format.GML.writeCurveOrLineString_(child, line, objectStack); @@ -1463,7 +1470,8 @@ ol.format.GML.writeCurveSegments_ = function(node, line, objectStack) { * @param {ol.geom.Geometry|ol.Extent} geometry Geometry. * @param {Array.<*>} objectStack Node stack. */ -ol.format.GML.writeGeometry = function(node, geometry, objectStack) { +ol.format.GML.prototype.writeGeometryElement = + function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var item = goog.object.clone(context); @@ -1492,7 +1500,8 @@ ol.format.GML.writeGeometry = function(node, geometry, objectStack) { * @param {ol.Feature} feature Feature. * @param {Array.<*>} objectStack Node stack. */ -ol.format.GML.writeFeature = function(node, feature, objectStack) { +ol.format.GML.prototype.writeFeatureElement = + function(node, feature, objectStack) { var fid = feature.getId(); if (goog.isDef(fid)) { node.setAttribute('fid', fid); @@ -1541,7 +1550,8 @@ ol.format.GML.writeFeature = function(node, feature, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.writeFeatureMembers_ = function(node, features, objectStack) { +ol.format.GML.prototype.writeFeatureMembers_ = + function(node, features, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var featureType = goog.object.get(context, 'featureType'); @@ -1660,7 +1670,7 @@ ol.format.GML.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = { * @return {Node|undefined} Node. * @private */ -ol.format.GML.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, +ol.format.GML.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) { var parentNode = objectStack[objectStack.length - 1].node; goog.asserts.assert(ol.xml.isNode(parentNode)); @@ -1677,7 +1687,7 @@ ol.format.GML.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, * @return {Node|undefined} Node. * @private */ -ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, +ol.format.GML.prototype.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); From c49891dcce8bf04bd5341f558aa6ca1b29980079 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 11:06:08 +0200 Subject: [PATCH 03/31] Call inner methods from 'this' object --- src/ol/format/gml/base.js | 51 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index 2d84131e0d..0e0f4078b1 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -205,7 +205,7 @@ ol.format.GML.prototype.readFeature_ = function(node, objectStack) { values[ol.xml.getLocalName(n)] = value; } else { geometryName = ol.xml.getLocalName(n); - values[geometryName] = ol.format.GML.readGeometry(n, objectStack); + values[geometryName] = this.readGeometryElement(n, objectStack); } } var feature = new ol.Feature(values); @@ -229,7 +229,7 @@ ol.format.GML.prototype.readPoint_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Point'); var flatCoordinates = - ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack); + this.readFlatCoordinatesFromNode_(node, objectStack); if (goog.isDefAndNotNull(flatCoordinates)) { var point = new ol.geom.Point(null); goog.asserts.assert(flatCoordinates.length == 3); @@ -422,7 +422,7 @@ ol.format.GML.prototype.readLineString_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LineString'); var flatCoordinates = - ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack); + this.readFlatCoordinatesFromNode_(node, objectStack); if (goog.isDefAndNotNull(flatCoordinates)) { var lineString = new ol.geom.LineString(null); lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates); @@ -564,7 +564,7 @@ ol.format.GML.prototype.readLinearRing_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var flatCoordinates = - ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack); + this.readFlatCoordinatesFromNode_(node, objectStack); if (goog.isDef(flatCoordinates)) { var ring = new ol.geom.LinearRing(null); ring.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates); @@ -1050,7 +1050,7 @@ ol.format.GML.RING_PARSERS_ = { * @inheritDoc */ ol.format.GML.prototype.readGeometryFromNode = function(node, opt_options) { - var geometry = ol.format.GML.readGeometry(node, + var geometry = this.readGeometryElement(node, [this.getReadOptions(node, goog.isDef(opt_options) ? opt_options : {})]); return (goog.isDef(geometry) ? geometry : null); }; @@ -1079,7 +1079,7 @@ ol.format.GML.prototype.readFeaturesFromNode = function(node, opt_options) { if (goog.isDef(opt_options)) { goog.object.extend(options, this.getReadOptions(node, opt_options)); } - return ol.format.GML.readFeatures_(node, [options]); + return this.readFeatures_(node, [options]); }; @@ -1152,7 +1152,7 @@ ol.format.GML.prototype.writePosList_ = function(node, value, objectStack) { var point; for (var i = 0; i < len; ++i) { point = points[i]; - parts[i] = ol.format.GML.getCoords_(point, srsName); + parts[i] = this.getCoords_(point, srsName); } ol.format.XSD.writeStringTextNode(node, parts.join(' ')); }; @@ -1173,7 +1173,7 @@ ol.format.GML.prototype.writePoint_ = function(node, geometry, objectStack) { } var pos = ol.xml.createElementNS(node.namespaceURI, 'pos'); node.appendChild(pos); - ol.format.GML.writePos_(pos, geometry, objectStack); + this.writePos_(pos, geometry, objectStack); }; @@ -1228,7 +1228,7 @@ ol.format.GML.prototype.writeLinearRing_ = } var posList = ol.xml.createElementNS(node.namespaceURI, 'posList'); node.appendChild(posList); - ol.format.GML.writePosList_(posList, geometry, objectStack); + this.writePosList_(posList, geometry, objectStack); }; @@ -1276,7 +1276,8 @@ ol.format.GML.prototype.writeSurfaceOrPolygon_ = } else if (node.nodeName === 'Surface') { var patches = ol.xml.createElementNS(node.namespaceURI, 'patches'); node.appendChild(patches); - ol.format.GML.writeSurfacePatches_(patches, geometry, objectStack); + this.writeSurfacePatches_( + patches, geometry, objectStack); } }; @@ -1298,11 +1299,12 @@ ol.format.GML.prototype.writeCurveOrLineString_ = if (node.nodeName === 'LineString' || node.nodeName === 'LineStringSegment') { var posList = ol.xml.createElementNS(node.namespaceURI, 'posList'); node.appendChild(posList); - ol.format.GML.writePosList_(posList, geometry, objectStack); + this.writePosList_(posList, geometry, objectStack); } else if (node.nodeName === 'Curve') { var segments = ol.xml.createElementNS(node.namespaceURI, 'segments'); node.appendChild(segments); - ol.format.GML.writeCurveSegments_(segments, geometry, objectStack); + this.writeCurveSegments_(segments, + geometry, objectStack); } }; @@ -1384,7 +1386,7 @@ ol.format.GML.prototype.writeMultiCurveOrLineString_ = function(node, geometry, ol.format.GML.prototype.writeRing_ = function(node, ring, objectStack) { var linearRing = ol.xml.createElementNS(node.namespaceURI, 'LinearRing'); node.appendChild(linearRing); - ol.format.GML.writeLinearRing_(linearRing, ring, objectStack); + this.writeLinearRing_(linearRing, ring, objectStack); }; @@ -1398,10 +1400,11 @@ ol.format.GML.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); - var child = ol.format.GML.GEOMETRY_NODE_FACTORY_(polygon, objectStack); + var child = this.GEOMETRY_NODE_FACTORY_( + polygon, objectStack); if (goog.isDef(child)) { node.appendChild(child); - ol.format.GML.writeSurfaceOrPolygon_(child, polygon, objectStack); + this.writeSurfaceOrPolygon_(child, polygon, objectStack); } }; @@ -1415,7 +1418,7 @@ ol.format.GML.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, ol.format.GML.prototype.writePointMember_ = function(node, point, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'Point'); node.appendChild(child); - ol.format.GML.writePoint_(child, point, objectStack); + this.writePoint_(child, point, objectStack); }; @@ -1429,10 +1432,10 @@ ol.format.GML.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); - var child = ol.format.GML.GEOMETRY_NODE_FACTORY_(line, objectStack); + var child = this.GEOMETRY_NODE_FACTORY_(line, objectStack); if (goog.isDef(child)) { node.appendChild(child); - ol.format.GML.writeCurveOrLineString_(child, line, objectStack); + this.writeCurveOrLineString_(child, line, objectStack); } }; @@ -1447,7 +1450,7 @@ ol.format.GML.prototype.writeSurfacePatches_ = function(node, polygon, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'PolygonPatch'); node.appendChild(child); - ol.format.GML.writeSurfaceOrPolygon_(child, polygon, objectStack); + this.writeSurfaceOrPolygon_(child, polygon, objectStack); }; @@ -1461,7 +1464,7 @@ ol.format.GML.prototype.writeCurveSegments_ = function(node, line, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'LineStringSegment'); node.appendChild(child); - ol.format.GML.writeCurveOrLineString_(child, line, objectStack); + this.writeCurveOrLineString_(child, line, objectStack); }; @@ -1524,7 +1527,7 @@ ol.format.GML.prototype.writeFeatureElement = if (key == geometryName) { if (!(key in context.serializers[featureNS])) { context.serializers[featureNS][key] = ol.xml.makeChildAppender( - ol.format.GML.writeGeometry); + this.writeGeometryElement, this); } } else { if (!(key in context.serializers[featureNS])) { @@ -1559,7 +1562,7 @@ ol.format.GML.prototype.writeFeatureMembers_ = var serializers = {}; serializers[featureNS] = {}; serializers[featureNS][featureType] = ol.xml.makeChildAppender( - ol.format.GML.writeFeature); + this.writeFeatureElement, this); var item = goog.object.clone(context); item.node = node; ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ @@ -1729,7 +1732,7 @@ ol.format.GML.prototype.writeGeometryNode = function(geometry, opt_options) { if (goog.isDef(opt_options)) { goog.object.extend(context, opt_options); } - ol.format.GML.writeGeometry(geom, geometry, [context]); + this.writeGeometryElement(geom, geometry, [context]); return geom; }; @@ -1766,6 +1769,6 @@ ol.format.GML.prototype.writeFeaturesNode = function(features, opt_options) { if (goog.isDef(opt_options)) { goog.object.extend(context, opt_options); } - ol.format.GML.writeFeatureMembers_(node, features, [context]); + this.writeFeatureMembers_(node, features, [context]); return node; }; From 5884f7343a90b9daac14749f8debaa8a181a4f40 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 11:35:21 +0200 Subject: [PATCH 04/31] Call method in ol.format.GML.prototype from ol.format.GML static objects --- src/ol/format/gml/base.js | 140 +++++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 61 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index 0e0f4078b1..f156775d49 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -153,8 +153,9 @@ ol.format.GML.prototype.readFeatures_ = function(node, objectStack) { */ ol.format.GML.FEATURE_COLLECTION_PARSERS = { 'http://www.opengis.net/gml': { - 'featureMember': ol.xml.makeArrayPusher(ol.format.GML.readFeatures_), - 'featureMembers': ol.xml.makeReplacer(ol.format.GML.readFeatures_) + 'featureMember': ol.xml.makeArrayPusher( + ol.format.GML.prototype.readFeatures_), + 'featureMembers': ol.xml.makeReplacer(ol.format.GML.prototype.readFeatures_) } }; @@ -791,19 +792,23 @@ ol.format.GML.prototype.readFlatPosList_ = function(node, objectStack) { */ ol.format.GML.GEOMETRY_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'Point': ol.xml.makeReplacer(ol.format.GML.readPoint_), - 'MultiPoint': ol.xml.makeReplacer(ol.format.GML.readMultiPoint_), - 'LineString': ol.xml.makeReplacer(ol.format.GML.readLineString_), + 'Point': ol.xml.makeReplacer(ol.format.GML.prototype.readPoint_), + 'MultiPoint': ol.xml.makeReplacer(ol.format.GML.prototype.readMultiPoint_), + 'LineString': ol.xml.makeReplacer(ol.format.GML.prototype.readLineString_), 'MultiLineString': ol.xml.makeReplacer( - ol.format.GML.readMultiLineString_), - 'LinearRing' : ol.xml.makeReplacer(ol.format.GML.readLinearRing_), - 'Polygon': ol.xml.makeReplacer(ol.format.GML.readPolygon_), - 'MultiPolygon': ol.xml.makeReplacer(ol.format.GML.readMultiPolygon_), - 'Surface': ol.xml.makeReplacer(ol.format.GML.readSurface_), - 'MultiSurface': ol.xml.makeReplacer(ol.format.GML.readMultiSurface_), - 'Curve': ol.xml.makeReplacer(ol.format.GML.readCurve_), - 'MultiCurve': ol.xml.makeReplacer(ol.format.GML.readMultiCurve_), - 'Envelope': ol.xml.makeReplacer(ol.format.GML.readEnvelope_) + ol.format.GML.prototype.readMultiLineString_), + 'LinearRing' : ol.xml.makeReplacer( + ol.format.GML.prototype.readLinearRing_), + 'Polygon': ol.xml.makeReplacer(ol.format.GML.prototype.readPolygon_), + 'MultiPolygon': ol.xml.makeReplacer( + ol.format.GML.prototype.readMultiPolygon_), + 'Surface': ol.xml.makeReplacer(ol.format.GML.prototype.readSurface_), + 'MultiSurface': ol.xml.makeReplacer( + ol.format.GML.prototype.readMultiSurface_), + 'Curve': ol.xml.makeReplacer(ol.format.GML.prototype.readCurve_), + 'MultiCurve': ol.xml.makeReplacer( + ol.format.GML.prototype.readMultiCurve_), + 'Envelope': ol.xml.makeReplacer(ol.format.GML.prototype.readEnvelope_) } }; @@ -815,8 +820,8 @@ ol.format.GML.GEOMETRY_PARSERS_ = { */ ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'pos': ol.xml.makeReplacer(ol.format.GML.readFlatPos_), - 'posList': ol.xml.makeReplacer(ol.format.GML.readFlatPosList_) + 'pos': ol.xml.makeReplacer(ol.format.GML.prototype.readFlatPos_), + 'posList': ol.xml.makeReplacer(ol.format.GML.prototype.readFlatPosList_) } }; @@ -828,8 +833,8 @@ ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { */ ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'interior': ol.format.GML.interiorParser_, - 'exterior': ol.format.GML.exteriorParser_ + 'interior': ol.format.GML.prototype.interiorParser_, + 'exterior': ol.format.GML.prototype.exteriorParser_ } }; @@ -841,8 +846,10 @@ ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_ = { */ ol.format.GML.MULTIPOINT_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'pointMember': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_), - 'pointMembers': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_) + 'pointMember': ol.xml.makeArrayPusher( + ol.format.GML.prototype.pointMemberParser_), + 'pointMembers': ol.xml.makeArrayPusher( + ol.format.GML.prototype.pointMemberParser_) } }; @@ -855,9 +862,9 @@ ol.format.GML.MULTIPOINT_PARSERS_ = { ol.format.GML.MULTILINESTRING_PARSERS_ = { 'http://www.opengis.net/gml' : { 'lineStringMember': ol.xml.makeArrayPusher( - ol.format.GML.lineStringMemberParser_), + ol.format.GML.prototype.lineStringMemberParser_), 'lineStringMembers': ol.xml.makeArrayPusher( - ol.format.GML.lineStringMemberParser_) + ol.format.GML.prototype.lineStringMemberParser_) } }; @@ -870,9 +877,9 @@ ol.format.GML.MULTILINESTRING_PARSERS_ = { ol.format.GML.MULTICURVE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'curveMember': ol.xml.makeArrayPusher( - ol.format.GML.curveMemberParser_), + ol.format.GML.prototype.curveMemberParser_), 'curveMembers': ol.xml.makeArrayPusher( - ol.format.GML.curveMemberParser_) + ol.format.GML.prototype.curveMemberParser_) } }; @@ -885,9 +892,9 @@ ol.format.GML.MULTICURVE_PARSERS_ = { ol.format.GML.MULTISURFACE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'surfaceMember': ol.xml.makeArrayPusher( - ol.format.GML.surfaceMemberParser_), + ol.format.GML.prototype.surfaceMemberParser_), 'surfaceMembers': ol.xml.makeArrayPusher( - ol.format.GML.surfaceMemberParser_) + ol.format.GML.prototype.surfaceMemberParser_) } }; @@ -900,9 +907,9 @@ ol.format.GML.MULTISURFACE_PARSERS_ = { ol.format.GML.MULTIPOLYGON_PARSERS_ = { 'http://www.opengis.net/gml' : { 'polygonMember': ol.xml.makeArrayPusher( - ol.format.GML.polygonMemberParser_), + ol.format.GML.prototype.polygonMemberParser_), 'polygonMembers': ol.xml.makeArrayPusher( - ol.format.GML.polygonMemberParser_) + ol.format.GML.prototype.polygonMemberParser_) } }; @@ -915,7 +922,7 @@ ol.format.GML.MULTIPOLYGON_PARSERS_ = { ol.format.GML.POINTMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeArrayPusher( - ol.format.GML.readFlatCoordinatesFromNode_) + ol.format.GML.prototype.readFlatCoordinatesFromNode_) } }; @@ -928,7 +935,7 @@ ol.format.GML.POINTMEMBER_PARSERS_ = { ol.format.GML.LINESTRINGMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( - ol.format.GML.readLineString_) + ol.format.GML.prototype.readLineString_) } }; @@ -940,8 +947,9 @@ ol.format.GML.LINESTRINGMEMBER_PARSERS_ = { */ ol.format.GML.CURVEMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'LineString': ol.xml.makeArrayPusher(ol.format.GML.readLineString_), - 'Curve': ol.xml.makeArrayPusher(ol.format.GML.readCurve_) + 'LineString': ol.xml.makeArrayPusher( + ol.format.GML.prototype.readLineString_), + 'Curve': ol.xml.makeArrayPusher(ol.format.GML.prototype.readCurve_) } }; @@ -953,8 +961,8 @@ ol.format.GML.CURVEMEMBER_PARSERS_ = { */ ol.format.GML.SURFACEMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_), - 'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_) + 'Polygon': ol.xml.makeArrayPusher(ol.format.GML.prototype.readPolygon_), + 'Surface': ol.xml.makeArrayPusher(ol.format.GML.prototype.readSurface_) } }; @@ -967,7 +975,7 @@ ol.format.GML.SURFACEMEMBER_PARSERS_ = { ol.format.GML.POLYGONMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Polygon': ol.xml.makeArrayPusher( - ol.format.GML.readPolygon_) + ol.format.GML.prototype.readPolygon_) } }; @@ -979,7 +987,7 @@ ol.format.GML.POLYGONMEMBER_PARSERS_ = { */ ol.format.GML.SURFACE_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'patches': ol.xml.makeReplacer(ol.format.GML.readPatch_) + 'patches': ol.xml.makeReplacer(ol.format.GML.prototype.readPatch_) } }; @@ -991,7 +999,7 @@ ol.format.GML.SURFACE_PARSERS_ = { */ ol.format.GML.CURVE_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'segments': ol.xml.makeReplacer(ol.format.GML.readSegment_) + 'segments': ol.xml.makeReplacer(ol.format.GML.prototype.readSegment_) } }; @@ -1003,8 +1011,10 @@ ol.format.GML.CURVE_PARSERS_ = { */ ol.format.GML.ENVELOPE_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'lowerCorner': ol.xml.makeArrayPusher(ol.format.GML.readFlatPosList_), - 'upperCorner': ol.xml.makeArrayPusher(ol.format.GML.readFlatPosList_) + 'lowerCorner': ol.xml.makeArrayPusher( + ol.format.GML.prototype.readFlatPosList_), + 'upperCorner': ol.xml.makeArrayPusher( + ol.format.GML.prototype.readFlatPosList_) } }; @@ -1016,7 +1026,8 @@ ol.format.GML.ENVELOPE_PARSERS_ = { */ ol.format.GML.PATCHES_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'PolygonPatch': ol.xml.makeReplacer(ol.format.GML.readPolygonPatch_) + 'PolygonPatch': ol.xml.makeReplacer( + ol.format.GML.prototype.readPolygonPatch_) } }; @@ -1029,7 +1040,7 @@ ol.format.GML.PATCHES_PARSERS_ = { ol.format.GML.SEGMENTS_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineStringSegment': ol.xml.makeReplacer( - ol.format.GML.readLineStringSegment_) + ol.format.GML.prototype.readLineStringSegment_) } }; @@ -1041,7 +1052,8 @@ ol.format.GML.SEGMENTS_PARSERS_ = { */ ol.format.GML.RING_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'LinearRing': ol.xml.makeReplacer(ol.format.GML.readFlatLinearRing_) + 'LinearRing': ol.xml.makeReplacer( + ol.format.GML.prototype.readFlatLinearRing_) } }; @@ -1580,9 +1592,9 @@ ol.format.GML.prototype.writeFeatureMembers_ = ol.format.GML.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = { 'http://www.opengis.net/gml': { 'surfaceMember': ol.xml.makeChildAppender( - ol.format.GML.writeSurfaceOrPolygonMember_), + ol.format.GML.prototype.writeSurfaceOrPolygonMember_), 'polygonMember': ol.xml.makeChildAppender( - ol.format.GML.writeSurfaceOrPolygonMember_) + ol.format.GML.prototype.writeSurfaceOrPolygonMember_) } }; @@ -1593,7 +1605,8 @@ ol.format.GML.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = { */ ol.format.GML.POINTMEMBER_SERIALIZERS_ = { 'http://www.opengis.net/gml': { - 'pointMember': ol.xml.makeChildAppender(ol.format.GML.writePointMember_) + 'pointMember': ol.xml.makeChildAppender( + ol.format.GML.prototype.writePointMember_) } }; @@ -1605,9 +1618,9 @@ ol.format.GML.POINTMEMBER_SERIALIZERS_ = { ol.format.GML.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = { 'http://www.opengis.net/gml': { 'lineStringMember': ol.xml.makeChildAppender( - ol.format.GML.writeLineStringOrCurveMember_), + ol.format.GML.prototype.writeLineStringOrCurveMember_), 'curveMember': ol.xml.makeChildAppender( - ol.format.GML.writeLineStringOrCurveMember_) + ol.format.GML.prototype.writeLineStringOrCurveMember_) } }; @@ -1618,8 +1631,8 @@ ol.format.GML.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = { */ ol.format.GML.RING_SERIALIZERS_ = { 'http://www.opengis.net/gml': { - 'exterior': ol.xml.makeChildAppender(ol.format.GML.writeRing_), - 'interior': ol.xml.makeChildAppender(ol.format.GML.writeRing_) + 'exterior': ol.xml.makeChildAppender(ol.format.GML.prototype.writeRing_), + 'interior': ol.xml.makeChildAppender(ol.format.GML.prototype.writeRing_) } }; @@ -1630,24 +1643,29 @@ ol.format.GML.RING_SERIALIZERS_ = { */ ol.format.GML.GEOMETRY_SERIALIZERS_ = { 'http://www.opengis.net/gml': { - 'Curve': ol.xml.makeChildAppender(ol.format.GML.writeCurveOrLineString_), + 'Curve': ol.xml.makeChildAppender( + ol.format.GML.prototype.writeCurveOrLineString_), 'MultiCurve': ol.xml.makeChildAppender( - ol.format.GML.writeMultiCurveOrLineString_), - 'Point': ol.xml.makeChildAppender(ol.format.GML.writePoint_), - 'MultiPoint': ol.xml.makeChildAppender(ol.format.GML.writeMultiPoint_), + ol.format.GML.prototype.writeMultiCurveOrLineString_), + 'Point': ol.xml.makeChildAppender(ol.format.GML.prototype.writePoint_), + 'MultiPoint': ol.xml.makeChildAppender( + ol.format.GML.prototype.writeMultiPoint_), 'LineString': ol.xml.makeChildAppender( - ol.format.GML.writeCurveOrLineString_), + ol.format.GML.prototype.writeCurveOrLineString_), 'MultiLineString': ol.xml.makeChildAppender( - ol.format.GML.writeMultiCurveOrLineString_), - 'LinearRing': ol.xml.makeChildAppender(ol.format.GML.writeLinearRing_), - 'Polygon': ol.xml.makeChildAppender(ol.format.GML.writeSurfaceOrPolygon_), + ol.format.GML.prototype.writeMultiCurveOrLineString_), + 'LinearRing': ol.xml.makeChildAppender( + ol.format.GML.prototype.writeLinearRing_), + 'Polygon': ol.xml.makeChildAppender( + ol.format.GML.prototype.writeSurfaceOrPolygon_), 'MultiPolygon': ol.xml.makeChildAppender( - ol.format.GML.writeMultiSurfaceOrPolygon_), - 'Surface': ol.xml.makeChildAppender(ol.format.GML.writeSurfaceOrPolygon_), + ol.format.GML.prototype.writeMultiSurfaceOrPolygon_), + 'Surface': ol.xml.makeChildAppender( + ol.format.GML.prototype.writeSurfaceOrPolygon_), 'MultiSurface': ol.xml.makeChildAppender( - ol.format.GML.writeMultiSurfaceOrPolygon_), + ol.format.GML.prototype.writeMultiSurfaceOrPolygon_), 'Envelope': ol.xml.makeChildAppender( - ol.format.GML.writeEnvelope) + ol.format.GML.prototype.writeEnvelope) } }; From 4aad872d71a972bf5a8d0b09971488059baf3f6a Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 11:37:56 +0200 Subject: [PATCH 05/31] Send ol.format.GML instance reference to ol.xml static methods --- src/ol/format/gml/base.js | 69 +++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index f156775d49..ef5222a40c 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -122,7 +122,8 @@ ol.format.GML.prototype.readFeatures_ = function(node, objectStack) { var features; if (localName == 'FeatureCollection') { features = ol.xml.pushParseAndPop(null, - ol.format.GML.FEATURE_COLLECTION_PARSERS, node, objectStack); + ol.format.GML.FEATURE_COLLECTION_PARSERS, node, + objectStack, this); } else if (localName == 'featureMembers' || localName == 'featureMember') { var context = objectStack[0]; goog.asserts.assert(goog.isObject(context)); @@ -136,8 +137,8 @@ ol.format.GML.prototype.readFeatures_ = function(node, objectStack) { var parsers = {}; var parsersNS = {}; parsers[featureType] = (localName == 'featureMembers') ? - ol.xml.makeArrayPusher(ol.format.GML.readFeature_) : - ol.xml.makeReplacer(ol.format.GML.readFeature_); + ol.xml.makeArrayPusher(this.readFeature_, this) : + ol.xml.makeReplacer(this.readFeature_, this); parsersNS[goog.object.get(context, 'featureNS')] = parsers; features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack); } @@ -171,7 +172,7 @@ ol.format.GML.prototype.readGeometryElement = function(node, objectStack) { goog.object.set(context, 'srsName', node.firstElementChild.getAttribute('srsName')); var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null), - ol.format.GML.GEOMETRY_PARSERS_, node, objectStack); + ol.format.GML.GEOMETRY_PARSERS_, node, objectStack, this); if (goog.isDefAndNotNull(geometry)) { return /** @type {ol.geom.Geometry} */ ( ol.format.Feature.transformWithOptions(geometry, false, context)); @@ -251,7 +252,7 @@ ol.format.GML.prototype.readMultiPoint_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiPoint'); var coordinates = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([]), - ol.format.GML.MULTIPOINT_PARSERS_, node, objectStack); + ol.format.GML.MULTIPOINT_PARSERS_, node, objectStack, this); if (goog.isDef(coordinates)) { return new ol.geom.MultiPoint(coordinates); } else { @@ -271,7 +272,7 @@ ol.format.GML.prototype.readMultiLineString_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiLineString'); var lineStrings = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.MULTILINESTRING_PARSERS_, node, objectStack); + ol.format.GML.MULTILINESTRING_PARSERS_, node, objectStack, this); if (goog.isDef(lineStrings)) { var multiLineString = new ol.geom.MultiLineString(null); multiLineString.setLineStrings(lineStrings); @@ -293,7 +294,7 @@ ol.format.GML.prototype.readMultiCurve_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiCurve'); var lineStrings = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.MULTICURVE_PARSERS_, node, objectStack); + ol.format.GML.MULTICURVE_PARSERS_, node, objectStack, this); if (goog.isDef(lineStrings)) { var multiLineString = new ol.geom.MultiLineString(null); multiLineString.setLineStrings(lineStrings); @@ -315,7 +316,7 @@ ol.format.GML.prototype.readMultiSurface_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiSurface'); var polygons = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.MULTISURFACE_PARSERS_, node, objectStack); + ol.format.GML.MULTISURFACE_PARSERS_, node, objectStack, this); if (goog.isDef(polygons)) { var multiPolygon = new ol.geom.MultiPolygon(null); multiPolygon.setPolygons(polygons); @@ -337,7 +338,7 @@ ol.format.GML.prototype.readMultiPolygon_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiPolygon'); var polygons = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.MULTIPOLYGON_PARSERS_, node, objectStack); + ol.format.GML.MULTIPOLYGON_PARSERS_, node, objectStack, this); if (goog.isDef(polygons)) { var multiPolygon = new ol.geom.MultiPolygon(null); multiPolygon.setPolygons(polygons); @@ -357,7 +358,7 @@ ol.format.GML.prototype.pointMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'pointMember' || node.localName == 'pointMembers'); - ol.xml.parse(ol.format.GML.POINTMEMBER_PARSERS_, node, objectStack); + ol.xml.parse(ol.format.GML.POINTMEMBER_PARSERS_, node, objectStack, this); }; @@ -370,7 +371,8 @@ ol.format.GML.prototype.lineStringMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'lineStringMember' || node.localName == 'lineStringMembers'); - ol.xml.parse(ol.format.GML.LINESTRINGMEMBER_PARSERS_, node, objectStack); + ol.xml.parse(ol.format.GML.LINESTRINGMEMBER_PARSERS_, + node, objectStack, this); }; @@ -383,7 +385,7 @@ ol.format.GML.prototype.curveMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'curveMember' || node.localName == 'curveMembers'); - ol.xml.parse(ol.format.GML.CURVEMEMBER_PARSERS_, node, objectStack); + ol.xml.parse(ol.format.GML.CURVEMEMBER_PARSERS_, node, objectStack, this); }; @@ -396,7 +398,7 @@ ol.format.GML.prototype.surfaceMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'surfaceMember' || node.localName == 'surfaceMembers'); - ol.xml.parse(ol.format.GML.SURFACEMEMBER_PARSERS_, node, objectStack); + ol.xml.parse(ol.format.GML.SURFACEMEMBER_PARSERS_, node, objectStack, this); }; @@ -409,7 +411,7 @@ ol.format.GML.prototype.polygonMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'polygonMember' || node.localName == 'polygonMembers'); - ol.xml.parse(ol.format.GML.POLYGONMEMBER_PARSERS_, node, objectStack); + ol.xml.parse(ol.format.GML.POLYGONMEMBER_PARSERS_, node, objectStack, this); }; @@ -445,7 +447,7 @@ ol.format.GML.prototype.readPatch_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'patches'); return ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML.PATCHES_PARSERS_, node, objectStack); + ol.format.GML.PATCHES_PARSERS_, node, objectStack, this); }; @@ -460,7 +462,7 @@ ol.format.GML.prototype.readSegment_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'segments'); return ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML.SEGMENTS_PARSERS_, node, objectStack); + ol.format.GML.SEGMENTS_PARSERS_, node, objectStack, this); }; @@ -475,7 +477,7 @@ ol.format.GML.prototype.readPolygonPatch_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'PolygonPatch'); return ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack); + ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); }; @@ -490,7 +492,8 @@ ol.format.GML.prototype.readLineStringSegment_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'LineStringSegment'); return ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack); + ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_, + node, objectStack, this); }; @@ -504,7 +507,7 @@ ol.format.GML.prototype.interiorParser_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'interior'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS_, node, objectStack); + ol.format.GML.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -525,7 +528,7 @@ ol.format.GML.prototype.exteriorParser_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'exterior'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS_, node, objectStack); + ol.format.GML.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -618,7 +621,7 @@ ol.format.GML.prototype.readSurface_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'Surface'); var flatLinearRings = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML.SURFACE_PARSERS_, node, objectStack); + ol.format.GML.SURFACE_PARSERS_, node, objectStack, this); if (goog.isDef(flatLinearRings) && !goog.isNull(flatLinearRings[0])) { var polygon = new ol.geom.Polygon(null); @@ -649,7 +652,7 @@ ol.format.GML.prototype.readCurve_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'Curve'); var flatCoordinates = ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML.CURVE_PARSERS_, node, objectStack); + ol.format.GML.CURVE_PARSERS_, node, objectStack, this); if (goog.isDef(flatCoordinates)) { var lineString = new ol.geom.LineString(null); lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates); @@ -671,7 +674,7 @@ ol.format.GML.prototype.readEnvelope_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'Envelope'); var flatCoordinates = ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML.ENVELOPE_PARSERS_, node, objectStack); + ol.format.GML.ENVELOPE_PARSERS_, node, objectStack, this); return ol.extent.createOrUpdate(flatCoordinates[1][0], flatCoordinates[1][1], flatCoordinates[2][0], flatCoordinates[2][1]); @@ -1220,7 +1223,7 @@ ol.format.GML.prototype.writeEnvelope = function(node, extent, objectStack) { ({node: node}), ol.format.GML.ENVELOPE_SERIALIZERS_, ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, - objectStack, keys); + objectStack, keys, this); }; @@ -1283,8 +1286,9 @@ ol.format.GML.prototype.writeSurfaceOrPolygon_ = var rings = geometry.getLinearRings(); ol.xml.pushSerializeAndPop( {node: node, srsName: srsName}, - ol.format.GML.RING_SERIALIZERS_, ol.format.GML.RING_NODE_FACTORY_, - rings, objectStack); + ol.format.GML.RING_SERIALIZERS_, + this.RING_NODE_FACTORY_, + rings, objectStack, undefined, this); } else if (node.nodeName === 'Surface') { var patches = ol.xml.createElementNS(node.namespaceURI, 'patches'); node.appendChild(patches); @@ -1339,8 +1343,8 @@ ol.format.GML.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, var polygons = geometry.getPolygons(); ol.xml.pushSerializeAndPop({node: node, srsName: srsName, surface: surface}, ol.format.GML.SURFACEORPOLYGONMEMBER_SERIALIZERS_, - ol.format.GML.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons, - objectStack); + this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons, + objectStack, undefined, this); }; @@ -1362,7 +1366,7 @@ ol.format.GML.prototype.writeMultiPoint_ = function(node, geometry, ol.xml.pushSerializeAndPop({node: node, srsName: srsName}, ol.format.GML.POINTMEMBER_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('pointMember'), points, - objectStack); + objectStack, undefined, this); }; @@ -1384,8 +1388,8 @@ ol.format.GML.prototype.writeMultiCurveOrLineString_ = function(node, geometry, var lines = geometry.getLineStrings(); ol.xml.pushSerializeAndPop({node: node, srsName: srsName, curve: curve}, ol.format.GML.LINESTRINGORCURVEMEMBER_SERIALIZERS_, - ol.format.GML.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines, - objectStack); + this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines, + objectStack, undefined, this); }; @@ -1506,7 +1510,8 @@ ol.format.GML.prototype.writeGeometryElement = } ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ (item), ol.format.GML.GEOMETRY_SERIALIZERS_, - ol.format.GML.GEOMETRY_NODE_FACTORY_, [value], objectStack); + this.GEOMETRY_NODE_FACTORY_, [value], + objectStack, undefined, this); }; From b8e5ffaf31d100746ce3ebfbc8e168e5ae612243 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 11:49:02 +0200 Subject: [PATCH 06/31] Use current scope on remote methods call if arg opt_this is undefined --- src/ol/xml.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index be03cdda9a..6c8e0d4da5 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -379,7 +379,8 @@ ol.xml.makeArrayPusher = function(valueReader, opt_this) { * @param {Array.<*>} objectStack Object stack. */ function(node, objectStack) { - var value = valueReader.call(opt_this, node, objectStack); + var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this, + node, objectStack); if (goog.isDef(value)) { var array = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isArray(array)); @@ -402,7 +403,8 @@ ol.xml.makeReplacer = function(valueReader, opt_this) { * @param {Array.<*>} objectStack Object stack. */ function(node, objectStack) { - var value = valueReader.call(opt_this, node, objectStack); + var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this, + node, objectStack); if (goog.isDef(value)) { objectStack[objectStack.length - 1] = value; } @@ -426,7 +428,8 @@ ol.xml.makeObjectPropertyPusher = * @param {Array.<*>} objectStack Object stack. */ function(node, objectStack) { - var value = valueReader.call(opt_this, node, objectStack); + var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this, + node, objectStack); if (goog.isDef(value)) { var object = /** @type {Object} */ (objectStack[objectStack.length - 1]); @@ -456,7 +459,8 @@ ol.xml.makeObjectPropertySetter = * @param {Array.<*>} objectStack Object stack. */ function(node, objectStack) { - var value = valueReader.call(opt_this, node, objectStack); + var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this, + node, objectStack); if (goog.isDef(value)) { var object = /** @type {Object} */ (objectStack[objectStack.length - 1]); @@ -494,7 +498,8 @@ ol.xml.makeParsersNS = function(namespaceURIs, parsers, opt_parsersNS) { */ ol.xml.makeChildAppender = function(nodeWriter, opt_this) { return function(node, value, objectStack) { - nodeWriter.call(opt_this, node, value, objectStack); + nodeWriter.call(goog.isDef(opt_this) ? opt_this : this, + node, value, objectStack); var parent = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(parent)); var parentNode = parent.node; From 8b38367e2b12093f667f521b60df205af8d3edeb Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 12:14:44 +0200 Subject: [PATCH 07/31] Add subclass for version ol.format.GML.v2 --- src/ol/format/gml/v2.js | 152 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/ol/format/gml/v2.js diff --git a/src/ol/format/gml/v2.js b/src/ol/format/gml/v2.js new file mode 100644 index 0000000000..742d74ef30 --- /dev/null +++ b/src/ol/format/gml/v2.js @@ -0,0 +1,152 @@ +goog.provide('ol.format.GML.v2'); + +goog.require('goog.asserts'); +goog.require('goog.dom'); +goog.require('goog.dom.NodeType'); +goog.require('goog.object'); +goog.require('ol.format.GML'); +goog.require('ol.format.XSD'); +goog.require('ol.proj'); +goog.require('ol.xml'); + + + +/** + * @classdesc + * Feature format for reading and writing data in the GML format, + * version 2.1.2. + * + * @constructor + * @param {olx.format.GMLOptions=} opt_options + * Optional configuration object. + * @extends {ol.format.GML} + * @api stable + */ +ol.format.GML.v2 = function(opt_options) { + + goog.base(this); +}; +goog.inherits(ol.format.GML.v2, ol.format.GML); + + +/** + * @protected + * @type {string} + */ +ol.format.GML.v2.schemaLocation_ = 'http://www.opengis.net/gml ' + + 'http://schemas.opengis.net/gml/2.1.2/feature.xsd'; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {Array.|undefined} Flat coordinates. + */ +ol.format.GML.v2.prototype.readFlatCoordinates_ = function(node, objectStack) { + var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, ''); + var context = objectStack[0]; + goog.asserts.assert(goog.isObject(context)); + var containerSrs = goog.object.get(context, 'srsName'); + var containerDimension = node.parentNode.getAttribute('srsDimension'); + var axisOrientation = 'enu'; + if (!goog.isNull(containerSrs)) { + var proj = ol.proj.get(containerSrs); + axisOrientation = proj.getAxisOrientation(); + } + var coords = s.split(/[\s,]+/); + // The "dimension" attribute is from the GML 3.0.1 spec. + var dim = 2; + if (!goog.isNull(node.getAttribute('srsDimension'))) { + dim = ol.format.XSD.readNonNegativeIntegerString( + node.getAttribute('srsDimension')); + } else if (!goog.isNull(node.getAttribute('dimension'))) { + dim = ol.format.XSD.readNonNegativeIntegerString( + node.getAttribute('dimension')); + } else if (!goog.isNull(containerDimension)) { + dim = ol.format.XSD.readNonNegativeIntegerString(containerDimension); + } + var x, y, z; + var flatCoordinates = []; + for (var i = 0, ii = coords.length; i < ii; i += dim) { + x = parseFloat(coords[i]); + y = parseFloat(coords[i + 1]); + z = (dim === 3) ? parseFloat(coords[i + 2]) : 0; + if (axisOrientation.substr(0, 2) === 'en') { + flatCoordinates.push(x, y, z); + } else { + flatCoordinates.push(y, x, z); + } + } + return flatCoordinates; +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GML.v2.prototype.innerBoundaryIsParser_ = + function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'innerBoundaryIs'); + var flatLinearRing = ol.xml.pushParseAndPop( + /** @type {Array.|undefined} */ (undefined), + ol.format.GML.RING_PARSERS, node, objectStack, this); + if (goog.isDef(flatLinearRing)) { + var flatLinearRings = /** @type {Array.>} */ + (objectStack[objectStack.length - 1]); + goog.asserts.assert(goog.isArray(flatLinearRings)); + goog.asserts.assert(flatLinearRings.length > 0); + flatLinearRings.push(flatLinearRing); + } +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GML.v2.prototype.outerBoundaryIsParser_ = + function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'outerBoundaryIs'); + var flatLinearRing = ol.xml.pushParseAndPop( + /** @type {Array.|undefined} */ (undefined), + ol.format.GML.RING_PARSERS, node, objectStack, this); + if (goog.isDef(flatLinearRing)) { + var flatLinearRings = /** @type {Array.>} */ + (objectStack[objectStack.length - 1]); + goog.asserts.assert(goog.isArray(flatLinearRings)); + goog.asserts.assert(flatLinearRings.length > 0); + flatLinearRings[0] = flatLinearRing; + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v2.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'coordinates': ol.xml.makeReplacer( + ol.format.GML.v2.prototype.readFlatCoordinates_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v2.FLAT_LINEAR_RINGS_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'innerBoundaryIs': ol.format.GML.v2.prototype.innerBoundaryIsParser_, + 'outerBoundaryIs': ol.format.GML.v2.prototype.outerBoundaryIsParser_ + } +}; From 8efab3d4be4644c9f160e164c854d83594487649 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 12:21:45 +0200 Subject: [PATCH 08/31] Make protected some shared methods or objects --- src/ol/format/gml/base.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index ef5222a40c..ad6b7961d3 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -89,11 +89,11 @@ ol.format.GML = function(opt_options) { options.multiSurface : true; /** - * @private + * @protected * @type {string} */ - this.schemaLocation_ = goog.isDef(options.schemaLocation) ? - options.schemaLocation : ol.format.GML.schemaLocation_; + this.schemaLocation = goog.isDef(options.schemaLocation) ? + options.schemaLocation : this.constructor.schemaLocation_; goog.base(this); }; @@ -1051,9 +1051,9 @@ ol.format.GML.SEGMENTS_PARSERS_ = { /** * @const * @type {Object.>} - * @private + * @protected */ -ol.format.GML.RING_PARSERS_ = { +ol.format.GML.RING_PARSERS = { 'http://www.opengis.net/gml' : { 'LinearRing': ol.xml.makeReplacer( ol.format.GML.prototype.readFlatLinearRing_) @@ -1779,7 +1779,7 @@ ol.format.GML.prototype.writeFeaturesNode = function(features, opt_options) { var node = ol.xml.createElementNS('http://www.opengis.net/gml', 'featureMembers'); ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation', this.schemaLocation_); + 'xsi:schemaLocation', this.schemaLocation); var context = { srsName: this.srsName_, curve: this.curve_, From 074330707c208481b931504625a6b7fbb71cf537 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 12:22:39 +0200 Subject: [PATCH 09/31] Call dedicated version format methods with 'this.constructor' object --- src/ol/format/gml/base.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index ad6b7961d3..5d48a08975 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -549,7 +549,8 @@ ol.format.GML.prototype.readFlatLinearRing_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var ring = ol.xml.pushParseAndPop(/** @type {Array.} */(null), - ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack); + this.constructor.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, + objectStack, this); if (goog.isDefAndNotNull(ring)) { return ring; } else { @@ -590,7 +591,7 @@ ol.format.GML.prototype.readPolygon_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'Polygon'); var flatLinearRings = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack); + this.constructor.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); if (goog.isDef(flatLinearRings) && !goog.isNull(flatLinearRings[0])) { var polygon = new ol.geom.Polygon(null); @@ -692,7 +693,8 @@ ol.format.GML.prototype.readFlatCoordinatesFromNode_ = function(node, goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); return /** @type {Array.} */ (ol.xml.pushParseAndPop( null, - ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack)); + this.constructor.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, + objectStack, this)); }; From 13f10f6a98f83f5ccf1b07610c53cb671d47ebec Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 12:24:04 +0200 Subject: [PATCH 10/31] Change GML method call signature from WFS format --- src/ol/format/wfsformat.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 8e0d7f0468..5ab27be9cb 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -196,7 +196,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument = ol.format.WFS.FEATURE_COLLECTION_PARSERS_ = { 'http://www.opengis.net/gml': { 'boundedBy': ol.xml.makeObjectPropertySetter( - ol.format.GML.readGeometry, 'bounds') + ol.format.GML.prototype.readGeometryElement, 'bounds') } }; @@ -363,7 +363,7 @@ ol.format.WFS.writeFeature_ = function(node, feature, objectStack) { var featureNS = goog.object.get(context, 'featureNS'); var child = ol.xml.createElementNS(featureNS, featureType); node.appendChild(child); - ol.format.GML.writeFeature(child, feature, objectStack); + ol.format.GML.prototype.writeFeatureElement(child, feature, objectStack); }; @@ -457,7 +457,8 @@ ol.format.WFS.writeProperty_ = function(node, pair, objectStack) { var value = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Value'); node.appendChild(value); if (pair.value instanceof ol.geom.Geometry) { - ol.format.GML.writeGeometry(value, pair.value, objectStack); + ol.format.GML.prototype.writeGeometryElement(value, + pair.value, objectStack); } else { ol.format.XSD.writeStringTextNode(value, pair.value); } @@ -564,7 +565,7 @@ ol.format.WFS.writeOgcBBOX_ = function(node, bbox, objectStack) { var bboxNode = ol.xml.createElementNS('http://www.opengis.net/ogc', 'BBOX'); node.appendChild(bboxNode); ol.format.WFS.writeOgcPropertyName_(bboxNode, geometryName, objectStack); - ol.format.GML.writeGeometry(bboxNode, bbox, objectStack); + ol.format.GML.prototype.writeGeometryElement(bboxNode, bbox, objectStack); }; @@ -746,7 +747,7 @@ ol.format.WFS.prototype.readProjectionFromNode = function(node) { (n.childNodes.length === 1 && n.firstChild.nodeType === 3))) { var objectStack = [{}]; - ol.format.GML.readGeometry(n, objectStack); + ol.format.GML.prototype.readGeometryElement(n, objectStack); return ol.proj.get(objectStack.pop().srsName); } } From 192c7827c9de95281cfba47fa791c4f709bdc7ab Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 12:28:51 +0200 Subject: [PATCH 11/31] Add tests suite for ol.format.GML.v2 class --- test/spec/ol/format/gmlv2format.test.js | 103 ++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 test/spec/ol/format/gmlv2format.test.js diff --git a/test/spec/ol/format/gmlv2format.test.js b/test/spec/ol/format/gmlv2format.test.js new file mode 100644 index 0000000000..5ff0e64ae5 --- /dev/null +++ b/test/spec/ol/format/gmlv2format.test.js @@ -0,0 +1,103 @@ +goog.provide('ol.test.format.GML.v2'); + +var readGeometry = function(format, text, opt_options) { + var doc = ol.xml.load(text); + // we need an intermediate node for testing purposes + var node = goog.dom.createElement(goog.dom.TagName.PRE); + node.appendChild(doc.documentElement); + return format.readGeometryFromNode(node, opt_options); +}; + +describe('ol.format.GML.v2', function() { + + var format, formatWGS84, formatNoSrs; + beforeEach(function() { + format = new ol.format.GML.v2({srsName: 'CRS:84'}); + formatWGS84 = new ol.format.GML.v2({ + srsName: 'urn:x-ogc:def:crs:EPSG:4326' + }); + formatNoSrs = new ol.format.GML.v2(); + }); + + + describe('#readGeometry', function() { + + describe('gml 2.1.2', function() { + + it('can read a point geometry', function() { + var text = '' + + ' -90,-180' + + ''; + + var g = readGeometry(format, text); + expect(g).to.be.an(ol.geom.Point); + expect(g.getCoordinates()).to.eql([-180, -90, 0]); + }); + + it('can read a multipolygon with gml:coordinates', function() { + + var text = + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' -0.318987,47.003018 ' + + ' -0.768746,47.358268 ' + + ' -0.574463,47.684285 -0.347374,47.854602 ' + + ' -0.006740,47.925567 ' + + ' 0.135191,47.726864 0.149384,47.599127 0.419052,' + + ' 47.670092 0.532597,47.428810 ' + + ' 0.305508,47.443003 0.475824,47.144948 0.064225,' + + ' 47.201721 ' + + ' -0.318987,47.003018 ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' -0.035126,47.485582 -0.035126,' + + ' 47.485582 ' + + ' -0.049319,47.641706 -0.233829,47.655899 ' + + ' -0.375760,47.457196 ' + + ' -0.276408,47.286879 -0.035126,47.485582 ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + + var g = readGeometry(format, text); + expect(g).to.be.an(ol.geom.MultiPolygon); + expect(g.getCoordinates()).to.eql([ + [ + [ + [47.003018, -0.318987, 0], [47.358268, -0.768746, 0], + [47.684285, -0.574463, 0], [47.854602, -0.347374, 0], + [47.925567, -0.00674, 0], [47.726864, 0.135191, 0], + [47.599127, 0.149384, 0], [47.670092, 0.419052, 0], + [47.42881, 0.532597, 0], [47.443003, 0.305508, 0], + [47.144948, 0.475824, 0], [47.201721, 0.064225, 0], + [47.003018, -0.318987, 0] + ], + [ + [47.485582, -0.035126, 0], [47.485582, -0.035126, 0], + [47.641706, -0.049319, 0], [47.655899, -0.233829, 0], + [47.457196, -0.37576, 0], [47.286879, -0.276408, 0], + [47.485582, -0.035126, 0] + ] + ] + ]); + }); + }); + }); +}); + +goog.require('goog.dom'); +goog.require('goog.dom.TagName'); +goog.require('ol.format.GML'); +goog.require('ol.geom.MultiPolygon'); +goog.require('ol.xml'); +goog.require('ol.geom.Point'); From f8e865348023edce7a4ba6ae52878e78c725e0fb Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 14:51:13 +0200 Subject: [PATCH 12/31] Add gmlFormat as option for WFS format --- externs/olx.js | 6 ++++++ src/ol/format/gml/v2.js | 2 +- src/ol/format/wfsformat.js | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 056f68e92a..eb9455d462 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -1647,6 +1647,12 @@ olx.format.WFSWriteGetFeatureOptions.prototype.maxFeatures; */ olx.format.WFSWriteGetFeatureOptions.prototype.geometryName; +/** + * GML format to use within the WFS format. + * @type {ol.format.GML|undefined} + * @api + */ +olx.format.WFSWriteGetFeatureOptions.prototype.gmlFormat; /** * Extent to use for the BBOX filter. diff --git a/src/ol/format/gml/v2.js b/src/ol/format/gml/v2.js index 742d74ef30..2911f4f78d 100644 --- a/src/ol/format/gml/v2.js +++ b/src/ol/format/gml/v2.js @@ -30,7 +30,7 @@ goog.inherits(ol.format.GML.v2, ol.format.GML); /** - * @protected + * @private * @type {string} */ ol.format.GML.v2.schemaLocation_ = 'http://www.opengis.net/gml ' + diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 5ab27be9cb..bb4e2bab7f 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -40,6 +40,13 @@ ol.format.WFS = function(opt_options) { */ this.featureNS_ = options.featureNS; + /** + * @private + * @type {string} + */ + this.gmlFormat_ = goog.isDef(options.gmlFormat) ? + options.gmlFormat : new ol.format.GML(); + /** * @private * @type {string} @@ -119,7 +126,8 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) { goog.isDef(opt_options) ? opt_options : {})); var objectStack = [context]; var features = ol.xml.pushParseAndPop([], - ol.format.GML.FEATURE_COLLECTION_PARSERS, node, objectStack); + ol.format.GML.FEATURE_COLLECTION_PARSERS, node, + objectStack, this.gmlFormat_); if (!goog.isDef(features)) { features = []; } From 82f267f0c5852dce0e76daab3bf809979401eb28 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 23 Sep 2014 14:51:45 +0200 Subject: [PATCH 13/31] Add test to parse WFS with GML 2.1.2 --- test/spec/ol/format/wfs/polygonv2.xml | 89 +++++++++++++++++++++++++++ test/spec/ol/format/wfsformat.test.js | 39 ++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 test/spec/ol/format/wfs/polygonv2.xml diff --git a/test/spec/ol/format/wfs/polygonv2.xml b/test/spec/ol/format/wfs/polygonv2.xml new file mode 100644 index 0000000000..a8140cdf36 --- /dev/null +++ b/test/spec/ol/format/wfs/polygonv2.xml @@ -0,0 +1,89 @@ + + + + + -0.768746,47.003018 3.002191,47.925567 + + + + + + + -0.768746,47.003018 0.532597,47.925567 + + + + + + + + + -0.318987,47.003018 -0.768746,47.358268 -0.574463,47.684285 -0.347374,47.854602 -0.006740,47.925567 0.135191,47.726864 0.149384,47.599127 0.419052,47.670092 0.532597,47.428810 0.305508,47.443003 0.475824,47.144948 0.064225,47.201721 -0.318987,47.003018 + + + + + -0.035126,47.485582 -0.035126,47.485582 -0.049319,47.641706 -0.233829,47.655899 -0.375760,47.457196 -0.276408,47.286879 -0.035126,47.485582 + + + + + + + 1 + My Polygon with hole + 0 + + + + + + + 1.511919,47.088176 3.002191,47.882988 + + + + + + + 1.625463,47.357844 1.511919,47.741057 1.880938,47.882988 2.420275,47.797830 2.789295,47.485582 3.002191,47.457196 2.874453,47.088176 2.178993,47.343651 1.625463,47.357844 + + + + + 2 + My simple Polygon + 0 + + + + + + + 0.000000,45.000000 2.000000,47.000000 + + + + + + + + + 0.000000,45.000000 2.000000,45.000000 2.000000,47.000000 0.000000,47.000000 0.000000,45.000000 + + + + + 0.500000,45.500000 1.500000,45.500000 1.500000,46.500000 0.500000,46.500000 0.500000,45.500000 + + + + + + + 3 + my polygon with hole + 3 + + + \ No newline at end of file diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index a68e3b1e55..6beb04c78a 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -50,6 +50,43 @@ describe('ol.format.WFS', function() { }); + describe('when parsing mapserver GML2 polygon', function() { + + var features, feature, xml; + var config = { + 'featureNS': 'http://mapserver.gis.umn.edu/mapserver', + 'featureType': 'polygon', + 'gmlFormat': new ol.format.GML.v2() + }; + + before(function(done) { + proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326')); + afterLoadText('spec/ol/format/wfs/polygonv2.xml', function(data) { + try { + xml = data; + features = new ol.format.WFS(config).readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('creates 3 features', function() { + expect(features).to.have.length(3); + }); + + it('creates a polygon for My Polygon with hole', function() { + feature = features[0]; + expect(feature.getId()).to.equal('1'); + expect(feature.get('name')).to.equal('My Polygon with hole'); + expect(feature.getGeometry()).to.be.an(ol.geom.MultiPolygon); + expect(feature.getGeometry().getFlatCoordinates()). + to.have.length(60); + }); + + }); + describe('when parsing FeatureCollection', function() { var response; before(function(done) { @@ -403,5 +440,7 @@ goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.MultiPoint'); goog.require('ol.geom.MultiPolygon'); goog.require('ol.geom.Polygon'); +goog.require('ol.format.GML'); +goog.require('ol.format.GML.v2'); goog.require('ol.format.WFS'); goog.require('ol.proj'); From c9171b86829ceb588edd9c2f01ab429e79964ab3 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:08:27 +0200 Subject: [PATCH 14/31] Pass options from v2 to its parent constructor --- src/ol/format/gml/v2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ol/format/gml/v2.js b/src/ol/format/gml/v2.js index 2911f4f78d..32b04137d5 100644 --- a/src/ol/format/gml/v2.js +++ b/src/ol/format/gml/v2.js @@ -24,12 +24,13 @@ goog.require('ol.xml'); */ ol.format.GML.v2 = function(opt_options) { - goog.base(this); + goog.base(this, opt_options); }; goog.inherits(ol.format.GML.v2, ol.format.GML); /** + * @const * @private * @type {string} */ From d8114012bb10266a5cbcacb91bf62a5f777391d9 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:11:14 +0200 Subject: [PATCH 15/31] Remove from GML base all objects and methods that should belong to v3 --- src/ol/format/gml/base.js | 1242 +------------------------------------ 1 file changed, 20 insertions(+), 1222 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index 5d48a08975..e561921c50 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -10,10 +10,8 @@ goog.require('goog.object'); goog.require('goog.string'); goog.require('ol.Feature'); goog.require('ol.array'); -goog.require('ol.extent'); goog.require('ol.format.Feature'); goog.require('ol.format.XMLFeature'); -goog.require('ol.format.XSD'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.LineString'); goog.require('ol.geom.LinearRing'); @@ -100,16 +98,6 @@ ol.format.GML = function(opt_options) { goog.inherits(ol.format.GML, ol.format.XMLFeature); -/** - * @const - * @type {string} - * @private - */ -ol.format.GML.schemaLocation_ = 'http://www.opengis.net/gml ' + - 'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' + - '1.0.0/gmlsf.xsd'; - - /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. @@ -286,51 +274,6 @@ ol.format.GML.prototype.readMultiLineString_ = function(node, objectStack) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private - * @return {ol.geom.MultiLineString|undefined} MultiLineString. - */ -ol.format.GML.prototype.readMultiCurve_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'MultiCurve'); - var lineStrings = ol.xml.pushParseAndPop( - /** @type {Array.} */ ([]), - ol.format.GML.MULTICURVE_PARSERS_, node, objectStack, this); - if (goog.isDef(lineStrings)) { - var multiLineString = new ol.geom.MultiLineString(null); - multiLineString.setLineStrings(lineStrings); - return multiLineString; - } else { - return undefined; - } -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. - */ -ol.format.GML.prototype.readMultiSurface_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'MultiSurface'); - var polygons = ol.xml.pushParseAndPop( - /** @type {Array.} */ ([]), - ol.format.GML.MULTISURFACE_PARSERS_, node, objectStack, this); - if (goog.isDef(polygons)) { - var multiPolygon = new ol.geom.MultiPolygon(null); - multiPolygon.setPolygons(polygons); - return multiPolygon; - } else { - return undefined; - } -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. */ ol.format.GML.prototype.readMultiPolygon_ = function(node, objectStack) { @@ -376,32 +319,6 @@ ol.format.GML.prototype.lineStringMemberParser_ = function(node, objectStack) { }; -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - */ -ol.format.GML.prototype.curveMemberParser_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'curveMember' || - node.localName == 'curveMembers'); - ol.xml.parse(ol.format.GML.CURVEMEMBER_PARSERS_, node, objectStack, this); -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - */ -ol.format.GML.prototype.surfaceMemberParser_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'surfaceMember' || - node.localName == 'surfaceMembers'); - ol.xml.parse(ol.format.GML.SURFACEMEMBER_PARSERS_, node, objectStack, this); -}; - - /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. @@ -436,109 +353,6 @@ ol.format.GML.prototype.readLineString_ = function(node, objectStack) { }; -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {Array.<(Array.)>|undefined} flat coordinates. - */ -ol.format.GML.prototype.readPatch_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'patches'); - return ol.xml.pushParseAndPop( - /** @type {Array.>} */ ([null]), - ol.format.GML.PATCHES_PARSERS_, node, objectStack, this); -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {Array.|undefined} flat coordinates. - */ -ol.format.GML.prototype.readSegment_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'segments'); - return ol.xml.pushParseAndPop( - /** @type {Array.} */ ([null]), - ol.format.GML.SEGMENTS_PARSERS_, node, objectStack, this); -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {Array.<(Array.)>|undefined} flat coordinates. - */ -ol.format.GML.prototype.readPolygonPatch_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'PolygonPatch'); - return ol.xml.pushParseAndPop( - /** @type {Array.>} */ ([null]), - ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {Array.|undefined} flat coordinates. - */ -ol.format.GML.prototype.readLineStringSegment_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'LineStringSegment'); - return ol.xml.pushParseAndPop( - /** @type {Array.} */ ([null]), - ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_, - node, objectStack, this); -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - */ -ol.format.GML.prototype.interiorParser_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'interior'); - var flatLinearRing = ol.xml.pushParseAndPop( - /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS, node, objectStack, this); - if (goog.isDef(flatLinearRing)) { - var flatLinearRings = /** @type {Array.>} */ - (objectStack[objectStack.length - 1]); - goog.asserts.assert(goog.isArray(flatLinearRings)); - goog.asserts.assert(flatLinearRings.length > 0); - flatLinearRings.push(flatLinearRing); - } -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - */ -ol.format.GML.prototype.exteriorParser_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'exterior'); - var flatLinearRing = ol.xml.pushParseAndPop( - /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS, node, objectStack, this); - if (goog.isDef(flatLinearRing)) { - var flatLinearRings = /** @type {Array.>} */ - (objectStack[objectStack.length - 1]); - goog.asserts.assert(goog.isArray(flatLinearRings)); - goog.asserts.assert(flatLinearRings.length > 0); - flatLinearRings[0] = flatLinearRing; - } -}; - - /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. @@ -611,77 +425,6 @@ ol.format.GML.prototype.readPolygon_ = function(node, objectStack) { }; -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {ol.geom.Polygon|undefined} Polygon. - */ -ol.format.GML.prototype.readSurface_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'Surface'); - var flatLinearRings = ol.xml.pushParseAndPop( - /** @type {Array.>} */ ([null]), - ol.format.GML.SURFACE_PARSERS_, node, objectStack, this); - if (goog.isDef(flatLinearRings) && - !goog.isNull(flatLinearRings[0])) { - var polygon = new ol.geom.Polygon(null); - var flatCoordinates = flatLinearRings[0]; - var ends = [flatCoordinates.length]; - var i, ii; - for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { - ol.array.safeExtend(flatCoordinates, flatLinearRings[i]); - ends.push(flatCoordinates.length); - } - polygon.setFlatCoordinates( - ol.geom.GeometryLayout.XYZ, flatCoordinates, ends); - return polygon; - } else { - return undefined; - } -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {ol.geom.LineString|undefined} LineString. - */ -ol.format.GML.prototype.readCurve_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'Curve'); - var flatCoordinates = ol.xml.pushParseAndPop( - /** @type {Array.} */ ([null]), - ol.format.GML.CURVE_PARSERS_, node, objectStack, this); - if (goog.isDef(flatCoordinates)) { - var lineString = new ol.geom.LineString(null); - lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates); - return lineString; - } else { - return undefined; - } -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - * @return {ol.Extent|undefined} Envelope. - */ -ol.format.GML.prototype.readEnvelope_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'Envelope'); - var flatCoordinates = ol.xml.pushParseAndPop( - /** @type {Array.} */ ([null]), - ol.format.GML.ENVELOPE_PARSERS_, node, objectStack, this); - return ol.extent.createOrUpdate(flatCoordinates[1][0], - flatCoordinates[1][1], flatCoordinates[2][0], - flatCoordinates[2][1]); -}; - - /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. @@ -699,94 +442,30 @@ ol.format.GML.prototype.readFlatCoordinatesFromNode_ = function(node, /** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. + * @const + * @type {Object.>} * @private - * @return {Array.|undefined} Flat coordinates. */ -ol.format.GML.prototype.readFlatPos_ = function(node, objectStack) { - var s = ol.xml.getAllTextContent(node, false); - var re = /^\s*([+\-]?\d*\.?\d+(?:[eE][+\-]?\d+)?)\s*/; - /** @type {Array.} */ - var flatCoordinates = []; - var m; - while ((m = re.exec(s))) { - flatCoordinates.push(parseFloat(m[1])); - s = s.substr(m[0].length); +ol.format.GML.POLYGONMEMBER_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'Polygon': ol.xml.makeArrayPusher( + ol.format.GML.prototype.readPolygon) } - if (s !== '') { - return undefined; - } - var context = objectStack[0]; - goog.asserts.assert(goog.isObject(context)); - var containerSrs = goog.object.get(context, 'srsName'); - var axisOrientation = 'enu'; - if (!goog.isNull(containerSrs)) { - var proj = ol.proj.get(containerSrs); - axisOrientation = proj.getAxisOrientation(); - } - if (axisOrientation === 'neu') { - var i, ii; - for (i = 0, ii = flatCoordinates.length; i < ii; i += 3) { - var y = flatCoordinates[i]; - var x = flatCoordinates[i + 1]; - flatCoordinates[i] = x; - flatCoordinates[i + 1] = y; - } - } - var len = flatCoordinates.length; - if (len == 2) { - flatCoordinates.push(0); - } - if (len === 0) { - return undefined; - } - return flatCoordinates; }; /** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. + * @const + * @type {Object.>} * @private - * @return {Array.|undefined} Flat coordinates. */ -ol.format.GML.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)); - var containerSrs = goog.object.get(context, 'srsName'); - var containerDimension = node.parentNode.getAttribute('srsDimension'); - var axisOrientation = 'enu'; - if (!goog.isNull(containerSrs)) { - var proj = ol.proj.get(containerSrs); - axisOrientation = proj.getAxisOrientation(); +ol.format.GML.MULTILINESTRING_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'lineStringMember': ol.xml.makeArrayPusher( + ol.format.GML.prototype.lineStringMemberParser_), + 'lineStringMembers': ol.xml.makeArrayPusher( + ol.format.GML.prototype.lineStringMemberParser_) } - var coords = s.split(/\s+/); - // The "dimension" attribute is from the GML 3.0.1 spec. - var dim = 2; - if (!goog.isNull(node.getAttribute('srsDimension'))) { - dim = ol.format.XSD.readNonNegativeIntegerString( - node.getAttribute('srsDimension')); - } else if (!goog.isNull(node.getAttribute('dimension'))) { - dim = ol.format.XSD.readNonNegativeIntegerString( - node.getAttribute('dimension')); - } else if (!goog.isNull(containerDimension)) { - dim = ol.format.XSD.readNonNegativeIntegerString(containerDimension); - } - var x, y, z; - var flatCoordinates = []; - for (var i = 0, ii = coords.length; i < ii; i += dim) { - x = parseFloat(coords[i]); - y = parseFloat(coords[i + 1]); - z = (dim === 3) ? parseFloat(coords[i + 2]) : 0; - if (axisOrientation.substr(0, 2) === 'en') { - flatCoordinates.push(x, y, z); - } else { - flatCoordinates.push(y, x, z); - } - } - return flatCoordinates; }; @@ -818,107 +497,6 @@ ol.format.GML.GEOMETRY_PARSERS_ = { }; -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'pos': ol.xml.makeReplacer(ol.format.GML.prototype.readFlatPos_), - 'posList': ol.xml.makeReplacer(ol.format.GML.prototype.readFlatPosList_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'interior': ol.format.GML.prototype.interiorParser_, - 'exterior': ol.format.GML.prototype.exteriorParser_ - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.MULTIPOINT_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'pointMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.pointMemberParser_), - 'pointMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.pointMemberParser_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.MULTILINESTRING_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'lineStringMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.lineStringMemberParser_), - 'lineStringMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.lineStringMemberParser_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.MULTICURVE_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'curveMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.curveMemberParser_), - 'curveMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.curveMemberParser_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.MULTISURFACE_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'surfaceMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.surfaceMemberParser_), - 'surfaceMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.surfaceMemberParser_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.MULTIPOLYGON_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'polygonMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.polygonMemberParser_), - 'polygonMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.polygonMemberParser_) - } -}; - - /** * @const * @type {Object.>} @@ -940,7 +518,7 @@ ol.format.GML.POINTMEMBER_PARSERS_ = { ol.format.GML.LINESTRINGMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readLineString_) + ol.format.GML.prototype.readLineString) } }; @@ -950,102 +528,12 @@ ol.format.GML.LINESTRINGMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.CURVEMEMBER_PARSERS_ = { +ol.format.GML.MULTIPOINT_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'LineString': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readLineString_), - 'Curve': ol.xml.makeArrayPusher(ol.format.GML.prototype.readCurve_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.SURFACEMEMBER_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'Polygon': ol.xml.makeArrayPusher(ol.format.GML.prototype.readPolygon_), - 'Surface': ol.xml.makeArrayPusher(ol.format.GML.prototype.readSurface_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.POLYGONMEMBER_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'Polygon': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readPolygon_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.SURFACE_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'patches': ol.xml.makeReplacer(ol.format.GML.prototype.readPatch_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.CURVE_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'segments': ol.xml.makeReplacer(ol.format.GML.prototype.readSegment_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.ENVELOPE_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'lowerCorner': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readFlatPosList_), - 'upperCorner': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readFlatPosList_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.PATCHES_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'PolygonPatch': ol.xml.makeReplacer( - ol.format.GML.prototype.readPolygonPatch_) - } -}; - - -/** - * @const - * @type {Object.>} - * @private - */ -ol.format.GML.SEGMENTS_PARSERS_ = { - 'http://www.opengis.net/gml' : { - 'LineStringSegment': ol.xml.makeReplacer( - ol.format.GML.prototype.readLineStringSegment_) + 'pointMember': ol.xml.makeArrayPusher( + ol.format.GML.prototype.pointMemberParser_), + 'pointMembers': ol.xml.makeArrayPusher( + ol.format.GML.prototype.pointMemberParser_) } }; @@ -1107,693 +595,3 @@ ol.format.GML.prototype.readProjectionFromNode = function(node) { return ol.proj.get(goog.isDef(this.srsName_) ? this.srsName_ : node.firstElementChild.getAttribute('srsName')); }; - - -/** - * @param {Node} node Node. - * @param {ol.geom.Point} value Point geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writePos_ = function(node, value, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - var axisOrientation = 'enu'; - if (goog.isDefAndNotNull(srsName)) { - axisOrientation = ol.proj.get(srsName).getAxisOrientation(); - } - var point = value.getCoordinates(); - var coords; - // only 2d for simple features profile - if (axisOrientation.substr(0, 2) === 'en') { - coords = (point[0] + ' ' + point[1]); - } else { - coords = (point[1] + ' ' + point[0]); - } - ol.format.XSD.writeStringTextNode(node, coords); -}; - - -/** - * @param {Array.} point Point geometry. - * @param {string=} opt_srsName Optional srsName - * @return {string} - * @private - */ -ol.format.GML.prototype.getCoords_ = function(point, opt_srsName) { - var axisOrientation = 'enu'; - if (goog.isDefAndNotNull(opt_srsName)) { - axisOrientation = ol.proj.get(opt_srsName).getAxisOrientation(); - } - return ((axisOrientation.substr(0, 2) === 'en') ? - point[0] + ' ' + point[1] : - point[1] + ' ' + point[0]); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.LineString|ol.geom.LinearRing} value Geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writePosList_ = function(node, value, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - // only 2d for simple features profile - var points = value.getCoordinates(); - var len = points.length; - var parts = new Array(len); - var point; - for (var i = 0; i < len; ++i) { - point = points[i]; - parts[i] = this.getCoords_(point, srsName); - } - ol.format.XSD.writeStringTextNode(node, parts.join(' ')); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.Point} geometry Point geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writePoint_ = function(node, geometry, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - if (goog.isDefAndNotNull(srsName)) { - node.setAttribute('srsName', srsName); - } - var pos = ol.xml.createElementNS(node.namespaceURI, 'pos'); - node.appendChild(pos); - this.writePos_(pos, geometry, objectStack); -}; - - -/** - * @type {Object.>} - * @private - */ -ol.format.GML.ENVELOPE_SERIALIZERS_ = { - 'http://www.opengis.net/gml': { - 'lowerCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode), - 'upperCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode) - } -}; - - -/** - * @param {Node} node Node. - * @param {ol.Extent} extent Extent. - * @param {Array.<*>} objectStack Node stack. - */ -ol.format.GML.prototype.writeEnvelope = function(node, extent, objectStack) { - goog.asserts.assert(extent.length == 4); - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - if (goog.isDef(srsName)) { - node.setAttribute('srsName', srsName); - } - var keys = ['lowerCorner', 'upperCorner']; - var values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]]; - ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ - ({node: node}), ol.format.GML.ENVELOPE_SERIALIZERS_, - ol.xml.OBJECT_PROPERTY_NODE_FACTORY, - values, - objectStack, keys, this); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.LinearRing} geometry LinearRing geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeLinearRing_ = - function(node, geometry, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - if (goog.isDefAndNotNull(srsName)) { - node.setAttribute('srsName', srsName); - } - var posList = ol.xml.createElementNS(node.namespaceURI, 'posList'); - node.appendChild(posList); - this.writePosList_(posList, geometry, objectStack); -}; - - -/** - * @param {*} value Value. - * @param {Array.<*>} objectStack Object stack. - * @param {string=} opt_nodeName Node name. - * @return {Node} Node. - * @private - */ -ol.format.GML.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)); - var exteriorWritten = goog.object.get(context, 'exteriorWritten'); - if (!goog.isDef(exteriorWritten)) { - goog.object.set(context, 'exteriorWritten', true); - } - return ol.xml.createElementNS(parentNode.namespaceURI, - goog.isDef(exteriorWritten) ? 'interior' : 'exterior'); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.Polygon} geometry Polygon geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeSurfaceOrPolygon_ = - function(node, geometry, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - if (node.nodeName !== 'PolygonPatch' && goog.isDefAndNotNull(srsName)) { - node.setAttribute('srsName', srsName); - } - if (node.nodeName === 'Polygon' || node.nodeName === 'PolygonPatch') { - var rings = geometry.getLinearRings(); - ol.xml.pushSerializeAndPop( - {node: node, srsName: srsName}, - ol.format.GML.RING_SERIALIZERS_, - this.RING_NODE_FACTORY_, - rings, objectStack, undefined, this); - } else if (node.nodeName === 'Surface') { - var patches = ol.xml.createElementNS(node.namespaceURI, 'patches'); - node.appendChild(patches); - this.writeSurfacePatches_( - patches, geometry, objectStack); - } -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.LineString} geometry LineString geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeCurveOrLineString_ = - function(node, geometry, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - if (node.nodeName !== 'LineStringSegment' && goog.isDefAndNotNull(srsName)) { - node.setAttribute('srsName', srsName); - } - if (node.nodeName === 'LineString' || node.nodeName === 'LineStringSegment') { - var posList = ol.xml.createElementNS(node.namespaceURI, 'posList'); - node.appendChild(posList); - this.writePosList_(posList, geometry, objectStack); - } else if (node.nodeName === 'Curve') { - var segments = ol.xml.createElementNS(node.namespaceURI, 'segments'); - node.appendChild(segments); - this.writeCurveSegments_(segments, - geometry, objectStack); - } -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.MultiPolygon} geometry MultiPolygon geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, - objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - var surface = goog.object.get(context, 'surface'); - if (goog.isDefAndNotNull(srsName)) { - node.setAttribute('srsName', srsName); - } - var polygons = geometry.getPolygons(); - ol.xml.pushSerializeAndPop({node: node, srsName: srsName, surface: surface}, - ol.format.GML.SURFACEORPOLYGONMEMBER_SERIALIZERS_, - this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons, - objectStack, undefined, this); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.MultiPoint} geometry MultiPoint geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeMultiPoint_ = function(node, geometry, - objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - if (goog.isDefAndNotNull(srsName)) { - node.setAttribute('srsName', srsName); - } - var points = geometry.getPoints(); - ol.xml.pushSerializeAndPop({node: node, srsName: srsName}, - ol.format.GML.POINTMEMBER_SERIALIZERS_, - ol.xml.makeSimpleNodeFactory('pointMember'), points, - objectStack, undefined, this); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.MultiLineString} geometry MultiLineString geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeMultiCurveOrLineString_ = function(node, geometry, - objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var srsName = goog.object.get(context, 'srsName'); - var curve = goog.object.get(context, 'curve'); - if (goog.isDefAndNotNull(srsName)) { - node.setAttribute('srsName', srsName); - } - var lines = geometry.getLineStrings(); - ol.xml.pushSerializeAndPop({node: node, srsName: srsName, curve: curve}, - ol.format.GML.LINESTRINGORCURVEMEMBER_SERIALIZERS_, - this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines, - objectStack, undefined, this); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.LinearRing} ring LinearRing geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeRing_ = function(node, ring, objectStack) { - var linearRing = ol.xml.createElementNS(node.namespaceURI, 'LinearRing'); - node.appendChild(linearRing); - this.writeLinearRing_(linearRing, ring, objectStack); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.Polygon} polygon Polygon geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, - objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var child = this.GEOMETRY_NODE_FACTORY_( - polygon, objectStack); - if (goog.isDef(child)) { - node.appendChild(child); - this.writeSurfaceOrPolygon_(child, polygon, objectStack); - } -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.Point} point Point geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writePointMember_ = function(node, point, objectStack) { - var child = ol.xml.createElementNS(node.namespaceURI, 'Point'); - node.appendChild(child); - this.writePoint_(child, point, objectStack); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.LineString} line LineString geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeLineStringOrCurveMember_ = function(node, line, - objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var child = this.GEOMETRY_NODE_FACTORY_(line, objectStack); - if (goog.isDef(child)) { - node.appendChild(child); - this.writeCurveOrLineString_(child, line, objectStack); - } -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.Polygon} polygon Polygon geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeSurfacePatches_ = - function(node, polygon, objectStack) { - var child = ol.xml.createElementNS(node.namespaceURI, 'PolygonPatch'); - node.appendChild(child); - this.writeSurfaceOrPolygon_(child, polygon, objectStack); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.LineString} line LineString geometry. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeCurveSegments_ = - function(node, line, objectStack) { - var child = ol.xml.createElementNS(node.namespaceURI, 'LineStringSegment'); - node.appendChild(child); - this.writeCurveOrLineString_(child, line, objectStack); -}; - - -/** - * @param {Node} node Node. - * @param {ol.geom.Geometry|ol.Extent} geometry Geometry. - * @param {Array.<*>} objectStack Node stack. - */ -ol.format.GML.prototype.writeGeometryElement = - function(node, geometry, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var item = goog.object.clone(context); - item.node = node; - var value; - if (goog.isArray(geometry)) { - if (goog.isDef(context.dataProjection)) { - value = ol.proj.transformExtent( - geometry, context.featureProjection, context.dataProjection); - } else { - value = geometry; - } - } else { - goog.asserts.assertInstanceof(geometry, ol.geom.Geometry); - value = - ol.format.Feature.transformWithOptions(geometry, true, context); - } - ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ - (item), ol.format.GML.GEOMETRY_SERIALIZERS_, - this.GEOMETRY_NODE_FACTORY_, [value], - objectStack, undefined, this); -}; - - -/** - * @param {Node} node Node. - * @param {ol.Feature} feature Feature. - * @param {Array.<*>} objectStack Node stack. - */ -ol.format.GML.prototype.writeFeatureElement = - function(node, feature, objectStack) { - var fid = feature.getId(); - if (goog.isDef(fid)) { - node.setAttribute('fid', fid); - } - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var featureNS = goog.object.get(context, 'featureNS'); - var geometryName = feature.getGeometryName(); - if (!goog.isDef(context.serializers)) { - context.serializers = {}; - context.serializers[featureNS] = {}; - } - var properties = feature.getProperties(); - var keys = [], values = []; - for (var key in properties) { - var value = properties[key]; - if (!goog.isNull(value)) { - keys.push(key); - values.push(value); - if (key == geometryName) { - if (!(key in context.serializers[featureNS])) { - context.serializers[featureNS][key] = ol.xml.makeChildAppender( - this.writeGeometryElement, this); - } - } else { - if (!(key in context.serializers[featureNS])) { - context.serializers[featureNS][key] = ol.xml.makeChildAppender( - ol.format.XSD.writeStringTextNode); - } - } - } - } - var item = goog.object.clone(context); - item.node = node; - ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ - (item), context.serializers, - ol.xml.makeSimpleNodeFactory(undefined, featureNS), - values, - objectStack, keys); -}; - - -/** - * @param {Node} node Node. - * @param {Array.} features Features. - * @param {Array.<*>} objectStack Node stack. - * @private - */ -ol.format.GML.prototype.writeFeatureMembers_ = - function(node, features, objectStack) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var featureType = goog.object.get(context, 'featureType'); - var featureNS = goog.object.get(context, 'featureNS'); - var serializers = {}; - serializers[featureNS] = {}; - serializers[featureNS][featureType] = ol.xml.makeChildAppender( - this.writeFeatureElement, this); - var item = goog.object.clone(context); - item.node = node; - ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ - (item), - serializers, - ol.xml.makeSimpleNodeFactory(featureType, featureNS), features, - objectStack); -}; - - -/** - * @type {Object.>} - * @private - */ -ol.format.GML.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = { - 'http://www.opengis.net/gml': { - 'surfaceMember': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeSurfaceOrPolygonMember_), - 'polygonMember': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeSurfaceOrPolygonMember_) - } -}; - - -/** - * @type {Object.>} - * @private - */ -ol.format.GML.POINTMEMBER_SERIALIZERS_ = { - 'http://www.opengis.net/gml': { - 'pointMember': ol.xml.makeChildAppender( - ol.format.GML.prototype.writePointMember_) - } -}; - - -/** - * @type {Object.>} - * @private - */ -ol.format.GML.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = { - 'http://www.opengis.net/gml': { - 'lineStringMember': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeLineStringOrCurveMember_), - 'curveMember': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeLineStringOrCurveMember_) - } -}; - - -/** - * @type {Object.>} - * @private - */ -ol.format.GML.RING_SERIALIZERS_ = { - 'http://www.opengis.net/gml': { - 'exterior': ol.xml.makeChildAppender(ol.format.GML.prototype.writeRing_), - 'interior': ol.xml.makeChildAppender(ol.format.GML.prototype.writeRing_) - } -}; - - -/** - * @type {Object.>} - * @private - */ -ol.format.GML.GEOMETRY_SERIALIZERS_ = { - 'http://www.opengis.net/gml': { - 'Curve': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeCurveOrLineString_), - 'MultiCurve': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeMultiCurveOrLineString_), - 'Point': ol.xml.makeChildAppender(ol.format.GML.prototype.writePoint_), - 'MultiPoint': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeMultiPoint_), - 'LineString': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeCurveOrLineString_), - 'MultiLineString': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeMultiCurveOrLineString_), - 'LinearRing': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeLinearRing_), - 'Polygon': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeSurfaceOrPolygon_), - 'MultiPolygon': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeMultiSurfaceOrPolygon_), - 'Surface': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeSurfaceOrPolygon_), - 'MultiSurface': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeMultiSurfaceOrPolygon_), - 'Envelope': ol.xml.makeChildAppender( - ol.format.GML.prototype.writeEnvelope) - } -}; - - -/** - * @const - * @type {Object.} - * @private - */ -ol.format.GML.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = { - 'MultiLineString': 'lineStringMember', - 'MultiCurve': 'curveMember', - 'MultiPolygon': 'polygonMember', - 'MultiSurface': 'surfaceMember' -}; - - -/** - * @const - * @param {*} value Value. - * @param {Array.<*>} objectStack Object stack. - * @param {string=} opt_nodeName Node name. - * @return {Node|undefined} Node. - * @private - */ -ol.format.GML.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = function(value, - objectStack, opt_nodeName) { - var parentNode = objectStack[objectStack.length - 1].node; - goog.asserts.assert(ol.xml.isNode(parentNode)); - return ol.xml.createElementNS('http://www.opengis.net/gml', - ol.format.GML.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]); -}; - - -/** - * @const - * @param {*} value Value. - * @param {Array.<*>} objectStack Object stack. - * @param {string=} opt_nodeName Node name. - * @return {Node|undefined} Node. - * @private - */ -ol.format.GML.prototype.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, - opt_nodeName) { - var context = objectStack[objectStack.length - 1]; - goog.asserts.assert(goog.isObject(context)); - var multiSurface = goog.object.get(context, 'multiSurface'); - var surface = goog.object.get(context, 'surface'); - var curve = goog.object.get(context, 'curve'); - var multiCurve = goog.object.get(context, 'multiCurve'); - var parentNode = objectStack[objectStack.length - 1].node; - goog.asserts.assert(ol.xml.isNode(parentNode)); - var nodeName; - if (!goog.isArray(value)) { - goog.asserts.assertInstanceof(value, ol.geom.Geometry); - nodeName = value.getType(); - if (nodeName === 'MultiPolygon' && multiSurface === true) { - nodeName = 'MultiSurface'; - } else if (nodeName === 'Polygon' && surface === true) { - nodeName = 'Surface'; - } else if (nodeName === 'LineString' && curve === true) { - nodeName = 'Curve'; - } else if (nodeName === 'MultiLineString' && multiCurve === true) { - nodeName = 'MultiCurve'; - } - } else { - nodeName = 'Envelope'; - } - return ol.xml.createElementNS('http://www.opengis.net/gml', - nodeName); -}; - - -/** - * @inheritDoc - */ -ol.format.GML.prototype.writeGeometryNode = function(geometry, opt_options) { - var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom'); - var context = {node: geom, srsName: this.srsName_, - curve: this.curve_, surface: this.surface_, - multiSurface: this.multiSurface_, multiCurve: this.multiCurve_}; - if (goog.isDef(opt_options)) { - goog.object.extend(context, opt_options); - } - this.writeGeometryElement(geom, geometry, [context]); - return geom; -}; - - -/** - * Encode an array of features in GML 3.1.1 Simple Features. - * - * @function - * @param {Array.} features Features. - * @param {olx.format.WriteOptions=} opt_options Options. - * @return {Node} Result. - * @api stable - */ -ol.format.GML.prototype.writeFeatures; - - -/** - * @inheritDoc - */ -ol.format.GML.prototype.writeFeaturesNode = function(features, opt_options) { - var node = ol.xml.createElementNS('http://www.opengis.net/gml', - 'featureMembers'); - ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation', this.schemaLocation); - var context = { - srsName: this.srsName_, - curve: this.curve_, - surface: this.surface_, - multiSurface: this.multiSurface_, - multiCurve: this.multiCurve_, - featureNS: this.featureNS_, - featureType: this.featureType_ - }; - if (goog.isDef(opt_options)) { - goog.object.extend(context, opt_options); - } - this.writeFeatureMembers_(node, features, [context]); - return node; -}; From 9324580c8748d7d32c7eb4066c325815e662eaaa Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:11:59 +0200 Subject: [PATCH 16/31] add format for GML v3 version all writing methods & objects are defined in v3, as writing for v2 is not done yet --- src/ol/format/gml/v3.js | 1290 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 1290 insertions(+) create mode 100644 src/ol/format/gml/v3.js diff --git a/src/ol/format/gml/v3.js b/src/ol/format/gml/v3.js new file mode 100644 index 0000000000..23ebd980b6 --- /dev/null +++ b/src/ol/format/gml/v3.js @@ -0,0 +1,1290 @@ +goog.provide('ol.format.GML.v3'); + +goog.require('goog.asserts'); +goog.require('goog.dom'); +goog.require('goog.dom.NodeType'); +goog.require('goog.object'); +goog.require('ol.Feature'); +goog.require('ol.array'); +goog.require('ol.extent'); +goog.require('ol.format.Feature'); +goog.require('ol.format.GML'); +goog.require('ol.format.XSD'); +goog.require('ol.geom.Geometry'); +goog.require('ol.geom.LineString'); +goog.require('ol.geom.LinearRing'); +goog.require('ol.geom.MultiLineString'); +goog.require('ol.geom.MultiPolygon'); +goog.require('ol.geom.Point'); +goog.require('ol.geom.Polygon'); +goog.require('ol.proj'); +goog.require('ol.xml'); + + + +/** + * @classdesc + * Feature format for reading and writing data in the GML format + * version 3.1.1. + * Currently only supports GML 3.1.1 Simple Features profile. + * + * @constructor + * @param {olx.format.GMLOptions=} opt_options + * Optional configuration object. + * @extends {ol.format.GML} + * @api stable + */ +ol.format.GML.v3 = function(opt_options) { + var options = /** @type {olx.format.GMLOptions} */ + (goog.isDef(opt_options) ? opt_options : {}); + + /** + * @private + * @type {boolean} + */ + this.surface_ = goog.isDef(options.surface) ? + options.surface : false; + + /** + * @private + * @type {boolean} + */ + this.curve_ = goog.isDef(options.curve) ? + options.curve : false; + + /** + * @private + * @type {boolean} + */ + this.multiCurve_ = goog.isDef(options.multiCurve) ? + options.multiCurve : true; + + /** + * @private + * @type {boolean} + */ + this.multiSurface_ = goog.isDef(options.multiSurface) ? + options.multiSurface : true; + + + goog.base(this, opt_options); +}; +goog.inherits(ol.format.GML.v3, ol.format.GML); + + +/** + * @const + * @type {string} + * @private + */ +ol.format.GML.v3.schemaLocation_ = 'http://www.opengis.net/gml ' + + 'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' + + '1.0.0/gmlsf.xsd'; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.geom.MultiLineString|undefined} MultiLineString. + */ +ol.format.GML.v3.prototype.readMultiCurve_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'MultiCurve'); + var lineStrings = ol.xml.pushParseAndPop( + /** @type {Array.} */ ([]), + ol.format.GML.v3.MULTICURVE_PARSERS_, node, objectStack, this); + if (goog.isDef(lineStrings)) { + var multiLineString = new ol.geom.MultiLineString(null); + multiLineString.setLineStrings(lineStrings); + return multiLineString; + } else { + return undefined; + } +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. + */ +ol.format.GML.v3.prototype.readMultiSurface_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'MultiSurface'); + var polygons = ol.xml.pushParseAndPop( + /** @type {Array.} */ ([]), + ol.format.GML.v3.MULTISURFACE_PARSERS_, node, objectStack, this); + if (goog.isDef(polygons)) { + var multiPolygon = new ol.geom.MultiPolygon(null); + multiPolygon.setPolygons(polygons); + return multiPolygon; + } else { + return undefined; + } +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GML.v3.prototype.curveMemberParser_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'curveMember' || + node.localName == 'curveMembers'); + ol.xml.parse(ol.format.GML.v3.CURVEMEMBER_PARSERS_, node, objectStack, this); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GML.v3.prototype.surfaceMemberParser_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'surfaceMember' || + node.localName == 'surfaceMembers'); + ol.xml.parse(ol.format.GML.v3.SURFACEMEMBER_PARSERS_, + node, objectStack, this); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {Array.<(Array.)>|undefined} flat coordinates. + */ +ol.format.GML.v3.prototype.readPatch_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'patches'); + return ol.xml.pushParseAndPop( + /** @type {Array.>} */ ([null]), + ol.format.GML.v3.PATCHES_PARSERS_, node, objectStack, this); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {Array.|undefined} flat coordinates. + */ +ol.format.GML.v3.prototype.readSegment_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'segments'); + return ol.xml.pushParseAndPop( + /** @type {Array.} */ ([null]), + ol.format.GML.v3.SEGMENTS_PARSERS_, node, objectStack, this); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {Array.<(Array.)>|undefined} flat coordinates. + */ +ol.format.GML.v3.prototype.readPolygonPatch_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'PolygonPatch'); + return ol.xml.pushParseAndPop( + /** @type {Array.>} */ ([null]), + this.constructor.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {Array.|undefined} flat coordinates. + */ +ol.format.GML.v3.prototype.readLineStringSegment_ = + function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'LineStringSegment'); + return ol.xml.pushParseAndPop( + /** @type {Array.} */ ([null]), + this.constructor.GEOMETRY_FLAT_COORDINATES_PARSERS_, + node, objectStack, this); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GML.v3.prototype.interiorParser_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'interior'); + var flatLinearRing = ol.xml.pushParseAndPop( + /** @type {Array.|undefined} */ (undefined), + ol.format.GML.RING_PARSERS, node, objectStack, this); + if (goog.isDef(flatLinearRing)) { + var flatLinearRings = /** @type {Array.>} */ + (objectStack[objectStack.length - 1]); + goog.asserts.assert(goog.isArray(flatLinearRings)); + goog.asserts.assert(flatLinearRings.length > 0); + flatLinearRings.push(flatLinearRing); + } +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GML.v3.prototype.exteriorParser_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'exterior'); + var flatLinearRing = ol.xml.pushParseAndPop( + /** @type {Array.|undefined} */ (undefined), + ol.format.GML.RING_PARSERS, node, objectStack, this); + if (goog.isDef(flatLinearRing)) { + var flatLinearRings = /** @type {Array.>} */ + (objectStack[objectStack.length - 1]); + goog.asserts.assert(goog.isArray(flatLinearRings)); + goog.asserts.assert(flatLinearRings.length > 0); + flatLinearRings[0] = flatLinearRing; + } +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.geom.Polygon|undefined} Polygon. + */ +ol.format.GML.v3.prototype.readSurface_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'Surface'); + var flatLinearRings = ol.xml.pushParseAndPop( + /** @type {Array.>} */ ([null]), + ol.format.GML.v3.SURFACE_PARSERS_, node, objectStack, this); + if (goog.isDef(flatLinearRings) && + !goog.isNull(flatLinearRings[0])) { + var polygon = new ol.geom.Polygon(null); + var flatCoordinates = flatLinearRings[0]; + var ends = [flatCoordinates.length]; + var i, ii; + for (i = 1, ii = flatLinearRings.length; i < ii; ++i) { + ol.array.safeExtend(flatCoordinates, flatLinearRings[i]); + ends.push(flatCoordinates.length); + } + polygon.setFlatCoordinates( + ol.geom.GeometryLayout.XYZ, flatCoordinates, ends); + return polygon; + } else { + return undefined; + } +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.geom.LineString|undefined} LineString. + */ +ol.format.GML.v3.prototype.readCurve_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'Curve'); + var flatCoordinates = ol.xml.pushParseAndPop( + /** @type {Array.} */ ([null]), + ol.format.GML.v3.CURVE_PARSERS_, node, objectStack, this); + if (goog.isDef(flatCoordinates)) { + var lineString = new ol.geom.LineString(null); + lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates); + return lineString; + } else { + return undefined; + } +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.Extent|undefined} Envelope. + */ +ol.format.GML.v3.prototype.readEnvelope_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'Envelope'); + var flatCoordinates = ol.xml.pushParseAndPop( + /** @type {Array.} */ ([null]), + ol.format.GML.v3.ENVELOPE_PARSERS_, node, objectStack, this); + return ol.extent.createOrUpdate(flatCoordinates[1][0], + flatCoordinates[1][1], flatCoordinates[2][0], + flatCoordinates[2][1]); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {Array.|undefined} Flat coordinates. + */ +ol.format.GML.v3.prototype.readFlatPos_ = function(node, objectStack) { + var s = ol.xml.getAllTextContent(node, false); + var re = /^\s*([+\-]?\d*\.?\d+(?:[eE][+\-]?\d+)?)\s*/; + /** @type {Array.} */ + var flatCoordinates = []; + var m; + while ((m = re.exec(s))) { + flatCoordinates.push(parseFloat(m[1])); + s = s.substr(m[0].length); + } + if (s !== '') { + return undefined; + } + var context = objectStack[0]; + goog.asserts.assert(goog.isObject(context)); + var containerSrs = goog.object.get(context, 'srsName'); + var axisOrientation = 'enu'; + if (!goog.isNull(containerSrs)) { + var proj = ol.proj.get(containerSrs); + axisOrientation = proj.getAxisOrientation(); + } + if (axisOrientation === 'neu') { + var i, ii; + for (i = 0, ii = flatCoordinates.length; i < ii; i += 3) { + var y = flatCoordinates[i]; + var x = flatCoordinates[i + 1]; + flatCoordinates[i] = x; + flatCoordinates[i + 1] = y; + } + } + var len = flatCoordinates.length; + if (len == 2) { + flatCoordinates.push(0); + } + if (len === 0) { + return undefined; + } + return flatCoordinates; +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {Array.|undefined} Flat coordinates. + */ +ol.format.GML.v3.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)); + var containerSrs = goog.object.get(context, 'srsName'); + var containerDimension = node.parentNode.getAttribute('srsDimension'); + var axisOrientation = 'enu'; + if (!goog.isNull(containerSrs)) { + var proj = ol.proj.get(containerSrs); + axisOrientation = proj.getAxisOrientation(); + } + var coords = s.split(/\s+/); + // The "dimension" attribute is from the GML 3.0.1 spec. + var dim = 2; + if (!goog.isNull(node.getAttribute('srsDimension'))) { + dim = ol.format.XSD.readNonNegativeIntegerString( + node.getAttribute('srsDimension')); + } else if (!goog.isNull(node.getAttribute('dimension'))) { + dim = ol.format.XSD.readNonNegativeIntegerString( + node.getAttribute('dimension')); + } else if (!goog.isNull(containerDimension)) { + dim = ol.format.XSD.readNonNegativeIntegerString(containerDimension); + } + var x, y, z; + var flatCoordinates = []; + for (var i = 0, ii = coords.length; i < ii; i += dim) { + x = parseFloat(coords[i]); + y = parseFloat(coords[i + 1]); + z = (dim === 3) ? parseFloat(coords[i + 2]) : 0; + if (axisOrientation.substr(0, 2) === 'en') { + flatCoordinates.push(x, y, z); + } else { + flatCoordinates.push(y, x, z); + } + } + return flatCoordinates; +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'pos': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readFlatPos_), + 'posList': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readFlatPosList_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.FLAT_LINEAR_RINGS_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'interior': ol.format.GML.v3.prototype.interiorParser_, + 'exterior': ol.format.GML.v3.prototype.exteriorParser_ + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.GEOMETRY_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'Point': ol.xml.makeReplacer(ol.format.GML.prototype.readPoint), + 'MultiPoint': ol.xml.makeReplacer(ol.format.GML.prototype.readMultiPoint), + 'LineString': ol.xml.makeReplacer(ol.format.GML.prototype.readLineString), + 'MultiLineString': ol.xml.makeReplacer( + ol.format.GML.prototype.readMultiLineString), + 'LinearRing' : ol.xml.makeReplacer( + ol.format.GML.prototype.readLinearRing), + 'Polygon': ol.xml.makeReplacer(ol.format.GML.prototype.readPolygon), + 'MultiPolygon': ol.xml.makeReplacer( + ol.format.GML.prototype.readMultiPolygon), + 'Surface': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readSurface_), + 'MultiSurface': ol.xml.makeReplacer( + ol.format.GML.v3.prototype.readMultiSurface_), + 'Curve': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readCurve_), + 'MultiCurve': ol.xml.makeReplacer( + ol.format.GML.v3.prototype.readMultiCurve_), + 'Envelope': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readEnvelope_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.MULTICURVE_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'curveMember': ol.xml.makeArrayPusher( + ol.format.GML.v3.prototype.curveMemberParser_), + 'curveMembers': ol.xml.makeArrayPusher( + ol.format.GML.v3.prototype.curveMemberParser_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.MULTISURFACE_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'surfaceMember': ol.xml.makeArrayPusher( + ol.format.GML.v3.prototype.surfaceMemberParser_), + 'surfaceMembers': ol.xml.makeArrayPusher( + ol.format.GML.v3.prototype.surfaceMemberParser_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.CURVEMEMBER_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'LineString': ol.xml.makeArrayPusher( + ol.format.GML.prototype.readLineString), + 'Curve': ol.xml.makeArrayPusher(ol.format.GML.v3.prototype.readCurve_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.SURFACEMEMBER_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'Polygon': ol.xml.makeArrayPusher(ol.format.GML.prototype.readPolygon), + 'Surface': ol.xml.makeArrayPusher(ol.format.GML.v3.prototype.readSurface_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.SURFACE_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'patches': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readPatch_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.CURVE_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'segments': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readSegment_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.ENVELOPE_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'lowerCorner': ol.xml.makeArrayPusher( + ol.format.GML.v3.prototype.readFlatPosList_), + 'upperCorner': ol.xml.makeArrayPusher( + ol.format.GML.v3.prototype.readFlatPosList_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.PATCHES_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'PolygonPatch': ol.xml.makeReplacer( + ol.format.GML.v3.prototype.readPolygonPatch_) + } +}; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v3.SEGMENTS_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'LineStringSegment': ol.xml.makeReplacer( + ol.format.GML.v3.prototype.readLineStringSegment_) + } +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Point} value Point geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writePos_ = function(node, value, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + var axisOrientation = 'enu'; + if (goog.isDefAndNotNull(srsName)) { + axisOrientation = ol.proj.get(srsName).getAxisOrientation(); + } + var point = value.getCoordinates(); + var coords; + // only 2d for simple features profile + if (axisOrientation.substr(0, 2) === 'en') { + coords = (point[0] + ' ' + point[1]); + } else { + coords = (point[1] + ' ' + point[0]); + } + ol.format.XSD.writeStringTextNode(node, coords); +}; + + +/** + * @param {Array.} point Point geometry. + * @param {string=} opt_srsName Optional srsName + * @return {string} + * @private + */ +ol.format.GML.v3.prototype.getCoords_ = function(point, opt_srsName) { + var axisOrientation = 'enu'; + if (goog.isDefAndNotNull(opt_srsName)) { + axisOrientation = ol.proj.get(opt_srsName).getAxisOrientation(); + } + return ((axisOrientation.substr(0, 2) === 'en') ? + point[0] + ' ' + point[1] : + point[1] + ' ' + point[0]); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.LineString|ol.geom.LinearRing} value Geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writePosList_ = function(node, value, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + // only 2d for simple features profile + var points = value.getCoordinates(); + var len = points.length; + var parts = new Array(len); + var point; + for (var i = 0; i < len; ++i) { + point = points[i]; + parts[i] = this.getCoords_(point, srsName); + } + ol.format.XSD.writeStringTextNode(node, parts.join(' ')); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Point} geometry Point geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writePoint_ = function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + if (goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + var pos = ol.xml.createElementNS(node.namespaceURI, 'pos'); + node.appendChild(pos); + this.writePos_(pos, geometry, objectStack); +}; + + +/** + * @type {Object.>} + * @private + */ +ol.format.GML.v3.ENVELOPE_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'lowerCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode), + 'upperCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode) + } +}; + + +/** + * @param {Node} node Node. + * @param {ol.Extent} extent Extent. + * @param {Array.<*>} objectStack Node stack. + */ +ol.format.GML.v3.prototype.writeEnvelope = function(node, extent, objectStack) { + goog.asserts.assert(extent.length == 4); + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + if (goog.isDef(srsName)) { + node.setAttribute('srsName', srsName); + } + var keys = ['lowerCorner', 'upperCorner']; + var values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]]; + ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ + ({node: node}), ol.format.GML.v3.ENVELOPE_SERIALIZERS_, + ol.xml.OBJECT_PROPERTY_NODE_FACTORY, + values, + objectStack, keys, this); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.LinearRing} geometry LinearRing geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeLinearRing_ = + function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + if (goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + var posList = ol.xml.createElementNS(node.namespaceURI, 'posList'); + node.appendChild(posList); + this.writePosList_(posList, geometry, objectStack); +}; + + +/** + * @param {*} value Value. + * @param {Array.<*>} objectStack Object stack. + * @param {string=} opt_nodeName Node name. + * @return {Node} Node. + * @private + */ +ol.format.GML.v3.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)); + var exteriorWritten = goog.object.get(context, 'exteriorWritten'); + if (!goog.isDef(exteriorWritten)) { + goog.object.set(context, 'exteriorWritten', true); + } + return ol.xml.createElementNS(parentNode.namespaceURI, + goog.isDef(exteriorWritten) ? 'interior' : 'exterior'); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Polygon} geometry Polygon geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeSurfaceOrPolygon_ = + function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + if (node.nodeName !== 'PolygonPatch' && goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + if (node.nodeName === 'Polygon' || node.nodeName === 'PolygonPatch') { + var rings = geometry.getLinearRings(); + ol.xml.pushSerializeAndPop( + {node: node, srsName: srsName}, + ol.format.GML.v3.RING_SERIALIZERS_, + this.RING_NODE_FACTORY_, + rings, objectStack, undefined, this); + } else if (node.nodeName === 'Surface') { + var patches = ol.xml.createElementNS(node.namespaceURI, 'patches'); + node.appendChild(patches); + this.writeSurfacePatches_( + patches, geometry, objectStack); + } +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.LineString} geometry LineString geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeCurveOrLineString_ = + function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + if (node.nodeName !== 'LineStringSegment' && + goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + if (node.nodeName === 'LineString' || + node.nodeName === 'LineStringSegment') { + var posList = ol.xml.createElementNS(node.namespaceURI, 'posList'); + node.appendChild(posList); + this.writePosList_(posList, geometry, objectStack); + } else if (node.nodeName === 'Curve') { + var segments = ol.xml.createElementNS(node.namespaceURI, 'segments'); + node.appendChild(segments); + this.writeCurveSegments_(segments, + geometry, objectStack); + } +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.MultiPolygon} geometry MultiPolygon geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_ = + function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + var surface = goog.object.get(context, 'surface'); + if (goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + var polygons = geometry.getPolygons(); + ol.xml.pushSerializeAndPop({node: node, srsName: srsName, surface: surface}, + ol.format.GML.v3.SURFACEORPOLYGONMEMBER_SERIALIZERS_, + this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons, + objectStack, undefined, this); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.MultiPoint} geometry MultiPoint geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeMultiPoint_ = function(node, geometry, + objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + if (goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + var points = geometry.getPoints(); + ol.xml.pushSerializeAndPop({node: node, srsName: srsName}, + ol.format.GML.v3.POINTMEMBER_SERIALIZERS_, + ol.xml.makeSimpleNodeFactory('pointMember'), points, + objectStack, undefined, this); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.MultiLineString} geometry MultiLineString geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeMultiCurveOrLineString_ = + function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + var curve = goog.object.get(context, 'curve'); + if (goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + var lines = geometry.getLineStrings(); + ol.xml.pushSerializeAndPop({node: node, srsName: srsName, curve: curve}, + ol.format.GML.v3.LINESTRINGORCURVEMEMBER_SERIALIZERS_, + this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines, + objectStack, undefined, this); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.LinearRing} ring LinearRing geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeRing_ = function(node, ring, objectStack) { + var linearRing = ol.xml.createElementNS(node.namespaceURI, 'LinearRing'); + node.appendChild(linearRing); + this.writeLinearRing_(linearRing, ring, objectStack); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Polygon} polygon Polygon geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeSurfaceOrPolygonMember_ = + function(node, polygon, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var child = this.GEOMETRY_NODE_FACTORY_( + polygon, objectStack); + if (goog.isDef(child)) { + node.appendChild(child); + this.writeSurfaceOrPolygon_(child, polygon, objectStack); + } +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Point} point Point geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writePointMember_ = + function(node, point, objectStack) { + var child = ol.xml.createElementNS(node.namespaceURI, 'Point'); + node.appendChild(child); + this.writePoint_(child, point, objectStack); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.LineString} line LineString geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeLineStringOrCurveMember_ = + function(node, line, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var child = this.GEOMETRY_NODE_FACTORY_(line, objectStack); + if (goog.isDef(child)) { + node.appendChild(child); + this.writeCurveOrLineString_(child, line, objectStack); + } +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Polygon} polygon Polygon geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeSurfacePatches_ = + function(node, polygon, objectStack) { + var child = ol.xml.createElementNS(node.namespaceURI, 'PolygonPatch'); + node.appendChild(child); + this.writeSurfaceOrPolygon_(child, polygon, objectStack); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.LineString} line LineString geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeCurveSegments_ = + function(node, line, objectStack) { + var child = ol.xml.createElementNS(node.namespaceURI, + 'LineStringSegment'); + node.appendChild(child); + this.writeCurveOrLineString_(child, line, objectStack); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Geometry|ol.Extent} geometry Geometry. + * @param {Array.<*>} objectStack Node stack. + */ +ol.format.GML.v3.prototype.writeGeometryElement = + function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var item = goog.object.clone(context); + item.node = node; + var value; + if (goog.isArray(geometry)) { + if (goog.isDef(context.dataProjection)) { + value = ol.proj.transformExtent( + geometry, context.featureProjection, context.dataProjection); + } else { + value = geometry; + } + } else { + goog.asserts.assertInstanceof(geometry, ol.geom.Geometry); + value = + ol.format.Feature.transformWithOptions(geometry, true, context); + } + ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ + (item), ol.format.GML.v3.GEOMETRY_SERIALIZERS_, + this.GEOMETRY_NODE_FACTORY_, [value], + objectStack, undefined, this); +}; + + +/** + * @param {Node} node Node. + * @param {ol.Feature} feature Feature. + * @param {Array.<*>} objectStack Node stack. + */ +ol.format.GML.v3.prototype.writeFeatureElement = + function(node, feature, objectStack) { + var fid = feature.getId(); + if (goog.isDef(fid)) { + node.setAttribute('fid', fid); + } + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var featureNS = goog.object.get(context, 'featureNS'); + var geometryName = feature.getGeometryName(); + if (!goog.isDef(context.serializers)) { + context.serializers = {}; + context.serializers[featureNS] = {}; + } + var properties = feature.getProperties(); + var keys = [], values = []; + for (var key in properties) { + var value = properties[key]; + if (!goog.isNull(value)) { + keys.push(key); + values.push(value); + if (key == geometryName) { + if (!(key in context.serializers[featureNS])) { + context.serializers[featureNS][key] = ol.xml.makeChildAppender( + this.writeGeometryElement, this); + } + } else { + if (!(key in context.serializers[featureNS])) { + context.serializers[featureNS][key] = ol.xml.makeChildAppender( + ol.format.XSD.writeStringTextNode); + } + } + } + } + var item = goog.object.clone(context); + item.node = node; + ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ + (item), context.serializers, + ol.xml.makeSimpleNodeFactory(undefined, featureNS), + values, + objectStack, keys); +}; + + +/** + * @param {Node} node Node. + * @param {Array.} features Features. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.v3.prototype.writeFeatureMembers_ = + function(node, features, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var featureType = goog.object.get(context, 'featureType'); + var featureNS = goog.object.get(context, 'featureNS'); + var serializers = {}; + serializers[featureNS] = {}; + serializers[featureNS][featureType] = ol.xml.makeChildAppender( + this.writeFeatureElement, this); + var item = goog.object.clone(context); + item.node = node; + ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ + (item), + serializers, + ol.xml.makeSimpleNodeFactory(featureType, featureNS), features, + objectStack); +}; + + +/** + * @type {Object.>} + * @private + */ +ol.format.GML.v3.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'surfaceMember': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeSurfaceOrPolygonMember_), + 'polygonMember': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeSurfaceOrPolygonMember_) + } +}; + + +/** + * @type {Object.>} + * @private + */ +ol.format.GML.v3.POINTMEMBER_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'pointMember': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writePointMember_) + } +}; + + +/** + * @type {Object.>} + * @private + */ +ol.format.GML.v3.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'lineStringMember': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeLineStringOrCurveMember_), + 'curveMember': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeLineStringOrCurveMember_) + } +}; + + +/** + * @type {Object.>} + * @private + */ +ol.format.GML.v3.RING_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'exterior': ol.xml.makeChildAppender(ol.format.GML.v3.prototype.writeRing_), + 'interior': ol.xml.makeChildAppender(ol.format.GML.v3.prototype.writeRing_) + } +}; + + +/** + * @type {Object.>} + * @private + */ +ol.format.GML.v3.GEOMETRY_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'Curve': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeCurveOrLineString_), + 'MultiCurve': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeMultiCurveOrLineString_), + 'Point': ol.xml.makeChildAppender(ol.format.GML.v3.prototype.writePoint_), + 'MultiPoint': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeMultiPoint_), + 'LineString': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeCurveOrLineString_), + 'MultiLineString': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeMultiCurveOrLineString_), + 'LinearRing': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeLinearRing_), + 'Polygon': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeSurfaceOrPolygon_), + 'MultiPolygon': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_), + 'Surface': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeSurfaceOrPolygon_), + 'MultiSurface': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_), + 'Envelope': ol.xml.makeChildAppender( + ol.format.GML.v3.prototype.writeEnvelope) + } +}; + + +/** + * @const + * @type {Object.} + * @private + */ +ol.format.GML.v3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = { + 'MultiLineString': 'lineStringMember', + 'MultiCurve': 'curveMember', + 'MultiPolygon': 'polygonMember', + 'MultiSurface': 'surfaceMember' +}; + + +/** + * @const + * @param {*} value Value. + * @param {Array.<*>} objectStack Object stack. + * @param {string=} opt_nodeName Node name. + * @return {Node|undefined} Node. + * @private + */ +ol.format.GML.v3.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = + function(value, objectStack, opt_nodeName) { + var parentNode = objectStack[objectStack.length - 1].node; + goog.asserts.assert(ol.xml.isNode(parentNode)); + return ol.xml.createElementNS('http://www.opengis.net/gml', + ol.format.GML.v3.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]); +}; + + +/** + * @const + * @param {*} value Value. + * @param {Array.<*>} objectStack Object stack. + * @param {string=} opt_nodeName Node name. + * @return {Node|undefined} Node. + * @private + */ +ol.format.GML.v3.prototype.GEOMETRY_NODE_FACTORY_ = + function(value, objectStack, opt_nodeName) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var multiSurface = goog.object.get(context, 'multiSurface'); + var surface = goog.object.get(context, 'surface'); + var curve = goog.object.get(context, 'curve'); + var multiCurve = goog.object.get(context, 'multiCurve'); + var parentNode = objectStack[objectStack.length - 1].node; + goog.asserts.assert(ol.xml.isNode(parentNode)); + var nodeName; + if (!goog.isArray(value)) { + goog.asserts.assertInstanceof(value, ol.geom.Geometry); + nodeName = value.getType(); + if (nodeName === 'MultiPolygon' && multiSurface === true) { + nodeName = 'MultiSurface'; + } else if (nodeName === 'Polygon' && surface === true) { + nodeName = 'Surface'; + } else if (nodeName === 'LineString' && curve === true) { + nodeName = 'Curve'; + } else if (nodeName === 'MultiLineString' && multiCurve === true) { + nodeName = 'MultiCurve'; + } + } else { + nodeName = 'Envelope'; + } + return ol.xml.createElementNS('http://www.opengis.net/gml', + nodeName); +}; + + +/** + * @inheritDoc + */ +ol.format.GML.v3.prototype.writeGeometryNode = function(geometry, opt_options) { + var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom'); + var context = {node: geom, srsName: this.srsName, + curve: this.curve_, surface: this.surface_, + multiSurface: this.multiSurface_, multiCurve: this.multiCurve_}; + if (goog.isDef(opt_options)) { + goog.object.extend(context, opt_options); + } + this.writeGeometryElement(geom, geometry, [context]); + return geom; +}; + + +/** + * Encode an array of features in GML 3.1.1 Simple Features. + * + * @function + * @param {Array.} features Features. + * @param {olx.format.WriteOptions=} opt_options Options. + * @return {Node} Result. + * @api stable + */ +ol.format.GML.v3.prototype.writeFeatures; + + +/** + * @inheritDoc + */ +ol.format.GML.v3.prototype.writeFeaturesNode = function(features, opt_options) { + var node = ol.xml.createElementNS('http://www.opengis.net/gml', + 'featureMembers'); + ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation', this.schemaLocation); + var context = { + srsName: this.srsName, + curve: this.curve_, + surface: this.surface_, + multiSurface: this.multiSurface_, + multiCurve: this.multiCurve_, + featureNS: this.featureNS, + featureType: this.featureType + }; + if (goog.isDef(opt_options)) { + goog.object.extend(context, opt_options); + } + this.writeFeatureMembers_(node, features, [context]); + return node; +}; From 81823964545a2748b8891b4a30e50ecb65a5da16 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:13:59 +0200 Subject: [PATCH 17/31] Make class members public or protected to be accessed from subclasses or static objects --- src/ol/format/gml/base.js | 66 ++++++++++----------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index e561921c50..937532f2d4 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -41,50 +41,22 @@ ol.format.GML = function(opt_options) { (goog.isDef(opt_options) ? opt_options : {}); /** - * @private + * @protected * @type {string} */ - this.featureType_ = options.featureType; + this.featureType = options.featureType; /** - * @private + * @protected * @type {string} */ - this.featureNS_ = options.featureNS; + this.featureNS = options.featureNS; /** - * @private + * @protected * @type {string} */ - this.srsName_ = options.srsName; - - /** - * @private - * @type {boolean} - */ - this.surface_ = goog.isDef(options.surface) ? - options.surface : false; - - /** - * @private - * @type {boolean} - */ - this.curve_ = goog.isDef(options.curve) ? - options.curve : false; - - /** - * @private - * @type {boolean} - */ - this.multiCurve_ = goog.isDef(options.multiCurve) ? - options.multiCurve : true; - - /** - * @private - * @type {boolean} - */ - this.multiSurface_ = goog.isDef(options.multiSurface) ? - options.multiSurface : true; + this.srsName = options.srsName; /** * @protected @@ -160,7 +132,7 @@ ol.format.GML.prototype.readGeometryElement = function(node, objectStack) { goog.object.set(context, 'srsName', node.firstElementChild.getAttribute('srsName')); var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null), - ol.format.GML.GEOMETRY_PARSERS_, node, objectStack, this); + this.constructor.GEOMETRY_PARSERS_, node, objectStack, this); if (goog.isDefAndNotNull(geometry)) { return /** @type {ol.geom.Geometry} */ ( ol.format.Feature.transformWithOptions(geometry, false, context)); @@ -212,10 +184,9 @@ ol.format.GML.prototype.readFeature_ = function(node, objectStack) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {ol.geom.Point|undefined} Point. */ -ol.format.GML.prototype.readPoint_ = function(node, objectStack) { +ol.format.GML.prototype.readPoint = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Point'); var flatCoordinates = @@ -232,10 +203,9 @@ ol.format.GML.prototype.readPoint_ = function(node, objectStack) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {ol.geom.MultiPoint|undefined} MultiPoint. */ -ol.format.GML.prototype.readMultiPoint_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiPoint = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiPoint'); var coordinates = ol.xml.pushParseAndPop( @@ -252,10 +222,9 @@ ol.format.GML.prototype.readMultiPoint_ = function(node, objectStack) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {ol.geom.MultiLineString|undefined} MultiLineString. */ -ol.format.GML.prototype.readMultiLineString_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiLineString = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiLineString'); var lineStrings = ol.xml.pushParseAndPop( @@ -276,7 +245,7 @@ ol.format.GML.prototype.readMultiLineString_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. */ -ol.format.GML.prototype.readMultiPolygon_ = function(node, objectStack) { +ol.format.GML.prototype.readMultiPolygon = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiPolygon'); var polygons = ol.xml.pushParseAndPop( @@ -335,10 +304,9 @@ ol.format.GML.prototype.polygonMemberParser_ = function(node, objectStack) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {ol.geom.LineString|undefined} LineString. */ -ol.format.GML.prototype.readLineString_ = function(node, objectStack) { +ol.format.GML.prototype.readLineString = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LineString'); var flatCoordinates = @@ -376,10 +344,9 @@ ol.format.GML.prototype.readFlatLinearRing_ = function(node, objectStack) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {ol.geom.LinearRing|undefined} LinearRing. */ -ol.format.GML.prototype.readLinearRing_ = function(node, objectStack) { +ol.format.GML.prototype.readLinearRing = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var flatCoordinates = @@ -397,10 +364,9 @@ ol.format.GML.prototype.readLinearRing_ = function(node, objectStack) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {ol.geom.Polygon|undefined} Polygon. */ -ol.format.GML.prototype.readPolygon_ = function(node, objectStack) { +ol.format.GML.prototype.readPolygon = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Polygon'); var flatLinearRings = ol.xml.pushParseAndPop( @@ -578,8 +544,8 @@ ol.format.GML.prototype.readFeatures; */ ol.format.GML.prototype.readFeaturesFromNode = function(node, opt_options) { var options = { - 'featureType': this.featureType_, - 'featureNS': this.featureNS_ + 'featureType': this.featureType, + 'featureNS': this.featureNS }; if (goog.isDef(opt_options)) { goog.object.extend(options, this.getReadOptions(node, opt_options)); From 07d6b831541dfcc13b1a358e7652e05db6b02c48 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:14:45 +0200 Subject: [PATCH 18/31] Redefine some PARSERS_ that are different in v2 and v3 --- src/ol/format/gml/base.js | 39 +++++++++++++-------------------------- src/ol/format/gml/v2.js | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index 937532f2d4..d8df504013 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -412,10 +412,12 @@ ol.format.GML.prototype.readFlatCoordinatesFromNode_ = function(node, * @type {Object.>} * @private */ -ol.format.GML.POLYGONMEMBER_PARSERS_ = { +ol.format.GML.MULTIPOINT_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'Polygon': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readPolygon) + 'pointMember': ol.xml.makeArrayPusher( + ol.format.GML.prototype.pointMemberParser_), + 'pointMembers': ol.xml.makeArrayPusher( + ol.format.GML.prototype.pointMemberParser_) } }; @@ -440,25 +442,12 @@ ol.format.GML.MULTILINESTRING_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.GEOMETRY_PARSERS_ = { +ol.format.GML.MULTIPOLYGON_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'Point': ol.xml.makeReplacer(ol.format.GML.prototype.readPoint_), - 'MultiPoint': ol.xml.makeReplacer(ol.format.GML.prototype.readMultiPoint_), - 'LineString': ol.xml.makeReplacer(ol.format.GML.prototype.readLineString_), - 'MultiLineString': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiLineString_), - 'LinearRing' : ol.xml.makeReplacer( - ol.format.GML.prototype.readLinearRing_), - 'Polygon': ol.xml.makeReplacer(ol.format.GML.prototype.readPolygon_), - 'MultiPolygon': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiPolygon_), - 'Surface': ol.xml.makeReplacer(ol.format.GML.prototype.readSurface_), - 'MultiSurface': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiSurface_), - 'Curve': ol.xml.makeReplacer(ol.format.GML.prototype.readCurve_), - 'MultiCurve': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiCurve_), - 'Envelope': ol.xml.makeReplacer(ol.format.GML.prototype.readEnvelope_) + 'polygonMember': ol.xml.makeArrayPusher( + ol.format.GML.prototype.polygonMemberParser_), + 'polygonMembers': ol.xml.makeArrayPusher( + ol.format.GML.prototype.polygonMemberParser_) } }; @@ -494,12 +483,10 @@ ol.format.GML.LINESTRINGMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.MULTIPOINT_PARSERS_ = { +ol.format.GML.POLYGONMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'pointMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.pointMemberParser_), - 'pointMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.pointMemberParser_) + 'Polygon': ol.xml.makeArrayPusher( + ol.format.GML.prototype.readPolygon) } }; diff --git a/src/ol/format/gml/v2.js b/src/ol/format/gml/v2.js index 32b04137d5..5d147a25e2 100644 --- a/src/ol/format/gml/v2.js +++ b/src/ol/format/gml/v2.js @@ -151,3 +151,24 @@ ol.format.GML.v2.FLAT_LINEAR_RINGS_PARSERS_ = { 'outerBoundaryIs': ol.format.GML.v2.prototype.outerBoundaryIsParser_ } }; + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.v2.GEOMETRY_PARSERS_ = { + 'http://www.opengis.net/gml' : { + 'Point': ol.xml.makeReplacer(ol.format.GML.prototype.readPoint), + 'MultiPoint': ol.xml.makeReplacer(ol.format.GML.prototype.readMultiPoint), + 'LineString': ol.xml.makeReplacer(ol.format.GML.prototype.readLineString), + 'MultiLineString': ol.xml.makeReplacer( + ol.format.GML.prototype.readMultiLineString), + 'LinearRing' : ol.xml.makeReplacer( + ol.format.GML.prototype.readLinearRing), + 'Polygon': ol.xml.makeReplacer(ol.format.GML.prototype.readPolygon), + 'MultiPolygon': ol.xml.makeReplacer( + ol.format.GML.prototype.readMultiPolygon) + } +}; From 58485fc1f142f5e41809ae9d96a114a921aec6fc Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:15:45 +0200 Subject: [PATCH 19/31] Instanciate ol.format.GML.v3 by default in gml tests --- test/spec/ol/format/gmlformat.test.js | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 05fcd09388..5f6781ea1c 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -1,4 +1,4 @@ -goog.provide('ol.test.format.GML'); +goog.provide('ol.test.format.GML.v3'); var readGeometry = function(format, text, opt_options) { var doc = ol.xml.load(text); @@ -8,13 +8,15 @@ var readGeometry = function(format, text, opt_options) { return format.readGeometryFromNode(node, opt_options); }; -describe('ol.format.GML', function() { +describe('ol.format.GML.v3', function() { var format, formatWGS84, formatNoSrs; beforeEach(function() { - format = new ol.format.GML({srsName: 'CRS:84'}); - formatWGS84 = new ol.format.GML({srsName: 'urn:x-ogc:def:crs:EPSG:4326'}); - formatNoSrs = new ol.format.GML(); + format = new ol.format.GML.v3({srsName: 'CRS:84'}); + formatWGS84 = new ol.format.GML.v3({ + srsName: 'urn:x-ogc:def:crs:EPSG:4326' + }); + formatNoSrs = new ol.format.GML.v3(); }); describe('#readGeometry', function() { @@ -216,7 +218,8 @@ describe('ol.format.GML', function() { var g = readGeometry(format, text); expect(g.getCoordinates()[0][0][0][0]).to.equal(-77.0081); expect(g.getCoordinates()[0][0][0][1]).to.equal(38.9661); - format = new ol.format.GML({srsName: 'urn:x-ogc:def:crs:EPSG:4326', + format = new ol.format.GML.v3({ + srsName: 'urn:x-ogc:def:crs:EPSG:4326', surface: false}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); @@ -321,7 +324,7 @@ describe('ol.format.GML', function() { expect(g.getCoordinates()).to.eql([[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]], [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]]); - format = new ol.format.GML({srsName: 'CRS:84', surface: true}); + format = new ol.format.GML.v3({srsName: 'CRS:84', surface: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -343,7 +346,7 @@ describe('ol.format.GML', function() { var g = readGeometry(format, text); expect(g).to.be.an(ol.geom.LineString); expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]); - format = new ol.format.GML({srsName: 'CRS:84', curve: true}); + format = new ol.format.GML.v3({srsName: 'CRS:84', curve: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -438,7 +441,7 @@ describe('ol.format.GML', function() { expect(g).to.be.an(ol.geom.MultiLineString); expect(g.getCoordinates()).to.eql( [[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]); - format = new ol.format.GML({srsName: 'CRS:84', multiCurve: false}); + format = new ol.format.GML.v3({srsName: 'CRS:84', multiCurve: false}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -506,7 +509,7 @@ describe('ol.format.GML', function() { [1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]], [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]], [[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]); - format = new ol.format.GML({srsName: 'CRS:84', multiSurface: false}); + format = new ol.format.GML.v3({srsName: 'CRS:84', multiSurface: false}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -606,7 +609,7 @@ describe('ol.format.GML', function() { expect(g).to.be.an(ol.geom.MultiLineString); expect(g.getCoordinates()).to.eql( [[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]); - format = new ol.format.GML({srsName: 'CRS:84', curve: true}); + format = new ol.format.GML.v3({srsName: 'CRS:84', curve: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -749,7 +752,7 @@ describe('ol.format.GML', function() { [1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]], [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]], [[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]); - format = new ol.format.GML({srsName: 'CRS:84', surface: true}); + format = new ol.format.GML.v3({srsName: 'CRS:84', surface: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -781,7 +784,7 @@ describe('ol.format.GML', function() { 'featureNS': 'http://www.openplans.org/topp', 'featureType': 'gnis_pop' }; - var features = new ol.format.GML(config).readFeatures(text); + var features = new ol.format.GML.v3(config).readFeatures(text); var feature = features[0]; expect(feature.get('empty')).to.be(undefined); }); @@ -793,7 +796,7 @@ describe('ol.format.GML', function() { afterLoadText('spec/ol/format/gml/topp-states-wfs.xml', function(xml) { try { text = xml; - gmlFormat = new ol.format.GML(); + gmlFormat = new ol.format.GML.v3(); features = gmlFormat.readFeatures(xml); } catch (e) { done(e); @@ -858,7 +861,7 @@ describe('ol.format.GML', function() { 'schemaLocation': schemaLoc }; text = xml; - gmlFormat = new ol.format.GML(config); + gmlFormat = new ol.format.GML.v3(config); features = gmlFormat.readFeatures(xml); } catch (e) { done(e); @@ -892,7 +895,7 @@ describe('ol.format.GML', function() { 'featureNS': 'http://www.openplans.org/topp', 'featureType': 'states' }; - features = new ol.format.GML(config).readFeatures(xml); + features = new ol.format.GML.v3(config).readFeatures(xml); } catch (e) { done(e); } @@ -923,7 +926,7 @@ describe('ol.format.GML', function() { 'featureNS': 'http://opengeo.org/#medford', 'featureType': 'zoning' }; - features = new ol.format.GML(config).readFeatures(xml); + features = new ol.format.GML.v3(config).readFeatures(xml); } catch (e) { done(e); } @@ -949,7 +952,7 @@ describe('ol.format.GML', function() { 'featureNS': 'http://opengeo.org/#medford', 'featureType': 'zoning' }; - features = new ol.format.GML(config).readFeatures(xml); + features = new ol.format.GML.v3(config).readFeatures(xml); } catch (e) { done(e); } From d3ac01445effc7ff20d79eb17a128901955f3e54 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:16:20 +0200 Subject: [PATCH 20/31] Use by default instance of ol.format.GML.v3 in WFS format --- src/ol/format/wfsformat.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index bb4e2bab7f..5dd5d9903d 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -42,10 +42,10 @@ ol.format.WFS = function(opt_options) { /** * @private - * @type {string} + * @type {ol.format.GML} */ this.gmlFormat_ = goog.isDef(options.gmlFormat) ? - options.gmlFormat : new ol.format.GML(); + options.gmlFormat : new ol.format.GML.v3(); /** * @private @@ -223,7 +223,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) { goog.object.set(result, 'numberOfFeatures', value); return ol.xml.pushParseAndPop( /** @type {ol.format.WFS.FeatureCollectionMetadata} */ (result), - ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, []); + ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, [], this.gmlFormat_); }; @@ -371,7 +371,7 @@ ol.format.WFS.writeFeature_ = function(node, feature, objectStack) { var featureNS = goog.object.get(context, 'featureNS'); var child = ol.xml.createElementNS(featureNS, featureType); node.appendChild(child); - ol.format.GML.prototype.writeFeatureElement(child, feature, objectStack); + ol.format.GML.v3.prototype.writeFeatureElement(child, feature, objectStack); }; @@ -465,7 +465,7 @@ ol.format.WFS.writeProperty_ = function(node, pair, objectStack) { var value = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Value'); node.appendChild(value); if (pair.value instanceof ol.geom.Geometry) { - ol.format.GML.prototype.writeGeometryElement(value, + ol.format.GML.v3.prototype.writeGeometryElement(value, pair.value, objectStack); } else { ol.format.XSD.writeStringTextNode(value, pair.value); @@ -573,7 +573,7 @@ ol.format.WFS.writeOgcBBOX_ = function(node, bbox, objectStack) { var bboxNode = ol.xml.createElementNS('http://www.opengis.net/ogc', 'BBOX'); node.appendChild(bboxNode); ol.format.WFS.writeOgcPropertyName_(bboxNode, geometryName, objectStack); - ol.format.GML.prototype.writeGeometryElement(bboxNode, bbox, objectStack); + ol.format.GML.v3.prototype.writeGeometryElement(bboxNode, bbox, objectStack); }; @@ -755,7 +755,7 @@ ol.format.WFS.prototype.readProjectionFromNode = function(node) { (n.childNodes.length === 1 && n.firstChild.nodeType === 3))) { var objectStack = [{}]; - ol.format.GML.prototype.readGeometryElement(n, objectStack); + this.gmlFormat_.readGeometryElement(n, objectStack); return ol.proj.get(objectStack.pop().srsName); } } From 563174383a23a55fa567c2c4e365e04c3f759658 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 11:19:45 +0200 Subject: [PATCH 21/31] Merge GML versions tests in base GML suite --- test/spec/ol/format/gmlformat.test.js | 89 +++++++++++++++++++- test/spec/ol/format/gmlv2format.test.js | 103 ------------------------ 2 files changed, 88 insertions(+), 104 deletions(-) delete mode 100644 test/spec/ol/format/gmlv2format.test.js diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 5f6781ea1c..e189be53c0 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -1,4 +1,4 @@ -goog.provide('ol.test.format.GML.v3'); +goog.provide('ol.test.format.GML'); var readGeometry = function(format, text, opt_options) { var doc = ol.xml.load(text); @@ -8,6 +8,93 @@ var readGeometry = function(format, text, opt_options) { return format.readGeometryFromNode(node, opt_options); }; +describe('ol.format.GML.v2', function() { + + var format, formatWGS84, formatNoSrs; + beforeEach(function() { + format = new ol.format.GML.v2({srsName: 'CRS:84'}); + formatWGS84 = new ol.format.GML.v2({ + srsName: 'urn:x-ogc:def:crs:EPSG:4326' + }); + formatNoSrs = new ol.format.GML.v2(); + }); + + + describe('#readGeometry', function() { + + describe('gml 2.1.2', function() { + + it('can read a point geometry', function() { + var text = '' + + ' -90,-180' + + ''; + + var g = readGeometry(format, text); + expect(g).to.be.an(ol.geom.Point); + expect(g.getCoordinates()).to.eql([-180, -90, 0]); + }); + + it('can read a multipolygon with gml:coordinates', function() { + + var text = + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' -0.318987,47.003018 ' + + ' -0.768746,47.358268 ' + + ' -0.574463,47.684285 -0.347374,47.854602 ' + + ' -0.006740,47.925567 ' + + ' 0.135191,47.726864 0.149384,47.599127 0.419052,' + + ' 47.670092 0.532597,47.428810 ' + + ' 0.305508,47.443003 0.475824,47.144948 0.064225,' + + ' 47.201721 ' + + ' -0.318987,47.003018 ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' -0.035126,47.485582 -0.035126,' + + ' 47.485582 ' + + ' -0.049319,47.641706 -0.233829,47.655899 ' + + ' -0.375760,47.457196 ' + + ' -0.276408,47.286879 -0.035126,47.485582 ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + + var g = readGeometry(format, text); + expect(g).to.be.an(ol.geom.MultiPolygon); + expect(g.getCoordinates()).to.eql([ + [ + [ + [47.003018, -0.318987, 0], [47.358268, -0.768746, 0], + [47.684285, -0.574463, 0], [47.854602, -0.347374, 0], + [47.925567, -0.00674, 0], [47.726864, 0.135191, 0], + [47.599127, 0.149384, 0], [47.670092, 0.419052, 0], + [47.42881, 0.532597, 0], [47.443003, 0.305508, 0], + [47.144948, 0.475824, 0], [47.201721, 0.064225, 0], + [47.003018, -0.318987, 0] + ], + [ + [47.485582, -0.035126, 0], [47.485582, -0.035126, 0], + [47.641706, -0.049319, 0], [47.655899, -0.233829, 0], + [47.457196, -0.37576, 0], [47.286879, -0.276408, 0], + [47.485582, -0.035126, 0] + ] + ] + ]); + }); + }); + }); +}); + describe('ol.format.GML.v3', function() { var format, formatWGS84, formatNoSrs; diff --git a/test/spec/ol/format/gmlv2format.test.js b/test/spec/ol/format/gmlv2format.test.js deleted file mode 100644 index 5ff0e64ae5..0000000000 --- a/test/spec/ol/format/gmlv2format.test.js +++ /dev/null @@ -1,103 +0,0 @@ -goog.provide('ol.test.format.GML.v2'); - -var readGeometry = function(format, text, opt_options) { - var doc = ol.xml.load(text); - // we need an intermediate node for testing purposes - var node = goog.dom.createElement(goog.dom.TagName.PRE); - node.appendChild(doc.documentElement); - return format.readGeometryFromNode(node, opt_options); -}; - -describe('ol.format.GML.v2', function() { - - var format, formatWGS84, formatNoSrs; - beforeEach(function() { - format = new ol.format.GML.v2({srsName: 'CRS:84'}); - formatWGS84 = new ol.format.GML.v2({ - srsName: 'urn:x-ogc:def:crs:EPSG:4326' - }); - formatNoSrs = new ol.format.GML.v2(); - }); - - - describe('#readGeometry', function() { - - describe('gml 2.1.2', function() { - - it('can read a point geometry', function() { - var text = '' + - ' -90,-180' + - ''; - - var g = readGeometry(format, text); - expect(g).to.be.an(ol.geom.Point); - expect(g.getCoordinates()).to.eql([-180, -90, 0]); - }); - - it('can read a multipolygon with gml:coordinates', function() { - - var text = - '' + - ' ' + - ' ' + - ' ' + - ' ' + - ' -0.318987,47.003018 ' + - ' -0.768746,47.358268 ' + - ' -0.574463,47.684285 -0.347374,47.854602 ' + - ' -0.006740,47.925567 ' + - ' 0.135191,47.726864 0.149384,47.599127 0.419052,' + - ' 47.670092 0.532597,47.428810 ' + - ' 0.305508,47.443003 0.475824,47.144948 0.064225,' + - ' 47.201721 ' + - ' -0.318987,47.003018 ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' -0.035126,47.485582 -0.035126,' + - ' 47.485582 ' + - ' -0.049319,47.641706 -0.233829,47.655899 ' + - ' -0.375760,47.457196 ' + - ' -0.276408,47.286879 -0.035126,47.485582 ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ''; - - var g = readGeometry(format, text); - expect(g).to.be.an(ol.geom.MultiPolygon); - expect(g.getCoordinates()).to.eql([ - [ - [ - [47.003018, -0.318987, 0], [47.358268, -0.768746, 0], - [47.684285, -0.574463, 0], [47.854602, -0.347374, 0], - [47.925567, -0.00674, 0], [47.726864, 0.135191, 0], - [47.599127, 0.149384, 0], [47.670092, 0.419052, 0], - [47.42881, 0.532597, 0], [47.443003, 0.305508, 0], - [47.144948, 0.475824, 0], [47.201721, 0.064225, 0], - [47.003018, -0.318987, 0] - ], - [ - [47.485582, -0.035126, 0], [47.485582, -0.035126, 0], - [47.641706, -0.049319, 0], [47.655899, -0.233829, 0], - [47.457196, -0.37576, 0], [47.286879, -0.276408, 0], - [47.485582, -0.035126, 0] - ] - ] - ]); - }); - }); - }); -}); - -goog.require('goog.dom'); -goog.require('goog.dom.TagName'); -goog.require('ol.format.GML'); -goog.require('ol.geom.MultiPolygon'); -goog.require('ol.xml'); -goog.require('ol.geom.Point'); From 607543e4e70f81e2e12144946b8877fb09cfb231 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 14:51:49 +0200 Subject: [PATCH 22/31] Create an alias ol.format.GML to ol.format.GML3 for backward compatibility --- src/ol/format/gml/v3.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ol/format/gml/v3.js b/src/ol/format/gml/v3.js index 23ebd980b6..9ca794493d 100644 --- a/src/ol/format/gml/v3.js +++ b/src/ol/format/gml/v3.js @@ -72,6 +72,22 @@ ol.format.GML.v3 = function(opt_options) { goog.inherits(ol.format.GML.v3, ol.format.GML); + +/** + * @classdesc + * Feature format for reading and writing data in the GML format + * version 3.1.1. + * Currently only supports GML 3.1.1 Simple Features profile. + * + * @constructor + * @param {olx.format.GMLOptions=} opt_options + * Optional configuration object. + * @extends {ol.format.GMLBase} + * @api stable + */ +ol.format.GML = ol.format.GML3; + + /** * @const * @type {string} From 678c66f50c00da70485b2fc2cc76a7d3aa65c734 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Wed, 24 Sep 2014 14:54:26 +0200 Subject: [PATCH 23/31] Move GML subclasses to ol.format namespace to avoid issue with ol.format.GML alias ol.format.GMLBase ol.format.GML2 ol.format.GML3 --- externs/olx.js | 2 +- src/ol/format/gml/base.js | 131 +++++++------ src/ol/format/gml/v2.js | 51 ++--- src/ol/format/gml/v3.js | 271 +++++++++++++------------- src/ol/format/wfsformat.js | 19 +- test/spec/ol/format/gmlformat.test.js | 44 +++-- test/spec/ol/format/wfsformat.test.js | 5 +- 7 files changed, 269 insertions(+), 254 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index eb9455d462..8c9a601d71 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -1649,7 +1649,7 @@ olx.format.WFSWriteGetFeatureOptions.prototype.geometryName; /** * GML format to use within the WFS format. - * @type {ol.format.GML|undefined} + * @type {ol.format.GMLBase|undefined} * @api */ olx.format.WFSWriteGetFeatureOptions.prototype.gmlFormat; diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index d8df504013..594cd9c424 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -1,7 +1,7 @@ // FIXME Envelopes should not be treated as geometries! readEnvelope_ is part // of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect // envelopes/extents, only geometries! -goog.provide('ol.format.GML'); +goog.provide('ol.format.GMLBase'); goog.require('goog.asserts'); goog.require('goog.dom'); @@ -34,9 +34,9 @@ goog.require('ol.xml'); * @param {olx.format.GMLOptions=} opt_options * Optional configuration object. * @extends {ol.format.XMLFeature} - * @api stable + * @api */ -ol.format.GML = function(opt_options) { +ol.format.GMLBase = function(opt_options) { var options = /** @type {olx.format.GMLOptions} */ (goog.isDef(opt_options) ? opt_options : {}); @@ -67,7 +67,7 @@ ol.format.GML = function(opt_options) { goog.base(this); }; -goog.inherits(ol.format.GML, ol.format.XMLFeature); +goog.inherits(ol.format.GMLBase, ol.format.XMLFeature); /** @@ -76,13 +76,13 @@ goog.inherits(ol.format.GML, ol.format.XMLFeature); * @return {Array.} Features. * @private */ -ol.format.GML.prototype.readFeatures_ = function(node, objectStack) { +ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); var localName = ol.xml.getLocalName(node); var features; if (localName == 'FeatureCollection') { features = ol.xml.pushParseAndPop(null, - ol.format.GML.FEATURE_COLLECTION_PARSERS, node, + ol.format.GMLBase.FEATURE_COLLECTION_PARSERS, node, objectStack, this); } else if (localName == 'featureMembers' || localName == 'featureMember') { var context = objectStack[0]; @@ -112,11 +112,12 @@ ol.format.GML.prototype.readFeatures_ = function(node, objectStack) { /** * @type {Object.>} */ -ol.format.GML.FEATURE_COLLECTION_PARSERS = { +ol.format.GMLBase.FEATURE_COLLECTION_PARSERS = { 'http://www.opengis.net/gml': { 'featureMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readFeatures_), - 'featureMembers': ol.xml.makeReplacer(ol.format.GML.prototype.readFeatures_) + ol.format.GMLBase.prototype.readFeatures_), + 'featureMembers': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readFeatures_) } }; @@ -126,7 +127,7 @@ ol.format.GML.FEATURE_COLLECTION_PARSERS = { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.Geometry|undefined} Geometry. */ -ol.format.GML.prototype.readGeometryElement = function(node, objectStack) { +ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) { var context = objectStack[0]; goog.asserts.assert(goog.isObject(context)); goog.object.set(context, 'srsName', @@ -148,7 +149,7 @@ ol.format.GML.prototype.readGeometryElement = function(node, objectStack) { * @return {ol.Feature} Feature. * @private */ -ol.format.GML.prototype.readFeature_ = function(node, objectStack) { +ol.format.GMLBase.prototype.readFeature_ = function(node, objectStack) { var n; var fid = node.getAttribute('fid') || ol.xml.getAttributeNS(node, 'http://www.opengis.net/gml', 'id'); @@ -186,7 +187,7 @@ ol.format.GML.prototype.readFeature_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.Point|undefined} Point. */ -ol.format.GML.prototype.readPoint = function(node, objectStack) { +ol.format.GMLBase.prototype.readPoint = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Point'); var flatCoordinates = @@ -205,12 +206,12 @@ ol.format.GML.prototype.readPoint = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.MultiPoint|undefined} MultiPoint. */ -ol.format.GML.prototype.readMultiPoint = function(node, objectStack) { +ol.format.GMLBase.prototype.readMultiPoint = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiPoint'); var coordinates = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([]), - ol.format.GML.MULTIPOINT_PARSERS_, node, objectStack, this); + ol.format.GMLBase.MULTIPOINT_PARSERS_, node, objectStack, this); if (goog.isDef(coordinates)) { return new ol.geom.MultiPoint(coordinates); } else { @@ -224,12 +225,12 @@ ol.format.GML.prototype.readMultiPoint = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.MultiLineString|undefined} MultiLineString. */ -ol.format.GML.prototype.readMultiLineString = function(node, objectStack) { +ol.format.GMLBase.prototype.readMultiLineString = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiLineString'); var lineStrings = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.MULTILINESTRING_PARSERS_, node, objectStack, this); + ol.format.GMLBase.MULTILINESTRING_PARSERS_, node, objectStack, this); if (goog.isDef(lineStrings)) { var multiLineString = new ol.geom.MultiLineString(null); multiLineString.setLineStrings(lineStrings); @@ -245,12 +246,12 @@ ol.format.GML.prototype.readMultiLineString = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. */ -ol.format.GML.prototype.readMultiPolygon = function(node, objectStack) { +ol.format.GMLBase.prototype.readMultiPolygon = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiPolygon'); var polygons = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.MULTIPOLYGON_PARSERS_, node, objectStack, this); + ol.format.GMLBase.MULTIPOLYGON_PARSERS_, node, objectStack, this); if (goog.isDef(polygons)) { var multiPolygon = new ol.geom.MultiPolygon(null); multiPolygon.setPolygons(polygons); @@ -266,24 +267,11 @@ ol.format.GML.prototype.readMultiPolygon = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.prototype.pointMemberParser_ = function(node, objectStack) { +ol.format.GMLBase.prototype.pointMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'pointMember' || node.localName == 'pointMembers'); - ol.xml.parse(ol.format.GML.POINTMEMBER_PARSERS_, node, objectStack, this); -}; - - -/** - * @param {Node} node Node. - * @param {Array.<*>} objectStack Object stack. - * @private - */ -ol.format.GML.prototype.lineStringMemberParser_ = function(node, objectStack) { - goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'lineStringMember' || - node.localName == 'lineStringMembers'); - ol.xml.parse(ol.format.GML.LINESTRINGMEMBER_PARSERS_, + ol.xml.parse(ol.format.GMLBase.POINTMEMBER_PARSERS_, node, objectStack, this); }; @@ -293,11 +281,28 @@ ol.format.GML.prototype.lineStringMemberParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.prototype.polygonMemberParser_ = function(node, objectStack) { +ol.format.GMLBase.prototype.lineStringMemberParser_ = + function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'lineStringMember' || + node.localName == 'lineStringMembers'); + ol.xml.parse(ol.format.GMLBase.LINESTRINGMEMBER_PARSERS_, + node, objectStack, this); +}; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GMLBase.prototype.polygonMemberParser_ = + function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'polygonMember' || node.localName == 'polygonMembers'); - ol.xml.parse(ol.format.GML.POLYGONMEMBER_PARSERS_, node, objectStack, this); + ol.xml.parse(ol.format.GMLBase.POLYGONMEMBER_PARSERS_, node, + objectStack, this); }; @@ -306,7 +311,7 @@ ol.format.GML.prototype.polygonMemberParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.LineString|undefined} LineString. */ -ol.format.GML.prototype.readLineString = function(node, objectStack) { +ol.format.GMLBase.prototype.readLineString = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LineString'); var flatCoordinates = @@ -327,7 +332,7 @@ ol.format.GML.prototype.readLineString = function(node, objectStack) { * @private * @return {Array.|undefined} LinearRing flat coordinates. */ -ol.format.GML.prototype.readFlatLinearRing_ = function(node, objectStack) { +ol.format.GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var ring = ol.xml.pushParseAndPop(/** @type {Array.} */(null), @@ -346,7 +351,7 @@ ol.format.GML.prototype.readFlatLinearRing_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.LinearRing|undefined} LinearRing. */ -ol.format.GML.prototype.readLinearRing = function(node, objectStack) { +ol.format.GMLBase.prototype.readLinearRing = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var flatCoordinates = @@ -366,7 +371,7 @@ ol.format.GML.prototype.readLinearRing = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @return {ol.geom.Polygon|undefined} Polygon. */ -ol.format.GML.prototype.readPolygon = function(node, objectStack) { +ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Polygon'); var flatLinearRings = ol.xml.pushParseAndPop( @@ -397,8 +402,8 @@ ol.format.GML.prototype.readPolygon = function(node, objectStack) { * @private * @return {Array.} Flat coordinates. */ -ol.format.GML.prototype.readFlatCoordinatesFromNode_ = function(node, - objectStack) { +ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_ = + function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); return /** @type {Array.} */ (ol.xml.pushParseAndPop( null, @@ -412,12 +417,12 @@ ol.format.GML.prototype.readFlatCoordinatesFromNode_ = function(node, * @type {Object.>} * @private */ -ol.format.GML.MULTIPOINT_PARSERS_ = { +ol.format.GMLBase.MULTIPOINT_PARSERS_ = { 'http://www.opengis.net/gml' : { 'pointMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.pointMemberParser_), + ol.format.GMLBase.prototype.pointMemberParser_), 'pointMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.pointMemberParser_) + ol.format.GMLBase.prototype.pointMemberParser_) } }; @@ -427,12 +432,12 @@ ol.format.GML.MULTIPOINT_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.MULTILINESTRING_PARSERS_ = { +ol.format.GMLBase.MULTILINESTRING_PARSERS_ = { 'http://www.opengis.net/gml' : { 'lineStringMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.lineStringMemberParser_), + ol.format.GMLBase.prototype.lineStringMemberParser_), 'lineStringMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.lineStringMemberParser_) + ol.format.GMLBase.prototype.lineStringMemberParser_) } }; @@ -442,12 +447,12 @@ ol.format.GML.MULTILINESTRING_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.MULTIPOLYGON_PARSERS_ = { +ol.format.GMLBase.MULTIPOLYGON_PARSERS_ = { 'http://www.opengis.net/gml' : { 'polygonMember': ol.xml.makeArrayPusher( - ol.format.GML.prototype.polygonMemberParser_), + ol.format.GMLBase.prototype.polygonMemberParser_), 'polygonMembers': ol.xml.makeArrayPusher( - ol.format.GML.prototype.polygonMemberParser_) + ol.format.GMLBase.prototype.polygonMemberParser_) } }; @@ -457,10 +462,10 @@ ol.format.GML.MULTIPOLYGON_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.POINTMEMBER_PARSERS_ = { +ol.format.GMLBase.POINTMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readFlatCoordinatesFromNode_) + ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_) } }; @@ -470,10 +475,10 @@ ol.format.GML.POINTMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.LINESTRINGMEMBER_PARSERS_ = { +ol.format.GMLBase.LINESTRINGMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readLineString) + ol.format.GMLBase.prototype.readLineString) } }; @@ -483,10 +488,10 @@ ol.format.GML.LINESTRINGMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.POLYGONMEMBER_PARSERS_ = { +ol.format.GMLBase.POLYGONMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Polygon': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readPolygon) + ol.format.GMLBase.prototype.readPolygon) } }; @@ -496,10 +501,10 @@ ol.format.GML.POLYGONMEMBER_PARSERS_ = { * @type {Object.>} * @protected */ -ol.format.GML.RING_PARSERS = { +ol.format.GMLBase.RING_PARSERS = { 'http://www.opengis.net/gml' : { 'LinearRing': ol.xml.makeReplacer( - ol.format.GML.prototype.readFlatLinearRing_) + ol.format.GMLBase.prototype.readFlatLinearRing_) } }; @@ -507,7 +512,8 @@ ol.format.GML.RING_PARSERS = { /** * @inheritDoc */ -ol.format.GML.prototype.readGeometryFromNode = function(node, opt_options) { +ol.format.GMLBase.prototype.readGeometryFromNode = + function(node, opt_options) { var geometry = this.readGeometryElement(node, [this.getReadOptions(node, goog.isDef(opt_options) ? opt_options : {})]); return (goog.isDef(geometry) ? geometry : null); @@ -523,13 +529,14 @@ ol.format.GML.prototype.readGeometryFromNode = function(node, opt_options) { * @return {Array.} Features. * @api stable */ -ol.format.GML.prototype.readFeatures; +ol.format.GMLBase.prototype.readFeatures; /** * @inheritDoc */ -ol.format.GML.prototype.readFeaturesFromNode = function(node, opt_options) { +ol.format.GMLBase.prototype.readFeaturesFromNode = + function(node, opt_options) { var options = { 'featureType': this.featureType, 'featureNS': this.featureNS @@ -544,7 +551,7 @@ ol.format.GML.prototype.readFeaturesFromNode = function(node, opt_options) { /** * @inheritDoc */ -ol.format.GML.prototype.readProjectionFromNode = function(node) { +ol.format.GMLBase.prototype.readProjectionFromNode = function(node) { return ol.proj.get(goog.isDef(this.srsName_) ? this.srsName_ : node.firstElementChild.getAttribute('srsName')); }; diff --git a/src/ol/format/gml/v2.js b/src/ol/format/gml/v2.js index 5d147a25e2..4d676977aa 100644 --- a/src/ol/format/gml/v2.js +++ b/src/ol/format/gml/v2.js @@ -1,10 +1,11 @@ -goog.provide('ol.format.GML.v2'); +goog.provide('ol.format.GML2'); goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); goog.require('ol.format.GML'); +goog.require('ol.format.GMLBase'); goog.require('ol.format.XSD'); goog.require('ol.proj'); goog.require('ol.xml'); @@ -19,14 +20,14 @@ goog.require('ol.xml'); * @constructor * @param {olx.format.GMLOptions=} opt_options * Optional configuration object. - * @extends {ol.format.GML} - * @api stable + * @extends {ol.format.GMLBase} + * @api */ -ol.format.GML.v2 = function(opt_options) { +ol.format.GML2 = function(opt_options) { goog.base(this, opt_options); }; -goog.inherits(ol.format.GML.v2, ol.format.GML); +goog.inherits(ol.format.GML2, ol.format.GMLBase); /** @@ -34,7 +35,7 @@ goog.inherits(ol.format.GML.v2, ol.format.GML); * @private * @type {string} */ -ol.format.GML.v2.schemaLocation_ = 'http://www.opengis.net/gml ' + +ol.format.GML2.schemaLocation_ = 'http://www.opengis.net/gml ' + 'http://schemas.opengis.net/gml/2.1.2/feature.xsd'; @@ -44,7 +45,7 @@ ol.format.GML.v2.schemaLocation_ = 'http://www.opengis.net/gml ' + * @private * @return {Array.|undefined} Flat coordinates. */ -ol.format.GML.v2.prototype.readFlatCoordinates_ = function(node, objectStack) { +ol.format.GML2.prototype.readFlatCoordinates_ = function(node, objectStack) { var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, ''); var context = objectStack[0]; goog.asserts.assert(goog.isObject(context)); @@ -88,13 +89,13 @@ ol.format.GML.v2.prototype.readFlatCoordinates_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.v2.prototype.innerBoundaryIsParser_ = +ol.format.GML2.prototype.innerBoundaryIsParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'innerBoundaryIs'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS, node, objectStack, this); + ol.format.GMLBase.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -110,13 +111,13 @@ ol.format.GML.v2.prototype.innerBoundaryIsParser_ = * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.v2.prototype.outerBoundaryIsParser_ = +ol.format.GML2.prototype.outerBoundaryIsParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'outerBoundaryIs'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS, node, objectStack, this); + ol.format.GMLBase.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -132,10 +133,10 @@ ol.format.GML.v2.prototype.outerBoundaryIsParser_ = * @type {Object.>} * @private */ -ol.format.GML.v2.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { +ol.format.GML2.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { 'http://www.opengis.net/gml' : { 'coordinates': ol.xml.makeReplacer( - ol.format.GML.v2.prototype.readFlatCoordinates_) + ol.format.GML2.prototype.readFlatCoordinates_) } }; @@ -145,10 +146,10 @@ ol.format.GML.v2.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v2.FLAT_LINEAR_RINGS_PARSERS_ = { +ol.format.GML2.FLAT_LINEAR_RINGS_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'innerBoundaryIs': ol.format.GML.v2.prototype.innerBoundaryIsParser_, - 'outerBoundaryIs': ol.format.GML.v2.prototype.outerBoundaryIsParser_ + 'innerBoundaryIs': ol.format.GML2.prototype.innerBoundaryIsParser_, + 'outerBoundaryIs': ol.format.GML2.prototype.outerBoundaryIsParser_ } }; @@ -158,17 +159,19 @@ ol.format.GML.v2.FLAT_LINEAR_RINGS_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v2.GEOMETRY_PARSERS_ = { +ol.format.GML2.GEOMETRY_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'Point': ol.xml.makeReplacer(ol.format.GML.prototype.readPoint), - 'MultiPoint': ol.xml.makeReplacer(ol.format.GML.prototype.readMultiPoint), - 'LineString': ol.xml.makeReplacer(ol.format.GML.prototype.readLineString), + 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint), + 'MultiPoint': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readMultiPoint), + 'LineString': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readLineString), 'MultiLineString': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiLineString), + ol.format.GMLBase.prototype.readMultiLineString), 'LinearRing' : ol.xml.makeReplacer( - ol.format.GML.prototype.readLinearRing), - 'Polygon': ol.xml.makeReplacer(ol.format.GML.prototype.readPolygon), + ol.format.GMLBase.prototype.readLinearRing), + 'Polygon': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPolygon), 'MultiPolygon': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiPolygon) + ol.format.GMLBase.prototype.readMultiPolygon) } }; diff --git a/src/ol/format/gml/v3.js b/src/ol/format/gml/v3.js index 9ca794493d..79534e49cb 100644 --- a/src/ol/format/gml/v3.js +++ b/src/ol/format/gml/v3.js @@ -1,4 +1,5 @@ -goog.provide('ol.format.GML.v3'); +goog.provide('ol.format.GML'); +goog.provide('ol.format.GML3'); goog.require('goog.asserts'); goog.require('goog.dom'); @@ -8,7 +9,7 @@ goog.require('ol.Feature'); goog.require('ol.array'); goog.require('ol.extent'); goog.require('ol.format.Feature'); -goog.require('ol.format.GML'); +goog.require('ol.format.GMLBase'); goog.require('ol.format.XSD'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.LineString'); @@ -31,10 +32,10 @@ goog.require('ol.xml'); * @constructor * @param {olx.format.GMLOptions=} opt_options * Optional configuration object. - * @extends {ol.format.GML} - * @api stable + * @extends {ol.format.GMLBase} + * @api */ -ol.format.GML.v3 = function(opt_options) { +ol.format.GML3 = function(opt_options) { var options = /** @type {olx.format.GMLOptions} */ (goog.isDef(opt_options) ? opt_options : {}); @@ -69,7 +70,7 @@ ol.format.GML.v3 = function(opt_options) { goog.base(this, opt_options); }; -goog.inherits(ol.format.GML.v3, ol.format.GML); +goog.inherits(ol.format.GML3, ol.format.GMLBase); @@ -93,7 +94,7 @@ ol.format.GML = ol.format.GML3; * @type {string} * @private */ -ol.format.GML.v3.schemaLocation_ = 'http://www.opengis.net/gml ' + +ol.format.GML3.schemaLocation_ = 'http://www.opengis.net/gml ' + 'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' + '1.0.0/gmlsf.xsd'; @@ -104,12 +105,12 @@ ol.format.GML.v3.schemaLocation_ = 'http://www.opengis.net/gml ' + * @private * @return {ol.geom.MultiLineString|undefined} MultiLineString. */ -ol.format.GML.v3.prototype.readMultiCurve_ = function(node, objectStack) { +ol.format.GML3.prototype.readMultiCurve_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiCurve'); var lineStrings = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.v3.MULTICURVE_PARSERS_, node, objectStack, this); + ol.format.GML3.MULTICURVE_PARSERS_, node, objectStack, this); if (goog.isDef(lineStrings)) { var multiLineString = new ol.geom.MultiLineString(null); multiLineString.setLineStrings(lineStrings); @@ -126,12 +127,12 @@ ol.format.GML.v3.prototype.readMultiCurve_ = function(node, objectStack) { * @private * @return {ol.geom.MultiPolygon|undefined} MultiPolygon. */ -ol.format.GML.v3.prototype.readMultiSurface_ = function(node, objectStack) { +ol.format.GML3.prototype.readMultiSurface_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'MultiSurface'); var polygons = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML.v3.MULTISURFACE_PARSERS_, node, objectStack, this); + ol.format.GML3.MULTISURFACE_PARSERS_, node, objectStack, this); if (goog.isDef(polygons)) { var multiPolygon = new ol.geom.MultiPolygon(null); multiPolygon.setPolygons(polygons); @@ -147,11 +148,11 @@ ol.format.GML.v3.prototype.readMultiSurface_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.v3.prototype.curveMemberParser_ = function(node, objectStack) { +ol.format.GML3.prototype.curveMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'curveMember' || node.localName == 'curveMembers'); - ol.xml.parse(ol.format.GML.v3.CURVEMEMBER_PARSERS_, node, objectStack, this); + ol.xml.parse(ol.format.GML3.CURVEMEMBER_PARSERS_, node, objectStack, this); }; @@ -160,11 +161,11 @@ ol.format.GML.v3.prototype.curveMemberParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.v3.prototype.surfaceMemberParser_ = function(node, objectStack) { +ol.format.GML3.prototype.surfaceMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'surfaceMember' || node.localName == 'surfaceMembers'); - ol.xml.parse(ol.format.GML.v3.SURFACEMEMBER_PARSERS_, + ol.xml.parse(ol.format.GML3.SURFACEMEMBER_PARSERS_, node, objectStack, this); }; @@ -175,12 +176,12 @@ ol.format.GML.v3.prototype.surfaceMemberParser_ = function(node, objectStack) { * @private * @return {Array.<(Array.)>|undefined} flat coordinates. */ -ol.format.GML.v3.prototype.readPatch_ = function(node, objectStack) { +ol.format.GML3.prototype.readPatch_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'patches'); return ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML.v3.PATCHES_PARSERS_, node, objectStack, this); + ol.format.GML3.PATCHES_PARSERS_, node, objectStack, this); }; @@ -190,12 +191,12 @@ ol.format.GML.v3.prototype.readPatch_ = function(node, objectStack) { * @private * @return {Array.|undefined} flat coordinates. */ -ol.format.GML.v3.prototype.readSegment_ = function(node, objectStack) { +ol.format.GML3.prototype.readSegment_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'segments'); return ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML.v3.SEGMENTS_PARSERS_, node, objectStack, this); + ol.format.GML3.SEGMENTS_PARSERS_, node, objectStack, this); }; @@ -205,7 +206,7 @@ ol.format.GML.v3.prototype.readSegment_ = function(node, objectStack) { * @private * @return {Array.<(Array.)>|undefined} flat coordinates. */ -ol.format.GML.v3.prototype.readPolygonPatch_ = function(node, objectStack) { +ol.format.GML3.prototype.readPolygonPatch_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'PolygonPatch'); return ol.xml.pushParseAndPop( @@ -220,7 +221,7 @@ ol.format.GML.v3.prototype.readPolygonPatch_ = function(node, objectStack) { * @private * @return {Array.|undefined} flat coordinates. */ -ol.format.GML.v3.prototype.readLineStringSegment_ = +ol.format.GML3.prototype.readLineStringSegment_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LineStringSegment'); @@ -236,12 +237,12 @@ ol.format.GML.v3.prototype.readLineStringSegment_ = * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.v3.prototype.interiorParser_ = function(node, objectStack) { +ol.format.GML3.prototype.interiorParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'interior'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS, node, objectStack, this); + ol.format.GMLBase.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -257,12 +258,12 @@ ol.format.GML.v3.prototype.interiorParser_ = function(node, objectStack) { * @param {Array.<*>} objectStack Object stack. * @private */ -ol.format.GML.v3.prototype.exteriorParser_ = function(node, objectStack) { +ol.format.GML3.prototype.exteriorParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'exterior'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GML.RING_PARSERS, node, objectStack, this); + ol.format.GMLBase.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -279,12 +280,12 @@ ol.format.GML.v3.prototype.exteriorParser_ = function(node, objectStack) { * @private * @return {ol.geom.Polygon|undefined} Polygon. */ -ol.format.GML.v3.prototype.readSurface_ = function(node, objectStack) { +ol.format.GML3.prototype.readSurface_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Surface'); var flatLinearRings = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML.v3.SURFACE_PARSERS_, node, objectStack, this); + ol.format.GML3.SURFACE_PARSERS_, node, objectStack, this); if (goog.isDef(flatLinearRings) && !goog.isNull(flatLinearRings[0])) { var polygon = new ol.geom.Polygon(null); @@ -310,12 +311,12 @@ ol.format.GML.v3.prototype.readSurface_ = function(node, objectStack) { * @private * @return {ol.geom.LineString|undefined} LineString. */ -ol.format.GML.v3.prototype.readCurve_ = function(node, objectStack) { +ol.format.GML3.prototype.readCurve_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Curve'); var flatCoordinates = ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML.v3.CURVE_PARSERS_, node, objectStack, this); + ol.format.GML3.CURVE_PARSERS_, node, objectStack, this); if (goog.isDef(flatCoordinates)) { var lineString = new ol.geom.LineString(null); lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates); @@ -332,12 +333,12 @@ ol.format.GML.v3.prototype.readCurve_ = function(node, objectStack) { * @private * @return {ol.Extent|undefined} Envelope. */ -ol.format.GML.v3.prototype.readEnvelope_ = function(node, objectStack) { +ol.format.GML3.prototype.readEnvelope_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'Envelope'); var flatCoordinates = ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML.v3.ENVELOPE_PARSERS_, node, objectStack, this); + ol.format.GML3.ENVELOPE_PARSERS_, node, objectStack, this); return ol.extent.createOrUpdate(flatCoordinates[1][0], flatCoordinates[1][1], flatCoordinates[2][0], flatCoordinates[2][1]); @@ -350,7 +351,7 @@ ol.format.GML.v3.prototype.readEnvelope_ = function(node, objectStack) { * @private * @return {Array.|undefined} Flat coordinates. */ -ol.format.GML.v3.prototype.readFlatPos_ = function(node, objectStack) { +ol.format.GML3.prototype.readFlatPos_ = function(node, objectStack) { var s = ol.xml.getAllTextContent(node, false); var re = /^\s*([+\-]?\d*\.?\d+(?:[eE][+\-]?\d+)?)\s*/; /** @type {Array.} */ @@ -397,7 +398,7 @@ ol.format.GML.v3.prototype.readFlatPos_ = function(node, objectStack) { * @private * @return {Array.|undefined} Flat coordinates. */ -ol.format.GML.v3.prototype.readFlatPosList_ = 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)); @@ -441,10 +442,10 @@ ol.format.GML.v3.prototype.readFlatPosList_ = function(node, objectStack) { * @type {Object.>} * @private */ -ol.format.GML.v3.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { +ol.format.GML3.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'pos': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readFlatPos_), - 'posList': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readFlatPosList_) + 'pos': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPos_), + 'posList': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPosList_) } }; @@ -454,10 +455,10 @@ ol.format.GML.v3.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.FLAT_LINEAR_RINGS_PARSERS_ = { +ol.format.GML3.FLAT_LINEAR_RINGS_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'interior': ol.format.GML.v3.prototype.interiorParser_, - 'exterior': ol.format.GML.v3.prototype.exteriorParser_ + 'interior': ol.format.GML3.prototype.interiorParser_, + 'exterior': ol.format.GML3.prototype.exteriorParser_ } }; @@ -467,25 +468,27 @@ ol.format.GML.v3.FLAT_LINEAR_RINGS_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.GEOMETRY_PARSERS_ = { +ol.format.GML3.GEOMETRY_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'Point': ol.xml.makeReplacer(ol.format.GML.prototype.readPoint), - 'MultiPoint': ol.xml.makeReplacer(ol.format.GML.prototype.readMultiPoint), - 'LineString': ol.xml.makeReplacer(ol.format.GML.prototype.readLineString), + 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint), + 'MultiPoint': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readMultiPoint), + 'LineString': ol.xml.makeReplacer( + ol.format.GMLBase.prototype.readLineString), 'MultiLineString': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiLineString), + ol.format.GMLBase.prototype.readMultiLineString), 'LinearRing' : ol.xml.makeReplacer( - ol.format.GML.prototype.readLinearRing), - 'Polygon': ol.xml.makeReplacer(ol.format.GML.prototype.readPolygon), + ol.format.GMLBase.prototype.readLinearRing), + 'Polygon': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPolygon), 'MultiPolygon': ol.xml.makeReplacer( - ol.format.GML.prototype.readMultiPolygon), - 'Surface': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readSurface_), + ol.format.GMLBase.prototype.readMultiPolygon), + 'Surface': ol.xml.makeReplacer(ol.format.GML3.prototype.readSurface_), 'MultiSurface': ol.xml.makeReplacer( - ol.format.GML.v3.prototype.readMultiSurface_), - 'Curve': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readCurve_), + ol.format.GML3.prototype.readMultiSurface_), + 'Curve': ol.xml.makeReplacer(ol.format.GML3.prototype.readCurve_), 'MultiCurve': ol.xml.makeReplacer( - ol.format.GML.v3.prototype.readMultiCurve_), - 'Envelope': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readEnvelope_) + ol.format.GML3.prototype.readMultiCurve_), + 'Envelope': ol.xml.makeReplacer(ol.format.GML3.prototype.readEnvelope_) } }; @@ -495,12 +498,12 @@ ol.format.GML.v3.GEOMETRY_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.MULTICURVE_PARSERS_ = { +ol.format.GML3.MULTICURVE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'curveMember': ol.xml.makeArrayPusher( - ol.format.GML.v3.prototype.curveMemberParser_), + ol.format.GML3.prototype.curveMemberParser_), 'curveMembers': ol.xml.makeArrayPusher( - ol.format.GML.v3.prototype.curveMemberParser_) + ol.format.GML3.prototype.curveMemberParser_) } }; @@ -510,12 +513,12 @@ ol.format.GML.v3.MULTICURVE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.MULTISURFACE_PARSERS_ = { +ol.format.GML3.MULTISURFACE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'surfaceMember': ol.xml.makeArrayPusher( - ol.format.GML.v3.prototype.surfaceMemberParser_), + ol.format.GML3.prototype.surfaceMemberParser_), 'surfaceMembers': ol.xml.makeArrayPusher( - ol.format.GML.v3.prototype.surfaceMemberParser_) + ol.format.GML3.prototype.surfaceMemberParser_) } }; @@ -525,11 +528,11 @@ ol.format.GML.v3.MULTISURFACE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.CURVEMEMBER_PARSERS_ = { +ol.format.GML3.CURVEMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( - ol.format.GML.prototype.readLineString), - 'Curve': ol.xml.makeArrayPusher(ol.format.GML.v3.prototype.readCurve_) + ol.format.GMLBase.prototype.readLineString), + 'Curve': ol.xml.makeArrayPusher(ol.format.GML3.prototype.readCurve_) } }; @@ -539,10 +542,10 @@ ol.format.GML.v3.CURVEMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.SURFACEMEMBER_PARSERS_ = { +ol.format.GML3.SURFACEMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'Polygon': ol.xml.makeArrayPusher(ol.format.GML.prototype.readPolygon), - 'Surface': ol.xml.makeArrayPusher(ol.format.GML.v3.prototype.readSurface_) + 'Polygon': ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readPolygon), + 'Surface': ol.xml.makeArrayPusher(ol.format.GML3.prototype.readSurface_) } }; @@ -552,9 +555,9 @@ ol.format.GML.v3.SURFACEMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.SURFACE_PARSERS_ = { +ol.format.GML3.SURFACE_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'patches': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readPatch_) + 'patches': ol.xml.makeReplacer(ol.format.GML3.prototype.readPatch_) } }; @@ -564,9 +567,9 @@ ol.format.GML.v3.SURFACE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.CURVE_PARSERS_ = { +ol.format.GML3.CURVE_PARSERS_ = { 'http://www.opengis.net/gml' : { - 'segments': ol.xml.makeReplacer(ol.format.GML.v3.prototype.readSegment_) + 'segments': ol.xml.makeReplacer(ol.format.GML3.prototype.readSegment_) } }; @@ -576,12 +579,12 @@ ol.format.GML.v3.CURVE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.ENVELOPE_PARSERS_ = { +ol.format.GML3.ENVELOPE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'lowerCorner': ol.xml.makeArrayPusher( - ol.format.GML.v3.prototype.readFlatPosList_), + ol.format.GML3.prototype.readFlatPosList_), 'upperCorner': ol.xml.makeArrayPusher( - ol.format.GML.v3.prototype.readFlatPosList_) + ol.format.GML3.prototype.readFlatPosList_) } }; @@ -591,10 +594,10 @@ ol.format.GML.v3.ENVELOPE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.PATCHES_PARSERS_ = { +ol.format.GML3.PATCHES_PARSERS_ = { 'http://www.opengis.net/gml' : { 'PolygonPatch': ol.xml.makeReplacer( - ol.format.GML.v3.prototype.readPolygonPatch_) + ol.format.GML3.prototype.readPolygonPatch_) } }; @@ -604,10 +607,10 @@ ol.format.GML.v3.PATCHES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.SEGMENTS_PARSERS_ = { +ol.format.GML3.SEGMENTS_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineStringSegment': ol.xml.makeReplacer( - ol.format.GML.v3.prototype.readLineStringSegment_) + ol.format.GML3.prototype.readLineStringSegment_) } }; @@ -618,7 +621,7 @@ ol.format.GML.v3.SEGMENTS_PARSERS_ = { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writePos_ = function(node, value, objectStack) { +ol.format.GML3.prototype.writePos_ = function(node, value, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -644,7 +647,7 @@ ol.format.GML.v3.prototype.writePos_ = function(node, value, objectStack) { * @return {string} * @private */ -ol.format.GML.v3.prototype.getCoords_ = function(point, opt_srsName) { +ol.format.GML3.prototype.getCoords_ = function(point, opt_srsName) { var axisOrientation = 'enu'; if (goog.isDefAndNotNull(opt_srsName)) { axisOrientation = ol.proj.get(opt_srsName).getAxisOrientation(); @@ -661,7 +664,7 @@ ol.format.GML.v3.prototype.getCoords_ = function(point, opt_srsName) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writePosList_ = function(node, value, objectStack) { +ol.format.GML3.prototype.writePosList_ = function(node, value, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -684,7 +687,7 @@ ol.format.GML.v3.prototype.writePosList_ = function(node, value, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writePoint_ = function(node, geometry, objectStack) { +ol.format.GML3.prototype.writePoint_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); var srsName = goog.object.get(context, 'srsName'); @@ -701,7 +704,7 @@ ol.format.GML.v3.prototype.writePoint_ = function(node, geometry, objectStack) { * @type {Object.>} * @private */ -ol.format.GML.v3.ENVELOPE_SERIALIZERS_ = { +ol.format.GML3.ENVELOPE_SERIALIZERS_ = { 'http://www.opengis.net/gml': { 'lowerCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode), 'upperCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode) @@ -714,7 +717,7 @@ ol.format.GML.v3.ENVELOPE_SERIALIZERS_ = { * @param {ol.Extent} extent Extent. * @param {Array.<*>} objectStack Node stack. */ -ol.format.GML.v3.prototype.writeEnvelope = function(node, extent, objectStack) { +ol.format.GML3.prototype.writeEnvelope = function(node, extent, objectStack) { goog.asserts.assert(extent.length == 4); var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -725,7 +728,7 @@ ol.format.GML.v3.prototype.writeEnvelope = function(node, extent, objectStack) { var keys = ['lowerCorner', 'upperCorner']; var values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]]; ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ - ({node: node}), ol.format.GML.v3.ENVELOPE_SERIALIZERS_, + ({node: node}), ol.format.GML3.ENVELOPE_SERIALIZERS_, ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, keys, this); @@ -738,7 +741,7 @@ ol.format.GML.v3.prototype.writeEnvelope = function(node, extent, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeLinearRing_ = +ol.format.GML3.prototype.writeLinearRing_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -759,7 +762,7 @@ ol.format.GML.v3.prototype.writeLinearRing_ = * @return {Node} Node. * @private */ -ol.format.GML.v3.prototype.RING_NODE_FACTORY_ = +ol.format.GML3.prototype.RING_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) { var context = objectStack[objectStack.length - 1]; var parentNode = context.node; @@ -779,7 +782,7 @@ ol.format.GML.v3.prototype.RING_NODE_FACTORY_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeSurfaceOrPolygon_ = +ol.format.GML3.prototype.writeSurfaceOrPolygon_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -791,7 +794,7 @@ ol.format.GML.v3.prototype.writeSurfaceOrPolygon_ = var rings = geometry.getLinearRings(); ol.xml.pushSerializeAndPop( {node: node, srsName: srsName}, - ol.format.GML.v3.RING_SERIALIZERS_, + ol.format.GML3.RING_SERIALIZERS_, this.RING_NODE_FACTORY_, rings, objectStack, undefined, this); } else if (node.nodeName === 'Surface') { @@ -809,7 +812,7 @@ ol.format.GML.v3.prototype.writeSurfaceOrPolygon_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeCurveOrLineString_ = +ol.format.GML3.prototype.writeCurveOrLineString_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -838,7 +841,7 @@ ol.format.GML.v3.prototype.writeCurveOrLineString_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_ = +ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -849,7 +852,7 @@ ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_ = } var polygons = geometry.getPolygons(); ol.xml.pushSerializeAndPop({node: node, srsName: srsName, surface: surface}, - ol.format.GML.v3.SURFACEORPOLYGONMEMBER_SERIALIZERS_, + ol.format.GML3.SURFACEORPOLYGONMEMBER_SERIALIZERS_, this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons, objectStack, undefined, this); }; @@ -861,7 +864,7 @@ ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeMultiPoint_ = function(node, geometry, +ol.format.GML3.prototype.writeMultiPoint_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -871,7 +874,7 @@ ol.format.GML.v3.prototype.writeMultiPoint_ = function(node, geometry, } var points = geometry.getPoints(); ol.xml.pushSerializeAndPop({node: node, srsName: srsName}, - ol.format.GML.v3.POINTMEMBER_SERIALIZERS_, + ol.format.GML3.POINTMEMBER_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('pointMember'), points, objectStack, undefined, this); }; @@ -883,7 +886,7 @@ ol.format.GML.v3.prototype.writeMultiPoint_ = function(node, geometry, * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeMultiCurveOrLineString_ = +ol.format.GML3.prototype.writeMultiCurveOrLineString_ = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -894,7 +897,7 @@ ol.format.GML.v3.prototype.writeMultiCurveOrLineString_ = } var lines = geometry.getLineStrings(); ol.xml.pushSerializeAndPop({node: node, srsName: srsName, curve: curve}, - ol.format.GML.v3.LINESTRINGORCURVEMEMBER_SERIALIZERS_, + ol.format.GML3.LINESTRINGORCURVEMEMBER_SERIALIZERS_, this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines, objectStack, undefined, this); }; @@ -906,7 +909,7 @@ ol.format.GML.v3.prototype.writeMultiCurveOrLineString_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeRing_ = function(node, ring, objectStack) { +ol.format.GML3.prototype.writeRing_ = function(node, ring, objectStack) { var linearRing = ol.xml.createElementNS(node.namespaceURI, 'LinearRing'); node.appendChild(linearRing); this.writeLinearRing_(linearRing, ring, objectStack); @@ -919,7 +922,7 @@ ol.format.GML.v3.prototype.writeRing_ = function(node, ring, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeSurfaceOrPolygonMember_ = +ol.format.GML3.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -938,7 +941,7 @@ ol.format.GML.v3.prototype.writeSurfaceOrPolygonMember_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writePointMember_ = +ol.format.GML3.prototype.writePointMember_ = function(node, point, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'Point'); node.appendChild(child); @@ -952,7 +955,7 @@ ol.format.GML.v3.prototype.writePointMember_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeLineStringOrCurveMember_ = +ol.format.GML3.prototype.writeLineStringOrCurveMember_ = function(node, line, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -970,7 +973,7 @@ ol.format.GML.v3.prototype.writeLineStringOrCurveMember_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeSurfacePatches_ = +ol.format.GML3.prototype.writeSurfacePatches_ = function(node, polygon, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'PolygonPatch'); node.appendChild(child); @@ -984,7 +987,7 @@ ol.format.GML.v3.prototype.writeSurfacePatches_ = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeCurveSegments_ = +ol.format.GML3.prototype.writeCurveSegments_ = function(node, line, objectStack) { var child = ol.xml.createElementNS(node.namespaceURI, 'LineStringSegment'); @@ -998,7 +1001,7 @@ ol.format.GML.v3.prototype.writeCurveSegments_ = * @param {ol.geom.Geometry|ol.Extent} geometry Geometry. * @param {Array.<*>} objectStack Node stack. */ -ol.format.GML.v3.prototype.writeGeometryElement = +ol.format.GML3.prototype.writeGeometryElement = function(node, geometry, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1018,7 +1021,7 @@ ol.format.GML.v3.prototype.writeGeometryElement = ol.format.Feature.transformWithOptions(geometry, true, context); } ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ - (item), ol.format.GML.v3.GEOMETRY_SERIALIZERS_, + (item), ol.format.GML3.GEOMETRY_SERIALIZERS_, this.GEOMETRY_NODE_FACTORY_, [value], objectStack, undefined, this); }; @@ -1029,7 +1032,7 @@ ol.format.GML.v3.prototype.writeGeometryElement = * @param {ol.Feature} feature Feature. * @param {Array.<*>} objectStack Node stack. */ -ol.format.GML.v3.prototype.writeFeatureElement = +ol.format.GML3.prototype.writeFeatureElement = function(node, feature, objectStack) { var fid = feature.getId(); if (goog.isDef(fid)) { @@ -1079,7 +1082,7 @@ ol.format.GML.v3.prototype.writeFeatureElement = * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML.v3.prototype.writeFeatureMembers_ = +ol.format.GML3.prototype.writeFeatureMembers_ = function(node, features, objectStack) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1103,12 +1106,12 @@ ol.format.GML.v3.prototype.writeFeatureMembers_ = * @type {Object.>} * @private */ -ol.format.GML.v3.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = { +ol.format.GML3.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = { 'http://www.opengis.net/gml': { 'surfaceMember': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeSurfaceOrPolygonMember_), + ol.format.GML3.prototype.writeSurfaceOrPolygonMember_), 'polygonMember': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeSurfaceOrPolygonMember_) + ol.format.GML3.prototype.writeSurfaceOrPolygonMember_) } }; @@ -1117,10 +1120,10 @@ ol.format.GML.v3.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.POINTMEMBER_SERIALIZERS_ = { +ol.format.GML3.POINTMEMBER_SERIALIZERS_ = { 'http://www.opengis.net/gml': { 'pointMember': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writePointMember_) + ol.format.GML3.prototype.writePointMember_) } }; @@ -1129,12 +1132,12 @@ ol.format.GML.v3.POINTMEMBER_SERIALIZERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = { +ol.format.GML3.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = { 'http://www.opengis.net/gml': { 'lineStringMember': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeLineStringOrCurveMember_), + ol.format.GML3.prototype.writeLineStringOrCurveMember_), 'curveMember': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeLineStringOrCurveMember_) + ol.format.GML3.prototype.writeLineStringOrCurveMember_) } }; @@ -1143,10 +1146,10 @@ ol.format.GML.v3.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.RING_SERIALIZERS_ = { +ol.format.GML3.RING_SERIALIZERS_ = { 'http://www.opengis.net/gml': { - 'exterior': ol.xml.makeChildAppender(ol.format.GML.v3.prototype.writeRing_), - 'interior': ol.xml.makeChildAppender(ol.format.GML.v3.prototype.writeRing_) + 'exterior': ol.xml.makeChildAppender(ol.format.GML3.prototype.writeRing_), + 'interior': ol.xml.makeChildAppender(ol.format.GML3.prototype.writeRing_) } }; @@ -1155,31 +1158,31 @@ ol.format.GML.v3.RING_SERIALIZERS_ = { * @type {Object.>} * @private */ -ol.format.GML.v3.GEOMETRY_SERIALIZERS_ = { +ol.format.GML3.GEOMETRY_SERIALIZERS_ = { 'http://www.opengis.net/gml': { 'Curve': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeCurveOrLineString_), + ol.format.GML3.prototype.writeCurveOrLineString_), 'MultiCurve': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeMultiCurveOrLineString_), - 'Point': ol.xml.makeChildAppender(ol.format.GML.v3.prototype.writePoint_), + ol.format.GML3.prototype.writeMultiCurveOrLineString_), + 'Point': ol.xml.makeChildAppender(ol.format.GML3.prototype.writePoint_), 'MultiPoint': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeMultiPoint_), + ol.format.GML3.prototype.writeMultiPoint_), 'LineString': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeCurveOrLineString_), + ol.format.GML3.prototype.writeCurveOrLineString_), 'MultiLineString': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeMultiCurveOrLineString_), + ol.format.GML3.prototype.writeMultiCurveOrLineString_), 'LinearRing': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeLinearRing_), + ol.format.GML3.prototype.writeLinearRing_), 'Polygon': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeSurfaceOrPolygon_), + ol.format.GML3.prototype.writeSurfaceOrPolygon_), 'MultiPolygon': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_), + ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_), 'Surface': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeSurfaceOrPolygon_), + ol.format.GML3.prototype.writeSurfaceOrPolygon_), 'MultiSurface': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeMultiSurfaceOrPolygon_), + ol.format.GML3.prototype.writeMultiSurfaceOrPolygon_), 'Envelope': ol.xml.makeChildAppender( - ol.format.GML.v3.prototype.writeEnvelope) + ol.format.GML3.prototype.writeEnvelope) } }; @@ -1189,7 +1192,7 @@ ol.format.GML.v3.GEOMETRY_SERIALIZERS_ = { * @type {Object.} * @private */ -ol.format.GML.v3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = { +ol.format.GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = { 'MultiLineString': 'lineStringMember', 'MultiCurve': 'curveMember', 'MultiPolygon': 'polygonMember', @@ -1205,12 +1208,12 @@ ol.format.GML.v3.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = { * @return {Node|undefined} Node. * @private */ -ol.format.GML.v3.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = +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)); return ol.xml.createElementNS('http://www.opengis.net/gml', - ol.format.GML.v3.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]); + ol.format.GML3.MULTIGEOMETRY_TO_MEMBER_NODENAME_[parentNode.nodeName]); }; @@ -1222,7 +1225,7 @@ ol.format.GML.v3.prototype.MULTIGEOMETRY_MEMBER_NODE_FACTORY_ = * @return {Node|undefined} Node. * @private */ -ol.format.GML.v3.prototype.GEOMETRY_NODE_FACTORY_ = +ol.format.GML3.prototype.GEOMETRY_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) { var context = objectStack[objectStack.length - 1]; goog.asserts.assert(goog.isObject(context)); @@ -1256,7 +1259,7 @@ ol.format.GML.v3.prototype.GEOMETRY_NODE_FACTORY_ = /** * @inheritDoc */ -ol.format.GML.v3.prototype.writeGeometryNode = function(geometry, opt_options) { +ol.format.GML3.prototype.writeGeometryNode = function(geometry, opt_options) { var geom = ol.xml.createElementNS('http://www.opengis.net/gml', 'geom'); var context = {node: geom, srsName: this.srsName, curve: this.curve_, surface: this.surface_, @@ -1278,13 +1281,13 @@ ol.format.GML.v3.prototype.writeGeometryNode = function(geometry, opt_options) { * @return {Node} Result. * @api stable */ -ol.format.GML.v3.prototype.writeFeatures; +ol.format.GML3.prototype.writeFeatures; /** * @inheritDoc */ -ol.format.GML.v3.prototype.writeFeaturesNode = function(features, opt_options) { +ol.format.GML3.prototype.writeFeaturesNode = function(features, opt_options) { var node = ol.xml.createElementNS('http://www.opengis.net/gml', 'featureMembers'); ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance', diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 5dd5d9903d..66fa3759c6 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -3,7 +3,8 @@ goog.provide('ol.format.WFS'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); -goog.require('ol.format.GML'); +goog.require('ol.format.GML3'); +goog.require('ol.format.GMLBase'); goog.require('ol.format.XMLFeature'); goog.require('ol.format.XSD'); goog.require('ol.geom.Geometry'); @@ -16,7 +17,7 @@ goog.require('ol.xml'); * @classdesc * Feature format for reading and writing data in the WFS format. * Currently only supports WFS version 1.1.0. - * Also see {@link ol.format.GML} which is used by this format. + * Also see {@link ol.format.GMLBase} which is used by this format. * * @constructor * @param {olx.format.WFSOptions=} opt_options @@ -42,10 +43,10 @@ ol.format.WFS = function(opt_options) { /** * @private - * @type {ol.format.GML} + * @type {ol.format.GMLBase} */ this.gmlFormat_ = goog.isDef(options.gmlFormat) ? - options.gmlFormat : new ol.format.GML.v3(); + options.gmlFormat : new ol.format.GML3(); /** * @private @@ -126,7 +127,7 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) { goog.isDef(opt_options) ? opt_options : {})); var objectStack = [context]; var features = ol.xml.pushParseAndPop([], - ol.format.GML.FEATURE_COLLECTION_PARSERS, node, + ol.format.GMLBase.FEATURE_COLLECTION_PARSERS, node, objectStack, this.gmlFormat_); if (!goog.isDef(features)) { features = []; @@ -204,7 +205,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument = ol.format.WFS.FEATURE_COLLECTION_PARSERS_ = { 'http://www.opengis.net/gml': { 'boundedBy': ol.xml.makeObjectPropertySetter( - ol.format.GML.prototype.readGeometryElement, 'bounds') + ol.format.GMLBase.prototype.readGeometryElement, 'bounds') } }; @@ -371,7 +372,7 @@ ol.format.WFS.writeFeature_ = function(node, feature, objectStack) { var featureNS = goog.object.get(context, 'featureNS'); var child = ol.xml.createElementNS(featureNS, featureType); node.appendChild(child); - ol.format.GML.v3.prototype.writeFeatureElement(child, feature, objectStack); + ol.format.GML3.prototype.writeFeatureElement(child, feature, objectStack); }; @@ -465,7 +466,7 @@ ol.format.WFS.writeProperty_ = function(node, pair, objectStack) { var value = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Value'); node.appendChild(value); if (pair.value instanceof ol.geom.Geometry) { - ol.format.GML.v3.prototype.writeGeometryElement(value, + ol.format.GML3.prototype.writeGeometryElement(value, pair.value, objectStack); } else { ol.format.XSD.writeStringTextNode(value, pair.value); @@ -573,7 +574,7 @@ ol.format.WFS.writeOgcBBOX_ = function(node, bbox, objectStack) { var bboxNode = ol.xml.createElementNS('http://www.opengis.net/ogc', 'BBOX'); node.appendChild(bboxNode); ol.format.WFS.writeOgcPropertyName_(bboxNode, geometryName, objectStack); - ol.format.GML.v3.prototype.writeGeometryElement(bboxNode, bbox, objectStack); + ol.format.GML3.prototype.writeGeometryElement(bboxNode, bbox, objectStack); }; diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index e189be53c0..0f7dd78349 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -8,15 +8,15 @@ var readGeometry = function(format, text, opt_options) { return format.readGeometryFromNode(node, opt_options); }; -describe('ol.format.GML.v2', function() { +describe('ol.format.GML2', function() { var format, formatWGS84, formatNoSrs; beforeEach(function() { - format = new ol.format.GML.v2({srsName: 'CRS:84'}); - formatWGS84 = new ol.format.GML.v2({ + format = new ol.format.GML2({srsName: 'CRS:84'}); + formatWGS84 = new ol.format.GML2({ srsName: 'urn:x-ogc:def:crs:EPSG:4326' }); - formatNoSrs = new ol.format.GML.v2(); + formatNoSrs = new ol.format.GML2(); }); @@ -95,15 +95,15 @@ describe('ol.format.GML.v2', function() { }); }); -describe('ol.format.GML.v3', function() { +describe('ol.format.GML3', function() { var format, formatWGS84, formatNoSrs; beforeEach(function() { - format = new ol.format.GML.v3({srsName: 'CRS:84'}); - formatWGS84 = new ol.format.GML.v3({ + format = new ol.format.GML({srsName: 'CRS:84'}); + formatWGS84 = new ol.format.GML({ srsName: 'urn:x-ogc:def:crs:EPSG:4326' }); - formatNoSrs = new ol.format.GML.v3(); + formatNoSrs = new ol.format.GML(); }); describe('#readGeometry', function() { @@ -305,7 +305,7 @@ describe('ol.format.GML.v3', function() { var g = readGeometry(format, text); expect(g.getCoordinates()[0][0][0][0]).to.equal(-77.0081); expect(g.getCoordinates()[0][0][0][1]).to.equal(38.9661); - format = new ol.format.GML.v3({ + format = new ol.format.GML({ srsName: 'urn:x-ogc:def:crs:EPSG:4326', surface: false}); var serialized = format.writeGeometry(g); @@ -411,7 +411,7 @@ describe('ol.format.GML.v3', function() { expect(g.getCoordinates()).to.eql([[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]], [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]]); - format = new ol.format.GML.v3({srsName: 'CRS:84', surface: true}); + format = new ol.format.GML({srsName: 'CRS:84', surface: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -433,7 +433,7 @@ describe('ol.format.GML.v3', function() { var g = readGeometry(format, text); expect(g).to.be.an(ol.geom.LineString); expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]); - format = new ol.format.GML.v3({srsName: 'CRS:84', curve: true}); + format = new ol.format.GML({srsName: 'CRS:84', curve: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -528,7 +528,7 @@ describe('ol.format.GML.v3', function() { expect(g).to.be.an(ol.geom.MultiLineString); expect(g.getCoordinates()).to.eql( [[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]); - format = new ol.format.GML.v3({srsName: 'CRS:84', multiCurve: false}); + format = new ol.format.GML({srsName: 'CRS:84', multiCurve: false}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -596,7 +596,7 @@ describe('ol.format.GML.v3', function() { [1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]], [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]], [[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]); - format = new ol.format.GML.v3({srsName: 'CRS:84', multiSurface: false}); + format = new ol.format.GML({srsName: 'CRS:84', multiSurface: false}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -696,7 +696,7 @@ describe('ol.format.GML.v3', function() { expect(g).to.be.an(ol.geom.MultiLineString); expect(g.getCoordinates()).to.eql( [[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]); - format = new ol.format.GML.v3({srsName: 'CRS:84', curve: true}); + format = new ol.format.GML({srsName: 'CRS:84', curve: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -839,7 +839,7 @@ describe('ol.format.GML.v3', function() { [1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]], [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]], [[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]); - format = new ol.format.GML.v3({srsName: 'CRS:84', surface: true}); + format = new ol.format.GML({srsName: 'CRS:84', surface: true}); var serialized = format.writeGeometry(g); expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); @@ -871,7 +871,7 @@ describe('ol.format.GML.v3', function() { 'featureNS': 'http://www.openplans.org/topp', 'featureType': 'gnis_pop' }; - var features = new ol.format.GML.v3(config).readFeatures(text); + var features = new ol.format.GML(config).readFeatures(text); var feature = features[0]; expect(feature.get('empty')).to.be(undefined); }); @@ -883,7 +883,7 @@ describe('ol.format.GML.v3', function() { afterLoadText('spec/ol/format/gml/topp-states-wfs.xml', function(xml) { try { text = xml; - gmlFormat = new ol.format.GML.v3(); + gmlFormat = new ol.format.GML(); features = gmlFormat.readFeatures(xml); } catch (e) { done(e); @@ -948,7 +948,7 @@ describe('ol.format.GML.v3', function() { 'schemaLocation': schemaLoc }; text = xml; - gmlFormat = new ol.format.GML.v3(config); + gmlFormat = new ol.format.GML(config); features = gmlFormat.readFeatures(xml); } catch (e) { done(e); @@ -982,7 +982,7 @@ describe('ol.format.GML.v3', function() { 'featureNS': 'http://www.openplans.org/topp', 'featureType': 'states' }; - features = new ol.format.GML.v3(config).readFeatures(xml); + features = new ol.format.GML(config).readFeatures(xml); } catch (e) { done(e); } @@ -1013,7 +1013,7 @@ describe('ol.format.GML.v3', function() { 'featureNS': 'http://opengeo.org/#medford', 'featureType': 'zoning' }; - features = new ol.format.GML.v3(config).readFeatures(xml); + features = new ol.format.GML(config).readFeatures(xml); } catch (e) { done(e); } @@ -1039,7 +1039,7 @@ describe('ol.format.GML.v3', function() { 'featureNS': 'http://opengeo.org/#medford', 'featureType': 'zoning' }; - features = new ol.format.GML.v3(config).readFeatures(xml); + features = new ol.format.GML(config).readFeatures(xml); } catch (e) { done(e); } @@ -1060,6 +1060,8 @@ describe('ol.format.GML.v3', function() { goog.require('goog.dom'); goog.require('goog.dom.TagName'); goog.require('ol.format.GML'); +goog.require('ol.format.GML2'); +goog.require('ol.format.GML3'); goog.require('ol.geom.LineString'); goog.require('ol.geom.LinearRing'); goog.require('ol.geom.MultiPoint'); diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 6beb04c78a..33e8242c53 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -56,7 +56,7 @@ describe('ol.format.WFS', function() { var config = { 'featureNS': 'http://mapserver.gis.umn.edu/mapserver', 'featureType': 'polygon', - 'gmlFormat': new ol.format.GML.v2() + 'gmlFormat': new ol.format.GML2() }; before(function(done) { @@ -440,7 +440,6 @@ goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.MultiPoint'); goog.require('ol.geom.MultiPolygon'); goog.require('ol.geom.Polygon'); -goog.require('ol.format.GML'); -goog.require('ol.format.GML.v2'); +goog.require('ol.format.GML2'); goog.require('ol.format.WFS'); goog.require('ol.proj'); From 0646056751f450bb06b5118e2dd9579aebe987a3 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 08:57:52 +0200 Subject: [PATCH 24/31] Overrides schemaLocation in subclasses --- src/ol/format/gml/base.js | 3 +-- src/ol/format/gml/v2.js | 16 ++++++++++++---- src/ol/format/gml/v3.js | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/base.js index 594cd9c424..13f80f8818 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/base.js @@ -62,8 +62,7 @@ ol.format.GMLBase = function(opt_options) { * @protected * @type {string} */ - this.schemaLocation = goog.isDef(options.schemaLocation) ? - options.schemaLocation : this.constructor.schemaLocation_; + this.schemaLocation = ''; goog.base(this); }; diff --git a/src/ol/format/gml/v2.js b/src/ol/format/gml/v2.js index 4d676977aa..e2c05d5f33 100644 --- a/src/ol/format/gml/v2.js +++ b/src/ol/format/gml/v2.js @@ -18,22 +18,30 @@ goog.require('ol.xml'); * version 2.1.2. * * @constructor - * @param {olx.format.GMLOptions=} opt_options - * Optional configuration object. + * @param {olx.format.GMLOptions=} opt_options Optional configuration object. * @extends {ol.format.GMLBase} * @api */ ol.format.GML2 = function(opt_options) { + var options = /** @type {olx.format.GMLOptions} */ + (goog.isDef(opt_options) ? opt_options : {}); + + goog.base(this, options); + + /** + * @inheritDoc + */ + this.schemaLocation = goog.isDef(options.schemaLocation) ? + options.schemaLocation : ol.format.GML2.schemaLocation_; - goog.base(this, opt_options); }; goog.inherits(ol.format.GML2, ol.format.GMLBase); /** * @const - * @private * @type {string} + * @private */ ol.format.GML2.schemaLocation_ = 'http://www.opengis.net/gml ' + 'http://schemas.opengis.net/gml/2.1.2/feature.xsd'; diff --git a/src/ol/format/gml/v3.js b/src/ol/format/gml/v3.js index 79534e49cb..b6bd645bd2 100644 --- a/src/ol/format/gml/v3.js +++ b/src/ol/format/gml/v3.js @@ -39,6 +39,8 @@ ol.format.GML3 = function(opt_options) { var options = /** @type {olx.format.GMLOptions} */ (goog.isDef(opt_options) ? opt_options : {}); + goog.base(this, options); + /** * @private * @type {boolean} @@ -67,8 +69,12 @@ ol.format.GML3 = function(opt_options) { this.multiSurface_ = goog.isDef(options.multiSurface) ? options.multiSurface : true; + /** + * @inheritDoc + */ + this.schemaLocation = goog.isDef(options.schemaLocation) ? + options.schemaLocation : ol.format.GML3.schemaLocation_; - goog.base(this, opt_options); }; goog.inherits(ol.format.GML3, ol.format.GMLBase); From bea721349ab0d7079a3f306b1b70459a3435531e Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 09:00:43 +0200 Subject: [PATCH 25/31] Rename gml format files to match convention also changes some comments and syntax (feedback from PR comments --- src/ol/format/gml/{v2.js => gml2.js} | 0 src/ol/format/gml/{v3.js => gml3.js} | 0 src/ol/format/gml/{base.js => gmlbase.js} | 8 +++++--- 3 files changed, 5 insertions(+), 3 deletions(-) rename src/ol/format/gml/{v2.js => gml2.js} (100%) rename src/ol/format/gml/{v3.js => gml3.js} (100%) rename src/ol/format/gml/{base.js => gmlbase.js} (98%) diff --git a/src/ol/format/gml/v2.js b/src/ol/format/gml/gml2.js similarity index 100% rename from src/ol/format/gml/v2.js rename to src/ol/format/gml/gml2.js diff --git a/src/ol/format/gml/v3.js b/src/ol/format/gml/gml3.js similarity index 100% rename from src/ol/format/gml/v3.js rename to src/ol/format/gml/gml3.js diff --git a/src/ol/format/gml/base.js b/src/ol/format/gml/gmlbase.js similarity index 98% rename from src/ol/format/gml/base.js rename to src/ol/format/gml/gmlbase.js index 13f80f8818..4f11887060 100644 --- a/src/ol/format/gml/base.js +++ b/src/ol/format/gml/gmlbase.js @@ -27,8 +27,10 @@ goog.require('ol.xml'); /** * @classdesc - * Feature format for reading and writing data in the GML format. - * Currently only supports GML 3.1.1 Simple Features profile. + * Feature base format for reading and writing data in the GML format. + * This class cannot be instantiate, it contains only base content that + * is shared with versioned format classes ol.format.GML2 and + * ol.format.GML3. * * @constructor * @param {olx.format.GMLOptions=} opt_options @@ -515,7 +517,7 @@ ol.format.GMLBase.prototype.readGeometryFromNode = function(node, opt_options) { var geometry = this.readGeometryElement(node, [this.getReadOptions(node, goog.isDef(opt_options) ? opt_options : {})]); - return (goog.isDef(geometry) ? geometry : null); + return goog.isDef(geometry) ? geometry : null; }; From 47e182524f8224764c2fc7aa435ec92736a0b405 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 09:23:13 +0200 Subject: [PATCH 26/31] Put PARSERS object into prototype too This is to avoid the use of this.constructor that breaks advanced build --- src/ol/format/gml/gml2.js | 10 ++++---- src/ol/format/gml/gml3.js | 50 ++++++++++++++++++------------------ src/ol/format/gml/gmlbase.js | 38 +++++++++++++-------------- src/ol/format/wfsformat.js | 2 +- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/ol/format/gml/gml2.js b/src/ol/format/gml/gml2.js index e2c05d5f33..1a6e3a00d7 100644 --- a/src/ol/format/gml/gml2.js +++ b/src/ol/format/gml/gml2.js @@ -103,7 +103,7 @@ ol.format.GML2.prototype.innerBoundaryIsParser_ = goog.asserts.assert(node.localName == 'innerBoundaryIs'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GMLBase.RING_PARSERS, node, objectStack, this); + this.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -125,7 +125,7 @@ ol.format.GML2.prototype.outerBoundaryIsParser_ = goog.asserts.assert(node.localName == 'outerBoundaryIs'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GMLBase.RING_PARSERS, node, objectStack, this); + this.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -141,7 +141,7 @@ ol.format.GML2.prototype.outerBoundaryIsParser_ = * @type {Object.>} * @private */ -ol.format.GML2.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { +ol.format.GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { 'http://www.opengis.net/gml' : { 'coordinates': ol.xml.makeReplacer( ol.format.GML2.prototype.readFlatCoordinates_) @@ -154,7 +154,7 @@ ol.format.GML2.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML2.FLAT_LINEAR_RINGS_PARSERS_ = { +ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = { 'http://www.opengis.net/gml' : { 'innerBoundaryIs': ol.format.GML2.prototype.innerBoundaryIsParser_, 'outerBoundaryIs': ol.format.GML2.prototype.outerBoundaryIsParser_ @@ -167,7 +167,7 @@ ol.format.GML2.FLAT_LINEAR_RINGS_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML2.GEOMETRY_PARSERS_ = { +ol.format.GML2.prototype.GEOMETRY_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint), 'MultiPoint': ol.xml.makeReplacer( diff --git a/src/ol/format/gml/gml3.js b/src/ol/format/gml/gml3.js index b6bd645bd2..d36d7e7428 100644 --- a/src/ol/format/gml/gml3.js +++ b/src/ol/format/gml/gml3.js @@ -116,7 +116,7 @@ ol.format.GML3.prototype.readMultiCurve_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiCurve'); var lineStrings = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML3.MULTICURVE_PARSERS_, node, objectStack, this); + this.MULTICURVE_PARSERS_, node, objectStack, this); if (goog.isDef(lineStrings)) { var multiLineString = new ol.geom.MultiLineString(null); multiLineString.setLineStrings(lineStrings); @@ -138,7 +138,7 @@ ol.format.GML3.prototype.readMultiSurface_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiSurface'); var polygons = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GML3.MULTISURFACE_PARSERS_, node, objectStack, this); + this.MULTISURFACE_PARSERS_, node, objectStack, this); if (goog.isDef(polygons)) { var multiPolygon = new ol.geom.MultiPolygon(null); multiPolygon.setPolygons(polygons); @@ -158,7 +158,7 @@ ol.format.GML3.prototype.curveMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'curveMember' || node.localName == 'curveMembers'); - ol.xml.parse(ol.format.GML3.CURVEMEMBER_PARSERS_, node, objectStack, this); + ol.xml.parse(this.CURVEMEMBER_PARSERS_, node, objectStack, this); }; @@ -171,7 +171,7 @@ ol.format.GML3.prototype.surfaceMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'surfaceMember' || node.localName == 'surfaceMembers'); - ol.xml.parse(ol.format.GML3.SURFACEMEMBER_PARSERS_, + ol.xml.parse(this.SURFACEMEMBER_PARSERS_, node, objectStack, this); }; @@ -187,7 +187,7 @@ ol.format.GML3.prototype.readPatch_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'patches'); return ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML3.PATCHES_PARSERS_, node, objectStack, this); + this.PATCHES_PARSERS_, node, objectStack, this); }; @@ -202,7 +202,7 @@ ol.format.GML3.prototype.readSegment_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'segments'); return ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML3.SEGMENTS_PARSERS_, node, objectStack, this); + this.SEGMENTS_PARSERS_, node, objectStack, this); }; @@ -217,7 +217,7 @@ ol.format.GML3.prototype.readPolygonPatch_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'PolygonPatch'); return ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - this.constructor.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); + this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); }; @@ -233,7 +233,7 @@ ol.format.GML3.prototype.readLineStringSegment_ = goog.asserts.assert(node.localName == 'LineStringSegment'); return ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - this.constructor.GEOMETRY_FLAT_COORDINATES_PARSERS_, + this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack, this); }; @@ -248,7 +248,7 @@ ol.format.GML3.prototype.interiorParser_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'interior'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GMLBase.RING_PARSERS, node, objectStack, this); + this.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -269,7 +269,7 @@ ol.format.GML3.prototype.exteriorParser_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'exterior'); var flatLinearRing = ol.xml.pushParseAndPop( /** @type {Array.|undefined} */ (undefined), - ol.format.GMLBase.RING_PARSERS, node, objectStack, this); + this.RING_PARSERS, node, objectStack, this); if (goog.isDef(flatLinearRing)) { var flatLinearRings = /** @type {Array.>} */ (objectStack[objectStack.length - 1]); @@ -291,7 +291,7 @@ ol.format.GML3.prototype.readSurface_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'Surface'); var flatLinearRings = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - ol.format.GML3.SURFACE_PARSERS_, node, objectStack, this); + this.SURFACE_PARSERS_, node, objectStack, this); if (goog.isDef(flatLinearRings) && !goog.isNull(flatLinearRings[0])) { var polygon = new ol.geom.Polygon(null); @@ -322,7 +322,7 @@ ol.format.GML3.prototype.readCurve_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'Curve'); var flatCoordinates = ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML3.CURVE_PARSERS_, node, objectStack, this); + this.CURVE_PARSERS_, node, objectStack, this); if (goog.isDef(flatCoordinates)) { var lineString = new ol.geom.LineString(null); lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates); @@ -344,7 +344,7 @@ ol.format.GML3.prototype.readEnvelope_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'Envelope'); var flatCoordinates = ol.xml.pushParseAndPop( /** @type {Array.} */ ([null]), - ol.format.GML3.ENVELOPE_PARSERS_, node, objectStack, this); + this.ENVELOPE_PARSERS_, node, objectStack, this); return ol.extent.createOrUpdate(flatCoordinates[1][0], flatCoordinates[1][1], flatCoordinates[2][0], flatCoordinates[2][1]); @@ -448,7 +448,7 @@ ol.format.GML3.prototype.readFlatPosList_ = function(node, objectStack) { * @type {Object.>} * @private */ -ol.format.GML3.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { +ol.format.GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { 'http://www.opengis.net/gml' : { 'pos': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPos_), 'posList': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPosList_) @@ -461,7 +461,7 @@ ol.format.GML3.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.FLAT_LINEAR_RINGS_PARSERS_ = { +ol.format.GML3.prototype.FLAT_LINEAR_RINGS_PARSERS_ = { 'http://www.opengis.net/gml' : { 'interior': ol.format.GML3.prototype.interiorParser_, 'exterior': ol.format.GML3.prototype.exteriorParser_ @@ -474,7 +474,7 @@ ol.format.GML3.FLAT_LINEAR_RINGS_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.GEOMETRY_PARSERS_ = { +ol.format.GML3.prototype.GEOMETRY_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint), 'MultiPoint': ol.xml.makeReplacer( @@ -504,7 +504,7 @@ ol.format.GML3.GEOMETRY_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.MULTICURVE_PARSERS_ = { +ol.format.GML3.prototype.MULTICURVE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'curveMember': ol.xml.makeArrayPusher( ol.format.GML3.prototype.curveMemberParser_), @@ -519,7 +519,7 @@ ol.format.GML3.MULTICURVE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.MULTISURFACE_PARSERS_ = { +ol.format.GML3.prototype.MULTISURFACE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'surfaceMember': ol.xml.makeArrayPusher( ol.format.GML3.prototype.surfaceMemberParser_), @@ -534,7 +534,7 @@ ol.format.GML3.MULTISURFACE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.CURVEMEMBER_PARSERS_ = { +ol.format.GML3.prototype.CURVEMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readLineString), @@ -548,7 +548,7 @@ ol.format.GML3.CURVEMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.SURFACEMEMBER_PARSERS_ = { +ol.format.GML3.prototype.SURFACEMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Polygon': ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readPolygon), 'Surface': ol.xml.makeArrayPusher(ol.format.GML3.prototype.readSurface_) @@ -561,7 +561,7 @@ ol.format.GML3.SURFACEMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.SURFACE_PARSERS_ = { +ol.format.GML3.prototype.SURFACE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'patches': ol.xml.makeReplacer(ol.format.GML3.prototype.readPatch_) } @@ -573,7 +573,7 @@ ol.format.GML3.SURFACE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.CURVE_PARSERS_ = { +ol.format.GML3.prototype.CURVE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'segments': ol.xml.makeReplacer(ol.format.GML3.prototype.readSegment_) } @@ -585,7 +585,7 @@ ol.format.GML3.CURVE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.ENVELOPE_PARSERS_ = { +ol.format.GML3.prototype.ENVELOPE_PARSERS_ = { 'http://www.opengis.net/gml' : { 'lowerCorner': ol.xml.makeArrayPusher( ol.format.GML3.prototype.readFlatPosList_), @@ -600,7 +600,7 @@ ol.format.GML3.ENVELOPE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.PATCHES_PARSERS_ = { +ol.format.GML3.prototype.PATCHES_PARSERS_ = { 'http://www.opengis.net/gml' : { 'PolygonPatch': ol.xml.makeReplacer( ol.format.GML3.prototype.readPolygonPatch_) @@ -613,7 +613,7 @@ ol.format.GML3.PATCHES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.SEGMENTS_PARSERS_ = { +ol.format.GML3.prototype.SEGMENTS_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineStringSegment': ol.xml.makeReplacer( ol.format.GML3.prototype.readLineStringSegment_) diff --git a/src/ol/format/gml/gmlbase.js b/src/ol/format/gml/gmlbase.js index 4f11887060..55dffca46f 100644 --- a/src/ol/format/gml/gmlbase.js +++ b/src/ol/format/gml/gmlbase.js @@ -83,7 +83,7 @@ ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) { var features; if (localName == 'FeatureCollection') { features = ol.xml.pushParseAndPop(null, - ol.format.GMLBase.FEATURE_COLLECTION_PARSERS, node, + this.FEATURE_COLLECTION_PARSERS, node, objectStack, this); } else if (localName == 'featureMembers' || localName == 'featureMember') { var context = objectStack[0]; @@ -113,7 +113,7 @@ ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) { /** * @type {Object.>} */ -ol.format.GMLBase.FEATURE_COLLECTION_PARSERS = { +ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = { 'http://www.opengis.net/gml': { 'featureMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readFeatures_), @@ -134,7 +134,7 @@ ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) { goog.object.set(context, 'srsName', node.firstElementChild.getAttribute('srsName')); var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null), - this.constructor.GEOMETRY_PARSERS_, node, objectStack, this); + this.GEOMETRY_PARSERS_, node, objectStack, this); if (goog.isDefAndNotNull(geometry)) { return /** @type {ol.geom.Geometry} */ ( ol.format.Feature.transformWithOptions(geometry, false, context)); @@ -212,7 +212,7 @@ ol.format.GMLBase.prototype.readMultiPoint = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiPoint'); var coordinates = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([]), - ol.format.GMLBase.MULTIPOINT_PARSERS_, node, objectStack, this); + this.MULTIPOINT_PARSERS_, node, objectStack, this); if (goog.isDef(coordinates)) { return new ol.geom.MultiPoint(coordinates); } else { @@ -231,7 +231,7 @@ ol.format.GMLBase.prototype.readMultiLineString = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiLineString'); var lineStrings = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GMLBase.MULTILINESTRING_PARSERS_, node, objectStack, this); + this.MULTILINESTRING_PARSERS_, node, objectStack, this); if (goog.isDef(lineStrings)) { var multiLineString = new ol.geom.MultiLineString(null); multiLineString.setLineStrings(lineStrings); @@ -252,7 +252,7 @@ ol.format.GMLBase.prototype.readMultiPolygon = function(node, objectStack) { goog.asserts.assert(node.localName == 'MultiPolygon'); var polygons = ol.xml.pushParseAndPop( /** @type {Array.} */ ([]), - ol.format.GMLBase.MULTIPOLYGON_PARSERS_, node, objectStack, this); + this.MULTIPOLYGON_PARSERS_, node, objectStack, this); if (goog.isDef(polygons)) { var multiPolygon = new ol.geom.MultiPolygon(null); multiPolygon.setPolygons(polygons); @@ -272,7 +272,7 @@ ol.format.GMLBase.prototype.pointMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'pointMember' || node.localName == 'pointMembers'); - ol.xml.parse(ol.format.GMLBase.POINTMEMBER_PARSERS_, + ol.xml.parse(this.POINTMEMBER_PARSERS_, node, objectStack, this); }; @@ -287,7 +287,7 @@ ol.format.GMLBase.prototype.lineStringMemberParser_ = goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'lineStringMember' || node.localName == 'lineStringMembers'); - ol.xml.parse(ol.format.GMLBase.LINESTRINGMEMBER_PARSERS_, + ol.xml.parse(this.LINESTRINGMEMBER_PARSERS_, node, objectStack, this); }; @@ -302,7 +302,7 @@ ol.format.GMLBase.prototype.polygonMemberParser_ = goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'polygonMember' || node.localName == 'polygonMembers'); - ol.xml.parse(ol.format.GMLBase.POLYGONMEMBER_PARSERS_, node, + ol.xml.parse(this.POLYGONMEMBER_PARSERS_, node, objectStack, this); }; @@ -337,7 +337,7 @@ ol.format.GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'LinearRing'); var ring = ol.xml.pushParseAndPop(/** @type {Array.} */(null), - this.constructor.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, + this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack, this); if (goog.isDefAndNotNull(ring)) { return ring; @@ -377,7 +377,7 @@ ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) { goog.asserts.assert(node.localName == 'Polygon'); var flatLinearRings = ol.xml.pushParseAndPop( /** @type {Array.>} */ ([null]), - this.constructor.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); + this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); if (goog.isDef(flatLinearRings) && !goog.isNull(flatLinearRings[0])) { var polygon = new ol.geom.Polygon(null); @@ -408,7 +408,7 @@ ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_ = goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); return /** @type {Array.} */ (ol.xml.pushParseAndPop( null, - this.constructor.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, + this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack, this)); }; @@ -418,7 +418,7 @@ ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_ = * @type {Object.>} * @private */ -ol.format.GMLBase.MULTIPOINT_PARSERS_ = { +ol.format.GMLBase.prototype.MULTIPOINT_PARSERS_ = { 'http://www.opengis.net/gml' : { 'pointMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.pointMemberParser_), @@ -433,7 +433,7 @@ ol.format.GMLBase.MULTIPOINT_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.MULTILINESTRING_PARSERS_ = { +ol.format.GMLBase.prototype.MULTILINESTRING_PARSERS_ = { 'http://www.opengis.net/gml' : { 'lineStringMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.lineStringMemberParser_), @@ -448,7 +448,7 @@ ol.format.GMLBase.MULTILINESTRING_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.MULTIPOLYGON_PARSERS_ = { +ol.format.GMLBase.prototype.MULTIPOLYGON_PARSERS_ = { 'http://www.opengis.net/gml' : { 'polygonMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.polygonMemberParser_), @@ -463,7 +463,7 @@ ol.format.GMLBase.MULTIPOLYGON_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.POINTMEMBER_PARSERS_ = { +ol.format.GMLBase.prototype.POINTMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_) @@ -476,7 +476,7 @@ ol.format.GMLBase.POINTMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.LINESTRINGMEMBER_PARSERS_ = { +ol.format.GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readLineString) @@ -489,7 +489,7 @@ ol.format.GMLBase.LINESTRINGMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.POLYGONMEMBER_PARSERS_ = { +ol.format.GMLBase.prototype.POLYGONMEMBER_PARSERS_ = { 'http://www.opengis.net/gml' : { 'Polygon': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readPolygon) @@ -502,7 +502,7 @@ ol.format.GMLBase.POLYGONMEMBER_PARSERS_ = { * @type {Object.>} * @protected */ -ol.format.GMLBase.RING_PARSERS = { +ol.format.GMLBase.prototype.RING_PARSERS = { 'http://www.opengis.net/gml' : { 'LinearRing': ol.xml.makeReplacer( ol.format.GMLBase.prototype.readFlatLinearRing_) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 66fa3759c6..989efdda83 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -127,7 +127,7 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) { goog.isDef(opt_options) ? opt_options : {})); var objectStack = [context]; var features = ol.xml.pushParseAndPop([], - ol.format.GMLBase.FEATURE_COLLECTION_PARSERS, node, + this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node, objectStack, this.gmlFormat_); if (!goog.isDef(features)) { features = []; From 1a7cbfd6ac09643af29ae7137ea469ee7976ef5b Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 10:01:31 +0200 Subject: [PATCH 27/31] Use Object() for objects in prototype to avoid linter warning --- src/ol/format/gml/gml2.js | 12 ++++----- src/ol/format/gml/gml3.js | 48 ++++++++++++++++++------------------ src/ol/format/gml/gmlbase.js | 32 ++++++++++++------------ 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/ol/format/gml/gml2.js b/src/ol/format/gml/gml2.js index 1a6e3a00d7..076f753cc3 100644 --- a/src/ol/format/gml/gml2.js +++ b/src/ol/format/gml/gml2.js @@ -141,12 +141,12 @@ ol.format.GML2.prototype.outerBoundaryIsParser_ = * @type {Object.>} * @private */ -ol.format.GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { +ol.format.GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'coordinates': ol.xml.makeReplacer( ol.format.GML2.prototype.readFlatCoordinates_) } -}; +}); /** @@ -154,12 +154,12 @@ ol.format.GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = { +ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'innerBoundaryIs': ol.format.GML2.prototype.innerBoundaryIsParser_, 'outerBoundaryIs': ol.format.GML2.prototype.outerBoundaryIsParser_ } -}; +}); /** @@ -167,7 +167,7 @@ ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML2.prototype.GEOMETRY_PARSERS_ = { +ol.format.GML2.prototype.GEOMETRY_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint), 'MultiPoint': ol.xml.makeReplacer( @@ -182,4 +182,4 @@ ol.format.GML2.prototype.GEOMETRY_PARSERS_ = { 'MultiPolygon': ol.xml.makeReplacer( ol.format.GMLBase.prototype.readMultiPolygon) } -}; +}); diff --git a/src/ol/format/gml/gml3.js b/src/ol/format/gml/gml3.js index d36d7e7428..3a12b20a20 100644 --- a/src/ol/format/gml/gml3.js +++ b/src/ol/format/gml/gml3.js @@ -448,12 +448,12 @@ ol.format.GML3.prototype.readFlatPosList_ = function(node, objectStack) { * @type {Object.>} * @private */ -ol.format.GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { +ol.format.GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'pos': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPos_), 'posList': ol.xml.makeReplacer(ol.format.GML3.prototype.readFlatPosList_) } -}; +}); /** @@ -461,12 +461,12 @@ ol.format.GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.FLAT_LINEAR_RINGS_PARSERS_ = { +ol.format.GML3.prototype.FLAT_LINEAR_RINGS_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'interior': ol.format.GML3.prototype.interiorParser_, 'exterior': ol.format.GML3.prototype.exteriorParser_ } -}; +}); /** @@ -474,7 +474,7 @@ ol.format.GML3.prototype.FLAT_LINEAR_RINGS_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.GEOMETRY_PARSERS_ = { +ol.format.GML3.prototype.GEOMETRY_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint), 'MultiPoint': ol.xml.makeReplacer( @@ -496,7 +496,7 @@ ol.format.GML3.prototype.GEOMETRY_PARSERS_ = { ol.format.GML3.prototype.readMultiCurve_), 'Envelope': ol.xml.makeReplacer(ol.format.GML3.prototype.readEnvelope_) } -}; +}); /** @@ -504,14 +504,14 @@ ol.format.GML3.prototype.GEOMETRY_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.MULTICURVE_PARSERS_ = { +ol.format.GML3.prototype.MULTICURVE_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'curveMember': ol.xml.makeArrayPusher( ol.format.GML3.prototype.curveMemberParser_), 'curveMembers': ol.xml.makeArrayPusher( ol.format.GML3.prototype.curveMemberParser_) } -}; +}); /** @@ -519,14 +519,14 @@ ol.format.GML3.prototype.MULTICURVE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.MULTISURFACE_PARSERS_ = { +ol.format.GML3.prototype.MULTISURFACE_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'surfaceMember': ol.xml.makeArrayPusher( ol.format.GML3.prototype.surfaceMemberParser_), 'surfaceMembers': ol.xml.makeArrayPusher( ol.format.GML3.prototype.surfaceMemberParser_) } -}; +}); /** @@ -534,13 +534,13 @@ ol.format.GML3.prototype.MULTISURFACE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.CURVEMEMBER_PARSERS_ = { +ol.format.GML3.prototype.CURVEMEMBER_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readLineString), 'Curve': ol.xml.makeArrayPusher(ol.format.GML3.prototype.readCurve_) } -}; +}); /** @@ -548,12 +548,12 @@ ol.format.GML3.prototype.CURVEMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.SURFACEMEMBER_PARSERS_ = { +ol.format.GML3.prototype.SURFACEMEMBER_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'Polygon': ol.xml.makeArrayPusher(ol.format.GMLBase.prototype.readPolygon), 'Surface': ol.xml.makeArrayPusher(ol.format.GML3.prototype.readSurface_) } -}; +}); /** @@ -561,11 +561,11 @@ ol.format.GML3.prototype.SURFACEMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.SURFACE_PARSERS_ = { +ol.format.GML3.prototype.SURFACE_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'patches': ol.xml.makeReplacer(ol.format.GML3.prototype.readPatch_) } -}; +}); /** @@ -573,11 +573,11 @@ ol.format.GML3.prototype.SURFACE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.CURVE_PARSERS_ = { +ol.format.GML3.prototype.CURVE_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'segments': ol.xml.makeReplacer(ol.format.GML3.prototype.readSegment_) } -}; +}); /** @@ -585,14 +585,14 @@ ol.format.GML3.prototype.CURVE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.ENVELOPE_PARSERS_ = { +ol.format.GML3.prototype.ENVELOPE_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'lowerCorner': ol.xml.makeArrayPusher( ol.format.GML3.prototype.readFlatPosList_), 'upperCorner': ol.xml.makeArrayPusher( ol.format.GML3.prototype.readFlatPosList_) } -}; +}); /** @@ -600,12 +600,12 @@ ol.format.GML3.prototype.ENVELOPE_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.PATCHES_PARSERS_ = { +ol.format.GML3.prototype.PATCHES_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'PolygonPatch': ol.xml.makeReplacer( ol.format.GML3.prototype.readPolygonPatch_) } -}; +}); /** @@ -613,12 +613,12 @@ ol.format.GML3.prototype.PATCHES_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GML3.prototype.SEGMENTS_PARSERS_ = { +ol.format.GML3.prototype.SEGMENTS_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'LineStringSegment': ol.xml.makeReplacer( ol.format.GML3.prototype.readLineStringSegment_) } -}; +}); /** diff --git a/src/ol/format/gml/gmlbase.js b/src/ol/format/gml/gmlbase.js index 55dffca46f..1c917c3c2e 100644 --- a/src/ol/format/gml/gmlbase.js +++ b/src/ol/format/gml/gmlbase.js @@ -113,14 +113,14 @@ ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) { /** * @type {Object.>} */ -ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = { +ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = Object({ 'http://www.opengis.net/gml': { 'featureMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readFeatures_), 'featureMembers': ol.xml.makeReplacer( ol.format.GMLBase.prototype.readFeatures_) } -}; +}); /** @@ -418,14 +418,14 @@ ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_ = * @type {Object.>} * @private */ -ol.format.GMLBase.prototype.MULTIPOINT_PARSERS_ = { +ol.format.GMLBase.prototype.MULTIPOINT_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'pointMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.pointMemberParser_), 'pointMembers': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.pointMemberParser_) } -}; +}); /** @@ -433,14 +433,14 @@ ol.format.GMLBase.prototype.MULTIPOINT_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.prototype.MULTILINESTRING_PARSERS_ = { +ol.format.GMLBase.prototype.MULTILINESTRING_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'lineStringMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.lineStringMemberParser_), 'lineStringMembers': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.lineStringMemberParser_) } -}; +}); /** @@ -448,14 +448,14 @@ ol.format.GMLBase.prototype.MULTILINESTRING_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.prototype.MULTIPOLYGON_PARSERS_ = { +ol.format.GMLBase.prototype.MULTIPOLYGON_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'polygonMember': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.polygonMemberParser_), 'polygonMembers': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.polygonMemberParser_) } -}; +}); /** @@ -463,12 +463,12 @@ ol.format.GMLBase.prototype.MULTIPOLYGON_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.prototype.POINTMEMBER_PARSERS_ = { +ol.format.GMLBase.prototype.POINTMEMBER_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'Point': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_) } -}; +}); /** @@ -476,12 +476,12 @@ ol.format.GMLBase.prototype.POINTMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = { +ol.format.GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'LineString': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readLineString) } -}; +}); /** @@ -489,12 +489,12 @@ ol.format.GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = { * @type {Object.>} * @private */ -ol.format.GMLBase.prototype.POLYGONMEMBER_PARSERS_ = { +ol.format.GMLBase.prototype.POLYGONMEMBER_PARSERS_ = Object({ 'http://www.opengis.net/gml' : { 'Polygon': ol.xml.makeArrayPusher( ol.format.GMLBase.prototype.readPolygon) } -}; +}); /** @@ -502,12 +502,12 @@ ol.format.GMLBase.prototype.POLYGONMEMBER_PARSERS_ = { * @type {Object.>} * @protected */ -ol.format.GMLBase.prototype.RING_PARSERS = { +ol.format.GMLBase.prototype.RING_PARSERS = Object({ 'http://www.opengis.net/gml' : { 'LinearRing': ol.xml.makeReplacer( ol.format.GMLBase.prototype.readFlatLinearRing_) } -}; +}); /** From d2904450488563531aa825184aae3b1ec273a17d Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 11:16:19 +0200 Subject: [PATCH 28/31] Make sure alias ol.format.GML show its content in apidoc --- src/ol/format/gml/gml3.js | 44 +++++++++++++++++++++++------------- src/ol/format/gml/gmlbase.js | 2 ++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/ol/format/gml/gml3.js b/src/ol/format/gml/gml3.js index 3a12b20a20..ca4a77488e 100644 --- a/src/ol/format/gml/gml3.js +++ b/src/ol/format/gml/gml3.js @@ -79,22 +79,6 @@ ol.format.GML3 = function(opt_options) { goog.inherits(ol.format.GML3, ol.format.GMLBase); - -/** - * @classdesc - * Feature format for reading and writing data in the GML format - * version 3.1.1. - * Currently only supports GML 3.1.1 Simple Features profile. - * - * @constructor - * @param {olx.format.GMLOptions=} opt_options - * Optional configuration object. - * @extends {ol.format.GMLBase} - * @api stable - */ -ol.format.GML = ol.format.GML3; - - /** * @const * @type {string} @@ -1313,3 +1297,31 @@ ol.format.GML3.prototype.writeFeaturesNode = function(features, opt_options) { this.writeFeatureMembers_(node, features, [context]); return node; }; + + + +/** + * @classdesc + * Feature format for reading and writing data in the GML format + * version 3.1.1. + * Currently only supports GML 3.1.1 Simple Features profile. + * + * @constructor + * @param {olx.format.GMLOptions=} opt_options + * Optional configuration object. + * @extends {ol.format.GMLBase} + * @api stable + */ +ol.format.GML = ol.format.GML3; + + +/** + * Encode an array of features in GML 3.1.1 Simple Features. + * + * @function + * @param {Array.} features Features. + * @param {olx.format.WriteOptions=} opt_options Options. + * @return {Node} Result. + * @api stable + */ +ol.format.GML.prototype.writeFeatures; diff --git a/src/ol/format/gml/gmlbase.js b/src/ol/format/gml/gmlbase.js index 1c917c3c2e..83b33f63ed 100644 --- a/src/ol/format/gml/gmlbase.js +++ b/src/ol/format/gml/gmlbase.js @@ -27,6 +27,8 @@ goog.require('ol.xml'); /** * @classdesc + * Abstract base class; normally only used for creating subclasses and not + * instantiated in apps. * Feature base format for reading and writing data in the GML format. * This class cannot be instantiate, it contains only base content that * is shared with versioned format classes ol.format.GML2 and From 8a07d241ff4715dbe6406c69f874ab97ddf06113 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 12:01:52 +0200 Subject: [PATCH 29/31] Add support for gml2 gml:box element --- src/ol/format/gml/gml2.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ol/format/gml/gml2.js b/src/ol/format/gml/gml2.js index 076f753cc3..f1564bc505 100644 --- a/src/ol/format/gml/gml2.js +++ b/src/ol/format/gml/gml2.js @@ -4,6 +4,7 @@ goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.dom.NodeType'); goog.require('goog.object'); +goog.require('ol.extent'); goog.require('ol.format.GML'); goog.require('ol.format.GMLBase'); goog.require('ol.format.XSD'); @@ -92,6 +93,24 @@ ol.format.GML2.prototype.readFlatCoordinates_ = function(node, objectStack) { }; +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.Extent|undefined} Envelope. + */ +ol.format.GML2.prototype.readBox_ = function(node, objectStack) { + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + goog.asserts.assert(node.localName == 'Box'); + var flatCoordinates = ol.xml.pushParseAndPop( + /** @type {Array.} */ ([null]), + this.BOX_PARSERS_, node, objectStack, this); + return ol.extent.createOrUpdate(flatCoordinates[1][0], + flatCoordinates[1][1], flatCoordinates[1][3], + flatCoordinates[1][4]); +}; + + /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. @@ -162,6 +181,19 @@ ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = Object({ }); +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML2.prototype.BOX_PARSERS_ = Object({ + 'http://www.opengis.net/gml' : { + 'coordinates': ol.xml.makeArrayPusher( + ol.format.GML2.prototype.readFlatCoordinates_) + } +}); + + /** * @const * @type {Object.>} @@ -180,6 +212,7 @@ ol.format.GML2.prototype.GEOMETRY_PARSERS_ = Object({ ol.format.GMLBase.prototype.readLinearRing), 'Polygon': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPolygon), 'MultiPolygon': ol.xml.makeReplacer( - ol.format.GMLBase.prototype.readMultiPolygon) + ol.format.GMLBase.prototype.readMultiPolygon), + 'Box': ol.xml.makeReplacer(ol.format.GML2.prototype.readBox_) } }); From 93db3d42b70bde0d1469003ea6f17258bd7a07c5 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 12:02:14 +0200 Subject: [PATCH 30/31] Add tests for gml2 gml:box element --- test/spec/ol/format/gmlformat.test.js | 11 +++++++++++ test/spec/ol/format/wfsformat.test.js | 2 ++ 2 files changed, 13 insertions(+) diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 0f7dd78349..be6c1d006b 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -35,6 +35,17 @@ describe('ol.format.GML2', function() { expect(g.getCoordinates()).to.eql([-180, -90, 0]); }); + it('can read a box element', function() { + var text = '' + + ' -0.768746,47.003018 ' + + ' 3.002191,47.925567' + + ''; + + var g = readGeometry(format, text); + expect(g).to.eql([47.003018, -0.768746, 47.925567, 3.002191]); + }); + it('can read a multipolygon with gml:coordinates', function() { var text = diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 33e8242c53..3362c3877d 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -80,6 +80,8 @@ describe('ol.format.WFS', function() { feature = features[0]; expect(feature.getId()).to.equal('1'); expect(feature.get('name')).to.equal('My Polygon with hole'); + expect(feature.get('boundedBy')).to.eql( + [47.003018, -0.768746, 47.925567, 0.532597]); expect(feature.getGeometry()).to.be.an(ol.geom.MultiPolygon); expect(feature.getGeometry().getFlatCoordinates()). to.have.length(60); From 27f32621ab92d72e5ecb5b4338f71d3d4199cdf0 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 12:09:22 +0200 Subject: [PATCH 31/31] Update comments on WFS format version --- src/ol/format/wfsformat.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 989efdda83..51e2ae9905 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -16,7 +16,8 @@ goog.require('ol.xml'); /** * @classdesc * Feature format for reading and writing data in the WFS format. - * Currently only supports WFS version 1.1.0. + * By default, supports WFS version 1.1.0. You can pass a GML format + * as option if you want to read a WFS that contains GML2 (WFS 1.0.0). * Also see {@link ol.format.GMLBase} which is used by this format. * * @constructor