From 17fefda8fd4fc3a95368374f4da88c0ff74816e8 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 2 Aug 2013 15:52:10 +0200 Subject: [PATCH] implement GMLReadOptions and GMLWriteOptions as discussed with @ahocevar --- src/objectliterals.jsdoc | 15 +++ src/ol/parser/ogc/gml.js | 96 ++++++++++++++----- src/ol/parser/ogc/gml_v2.js | 18 ++-- src/ol/parser/ogc/gml_v3.js | 38 ++++---- test/spec/ol/parser/ogc/gml_v2.test.js | 30 +++--- test/spec/ol/parser/ogc/gml_v3.test.js | 39 +++++--- .../gml_v2/geometrycollection-coordinates.xml | 8 +- .../ogc/xml/gml_v2/linearring-coordinates.xml | 2 +- .../ogc/xml/gml_v2/linestring-coordinates.xml | 2 +- .../gml_v2/multilinestring-coordinates.xml | 2 +- .../ogc/xml/gml_v2/multipoint-coordinates.xml | 2 +- .../xml/gml_v2/multipolygon-coordinates.xml | 2 +- .../ol/parser/ogc/xml/gml_v2/point-coord.xml | 2 +- .../ogc/xml/gml_v2/point-coordinates.xml | 2 +- .../ogc/xml/gml_v2/polygon-coordinates.xml | 2 +- test/spec/ol/parser/ogc/xml/gml_v3/curve.xml | 2 +- .../ol/parser/ogc/xml/gml_v3/linearring.xml | 2 +- .../ol/parser/ogc/xml/gml_v3/linestring.xml | 2 +- .../ogc/xml/gml_v3/multicurve-curve.xml | 2 +- .../ogc/xml/gml_v3/multicurve-singular.xml | 2 +- .../xml/gml_v3/multilinestring-singular.xml | 2 +- .../ogc/xml/gml_v3/multipoint-singular.xml | 2 +- .../ogc/xml/gml_v3/multipolygon-singular.xml | 2 +- .../ogc/xml/gml_v3/multisurface-singular.xml | 2 +- .../ogc/xml/gml_v3/multisurface-surface.xml | 2 +- test/spec/ol/parser/ogc/xml/gml_v3/point.xml | 2 +- .../spec/ol/parser/ogc/xml/gml_v3/polygon.xml | 2 +- .../spec/ol/parser/ogc/xml/gml_v3/surface.xml | 2 +- 28 files changed, 186 insertions(+), 100 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 3d4bf7d6c3..497b911024 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -354,6 +354,17 @@ * parse. */ +/** + * @typedef {Object} ol.parser.GMLReadOptions + * @property {string|undefined} axisOrientation The axis orientation. + */ + +/** + * @typedef {Object} ol.parser.GMLWriteOptions + * @property {ol.ProjectionLike} srsName The srsName to use when writing. + * @property {string|undefined} axisOrientation The axis orientation. + */ + /** * @typedef {Object} ol.parser.GMLOptions * @property {boolean|undefined} curve Write gml:Curve instead of @@ -379,6 +390,10 @@ * @property {boolean|undefined} surface Write gml:Surface instead of * gml:Polygon elements. This also affects the elements in multi-part * geometries. Default is `false“. This only applies to GML version 3. + * @property {ol.parser.GMLReadOptions|undefined} readOptions readOptions to + * use for this instance. + * @property {ol.parser.GMLWriteOptions|undefined} writeOptions writeOptions + * to use for this instance. */ /** diff --git a/src/ol/parser/ogc/gml.js b/src/ol/parser/ogc/gml.js index 5418c33253..8d271561a0 100644 --- a/src/ol/parser/ogc/gml.js +++ b/src/ol/parser/ogc/gml.js @@ -1,5 +1,6 @@ goog.provide('ol.parser.ogc.GML'); goog.require('goog.array'); +goog.require('goog.asserts'); goog.require('goog.dom.xml'); goog.require('ol.Feature'); goog.require('ol.geom.Geometry'); @@ -38,6 +39,8 @@ ol.parser.ogc.GML = function(opt_options) { options.multiCurve : true; this.multiSurface = goog.isDef(options.multiSurface) ? options.multiSurface : true; + this.readOptions = options.readOptions; + this.writeOptions = options.writeOptions; /** * @protected @@ -72,6 +75,17 @@ ol.parser.ogc.GML = function(opt_options) { 'http://www.opengis.net/gml': { '_inherit': function(node, obj, container) { // To be implemented by version specific parsers + var srsName; + if (!goog.isDef(this.srsName)) { + srsName = this.srsName = node.getAttribute('srsName'); + } + if (!goog.isDef(this.axisOrientation)) { + if (goog.isDefAndNotNull(srsName)) { + this.axisOrientation = ol.proj.get(srsName).getAxisOrientation(); + } else { + this.axisOrientation = 'enu'; + } + } }, 'name': function(node, obj) { obj.name = this.getChildValue(node); @@ -136,6 +150,8 @@ ol.parser.ogc.GML = function(opt_options) { }, 'Point': function(node, container) { var coordinates = []; + this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, + [node, coordinates, container]); this.readChildNodes(node, coordinates); var point = { type: ol.geom.GeometryType.POINT, @@ -207,7 +223,7 @@ ol.parser.ogc.GML = function(opt_options) { var points = new Array(numPoints); for (var i = 0; i < numPoints; ++i) { coords = goog.array.map(pointList[i].split(cs), parseFloat); - if (this.getAxisOrientation().substr(0, 2) === 'en') { + if (this.axisOrientation.substr(0, 2) === 'en') { points[i] = coords; } else { if (coords.length === 2) { @@ -314,7 +330,7 @@ ol.parser.ogc.GML = function(opt_options) { } // TODO: Deal with GML documents that do not have the same SRS for all // geometries. - var srsName; + /*var srsName; if (!goog.isDef(this.srsName)) { for (var i = node.childNodes.length - 1; i >= 0; --i) { var child = node.childNodes[i]; @@ -331,7 +347,7 @@ ol.parser.ogc.GML = function(opt_options) { if (goog.isDef(srsName)) { this.axisOrientation = ol.proj.get(srsName).getAxisOrientation(); } - } + }*/ this.readChildNodes(node, obj); }, '_attribute': function(node, obj) { @@ -464,9 +480,8 @@ ol.parser.ogc.GML = function(opt_options) { } else if (type === ol.geom.GeometryType.GEOMETRYCOLLECTION) { child = this.writeNode('GeometryCollection', geometry, null, node); } - if (goog.isDef(this.getSrsName())) { - this.setAttributeNS(child, null, 'srsName', - ol.proj.get(this.getSrsName()).getCode()); + if (goog.isDef(this.srsName)) { + this.setAttributeNS(child, null, 'srsName', this.srsName); } return node; }, @@ -484,27 +499,28 @@ ol.parser.ogc.GML = function(opt_options) { goog.inherits(ol.parser.ogc.GML, ol.parser.XML); -/** - * @return {string?} Axis orientation. - */ -ol.parser.ogc.GML.prototype.getAxisOrientation = function() { - return goog.isDef(this.axisOrientation) ? this.axisOrientation : 'enu'; -}; - - -/** - * @return {string|undefined} SRS name. - */ -ol.parser.ogc.GML.prototype.getSrsName = function() { - return this.srsName; -}; - - /** * @param {string|Document|Element|Object} data Data to read. + * @param {ol.parser.GMLReadOptions=} opt_options Read options. * @return {ol.parser.ReadFeaturesResult} An object representing the document. */ -ol.parser.ogc.GML.prototype.read = function(data) { +ol.parser.ogc.GML.prototype.read = function(data, opt_options) { + var srsName; + if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) { + srsName = opt_options.srsName; + } else if (goog.isDef(this.readOptions) && + goog.isDef(this.readOptions.srsName)) { + srsName = this.readOptions.srsName; + } + if (goog.isDef(srsName)) { + this.srsName = goog.isString(srsName) ? srsName : srsName.getCode(); + } + if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) { + this.axisOrientation = opt_options.axisOrientation; + } else if (goog.isDef(this.readOptions) && + goog.isDef(this.readOptions.axisOrientation)) { + this.axisOrientation = this.readOptions.axisOrientation; + } if (typeof data == 'string') { data = goog.dom.xml.loadXml(data); } @@ -515,6 +531,8 @@ ol.parser.ogc.GML.prototype.read = function(data) { ({features: [], metadata: {}}); this.readNode(data, obj, true); obj.metadata.projection = this.srsName; + delete this.srsName; + delete this.axisOrientation; return obj; }; @@ -626,3 +644,35 @@ ol.parser.ogc.GML.prototype.readFeaturesWithMetadataFromString = this.readFeaturesOptions_ = opt_options; return this.read(str); }; + + +/** + * @protected + * Handle the writeOptions passed into the write function. + * @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as + * GML. + * @param {ol.parser.GMLWriteOptions=} opt_options Write options. + */ +ol.parser.ogc.GML.prototype.handleWriteOptions = function(obj, opt_options) { + // srsName handling: opt_options takes precedence over obj.metadata + var srsName; + if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) { + srsName = opt_options.srsName; + } else if (goog.isDef(this.writeOptions) && + goog.isDef(this.writeOptions.srsName)) { + srsName = this.writeOptions.srsName; + } else if (goog.isDef(obj.metadata)) { + srsName = obj.metadata.projection; + } + goog.asserts.assert(goog.isDef(srsName)); + this.srsName = goog.isString(srsName) ? srsName : srsName.getCode(); + // axisOrientation handling + if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) { + this.axisOrientation = opt_options.axisOrientation; + } else if (goog.isDef(this.writeOptions) && + goog.isDef(this.writeOptions.axisOrientation)) { + this.axisOrientation = this.writeOptions.axisOrientation; + } else { + this.axisOrientation = ol.proj.get(this.srsName).getAxisOrientation(); + } +}; diff --git a/src/ol/parser/ogc/gml_v2.js b/src/ol/parser/ogc/gml_v2.js index 113e65924d..e9bb62bb06 100644 --- a/src/ol/parser/ogc/gml_v2.js +++ b/src/ol/parser/ogc/gml_v2.js @@ -3,7 +3,6 @@ goog.provide('ol.parser.ogc.GML_v2'); goog.require('goog.array'); goog.require('goog.object'); goog.require('ol.parser.ogc.GML'); -goog.require('ol.proj'); @@ -29,6 +28,8 @@ ol.parser.ogc.GML_v2 = function(opt_options) { }, 'Box': function(node, container) { var coordinates = []; + this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, + [node, coordinates, container]); this.readChildNodes(node, coordinates); container.bounds = [coordinates[0][0][0], coordinates[0][1][0], coordinates[0][0][1], coordinates[0][1][1]]; @@ -46,7 +47,7 @@ ol.parser.ogc.GML_v2 = function(opt_options) { for (var i = 0; i < numCoordinates; ++i) { var coord = coordinates[i]; var part = goog.array.concat(coord); - if (this.getAxisOrientation().substr(0, 2) !== 'en') { + if (this.axisOrientation.substr(0, 2) !== 'en') { part[0] = coord[1]; part[1] = coord[0]; } @@ -102,8 +103,8 @@ ol.parser.ogc.GML_v2 = function(opt_options) { this.writeNode('coordinates', [[extent.minX, extent.minY], [extent.maxX, extent.maxY]], null, node); // srsName attribute is optional for gml:Box - if (goog.isDef(this.getSrsName())) { - node.setAttribute('srsName', this.getSrsName()); + if (goog.isDef(this.srsName)) { + node.setAttribute('srsName', this.srsName); } return node; } @@ -115,13 +116,11 @@ goog.inherits(ol.parser.ogc.GML_v2, ol.parser.ogc.GML); /** * @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as * GML. + * @param {ol.parser.GMLWriteOptions=} opt_options Write options. * @return {string} A string representing the GML document. */ -ol.parser.ogc.GML_v2.prototype.write = function(obj) { - if (goog.isDef(obj.metadata)) { - this.srsName = goog.isDef(obj.metadata.projection) ? - ol.proj.get(obj.metadata.projection).getCode() : undefined; - } +ol.parser.ogc.GML_v2.prototype.write = function(obj, opt_options) { + this.handleWriteOptions(obj, opt_options); var root = this.writeNode('FeatureCollection', obj.features, 'http://www.opengis.net/wfs'); this.setAttributeNS( @@ -129,5 +128,6 @@ ol.parser.ogc.GML_v2.prototype.write = function(obj) { 'xsi:schemaLocation', this.schemaLocation); var gml = this.serialize(root); delete this.srsName; + delete this.axisOrientation; return gml; }; diff --git a/src/ol/parser/ogc/gml_v3.js b/src/ol/parser/ogc/gml_v3.js index a7f9096cac..ebf321c37b 100644 --- a/src/ol/parser/ogc/gml_v3.js +++ b/src/ol/parser/ogc/gml_v3.js @@ -4,7 +4,6 @@ goog.require('goog.array'); goog.require('goog.object'); goog.require('ol.geom.GeometryType'); goog.require('ol.parser.ogc.GML'); -goog.require('ol.proj'); @@ -56,14 +55,15 @@ ol.parser.ogc.GML_v3 = function(opt_options) { } else if (type === ol.geom.GeometryType.GEOMETRYCOLLECTION) { child = this.writeNode('MultiGeometry', geometry, null, node); } - if (goog.isDef(this.getSrsName())) { - this.setAttributeNS(child, null, 'srsName', - ol.proj.get(this.getSrsName()).getCode()); + if (goog.isDef(this.srsName)) { + this.setAttributeNS(child, null, 'srsName', this.srsName); } return node; }; + var baseInherit = this.readers['http://www.opengis.net/gml']['_inherit']; goog.object.extend(this.readers['http://www.opengis.net/gml'], { '_inherit': function(node, obj, container) { + baseInherit.call(this, node, obj, container); // SRSReferenceGroup attributes var dim = parseInt(node.getAttribute('srsDimension'), 10) || (container && container.srsDimension); @@ -103,7 +103,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) { this.regExes.trimSpace, ''); var coords = goog.array.map(str.split(this.regExes.splitSpace), parseFloat); - if (this.getAxisOrientation().substr(0, 2) === 'en') { + if (this.axisOrientation.substr(0, 2) === 'en') { obj.push([coords]); } else { if (coords.length === 2) { @@ -127,7 +127,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) { for (var i = 0, ii = coords.length; i < ii; i += dim) { x = parseFloat(coords[i]); y = parseFloat(coords[i + 1]); - var xy = this.getAxisOrientation().substr(0, 2) === 'en'; + var xy = this.axisOrientation.substr(0, 2) === 'en'; if (dim === 3) { if (xy) { points[i / dim] = [x, y, parseFloat(coords[i + 2])]; @@ -207,6 +207,8 @@ ol.parser.ogc.GML_v3 = function(opt_options) { }, 'Envelope': function(node, container) { var coordinates = []; + this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, + [node, coordinates, container]); this.readChildNodes(node, coordinates); container.bounds = [coordinates[0][0][0][0], coordinates[1][0][0][0], coordinates[0][0][0][1], coordinates[1][0][0][1]]; @@ -240,7 +242,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) { 'pos': function(point) { // only 2d for simple features profile var pos; - if (this.getAxisOrientation().substr(0, 2) === 'en') { + if (this.axisOrientation.substr(0, 2) === 'en') { pos = (point[0] + ' ' + point[1]); } else { pos = (point[1] + ' ' + point[0]); @@ -276,7 +278,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) { var point; for (var i = 0; i < len; ++i) { point = points[i]; - if (this.getAxisOrientation().substr(0, 2) === 'en') { + if (this.axisOrientation.substr(0, 2) === 'en') { parts[i] = point[0] + ' ' + point[1]; } else { parts[i] = point[1] + ' ' + point[0]; @@ -375,15 +377,15 @@ ol.parser.ogc.GML_v3 = function(opt_options) { this.writeNode('lowerCorner', bounds, null, node); this.writeNode('upperCorner', bounds, null, node); // srsName attribute is required for gml:Envelope - if (this.getSrsName()) { - node.setAttribute('srsName', this.getSrsName()); + if (goog.isDef(this.srsName)) { + node.setAttribute('srsName', this.srsName); } return node; }, 'lowerCorner': function(bounds) { // only 2d for simple features profile var pos; - if (this.getAxisOrientation().substr(0, 2) === 'en') { + if (this.axisOrientation.substr(0, 2) === 'en') { pos = (bounds.left + ' ' + bounds.bottom); } else { pos = (bounds.bottom + ' ' + bounds.left); @@ -395,7 +397,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) { 'upperCorner': function(bounds) { // only 2d for simple features profile var pos; - if (this.getAxisOrientation().substr(0, 2) === 'en') { + if (this.axisOrientation.substr(0, 2) === 'en') { pos = (bounds.right + ' ' + bounds.top); } else { pos = (bounds.top + ' ' + bounds.right); @@ -410,19 +412,19 @@ goog.inherits(ol.parser.ogc.GML_v3, ol.parser.ogc.GML); /** - * @param {Object} obj Object structure to write out as XML. + * @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as + * XML. + * @param {ol.parser.GMLWriteOptions=} opt_options Write options. * @return {string} An string representing the XML document. */ -ol.parser.ogc.GML_v3.prototype.write = function(obj) { - if (goog.isDef(obj.metadata)) { - this.srsName = goog.isDef(obj.metadata.projection) ? - ol.proj.get(obj.metadata.projection).getCode() : undefined; - } +ol.parser.ogc.GML_v3.prototype.write = function(obj, opt_options) { + this.handleWriteOptions(obj, opt_options); var root = this.writeNode('featureMembers', obj.features); this.setAttributeNS( root, 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', this.schemaLocation); var gml = this.serialize(root); delete this.srsName; + delete this.axisOrientation; return gml; }; diff --git a/test/spec/ol/parser/ogc/gml_v2.test.js b/test/spec/ol/parser/ogc/gml_v2.test.js index 0a4f6596ed..3955af80c9 100644 --- a/test/spec/ol/parser/ogc/gml_v2.test.js +++ b/test/spec/ol/parser/ogc/gml_v2.test.js @@ -18,11 +18,12 @@ describe('ol.parser.gml_v2', function() { var url = 'spec/ol/parser/ogc/xml/gml_v2/point-coordinates.xml'; afterLoadXml(url, function(xml) { var obj = parser.read(xml); + parser.handleWriteOptions(obj); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('point'); expect(obj.geometry.coordinates).to.eql([1, 2]); @@ -47,10 +48,11 @@ describe('ol.parser.gml_v2', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multipoint'); expect(obj.geometry.parts.length).to.eql(3); @@ -76,10 +78,11 @@ describe('ol.parser.gml_v2', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('linestring'); expect(obj.geometry.coordinates.length).to.eql(2); @@ -104,10 +107,11 @@ describe('ol.parser.gml_v2', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multilinestring'); expect(obj.geometry.parts.length).to.eql(2); @@ -138,10 +142,11 @@ describe('ol.parser.gml_v2', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('polygon'); done(); @@ -162,10 +167,11 @@ describe('ol.parser.gml_v2', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multipolygon'); expect(obj.geometry.parts.length).to.eql(2); @@ -180,10 +186,11 @@ describe('ol.parser.gml_v2', function() { var p = new ol.parser.ogc.GML_v2({featureNS: 'http://foo'}); var obj = p.read(xml); var geom = p.createGeometry_({geometry: obj.geometry}); - p.srsName = 'EPSG:4326'; + p.handleWriteOptions(obj); var node = p.featureNSWiters_['_geometry'].apply(p, [geom]).firstChild; delete p.srsName; + delete p.axisOrientation; expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('geometrycollection'); expect(obj.geometry.parts.length).to.eql(3); @@ -224,10 +231,11 @@ describe('ol.parser.gml_v2', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('linearring'); expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4], [5, 6], @@ -249,10 +257,8 @@ describe('ol.parser.gml_v2', function() { schemaLocation: schemaLoc}); // overwrite the axis orientation of the projection, since WFS 1.0.0 // always uses enu - p.axisOrientation = 'enu'; - var obj = p.read(xml); - delete p.axisOrientation; - var output = p.write(obj); + var obj = p.read(xml, {axisOrientation: 'enu'}); + var output = p.write(obj, {axisOrientation: 'enu'}); expect(goog.dom.xml.loadXml(output)).to.xmleql(xml); expect(obj.features.length).to.eql(3); var feature = obj.features[0]; diff --git a/test/spec/ol/parser/ogc/gml_v3.test.js b/test/spec/ol/parser/ogc/gml_v3.test.js index da829d0e93..6dec1b94d2 100644 --- a/test/spec/ol/parser/ogc/gml_v3.test.js +++ b/test/spec/ol/parser/ogc/gml_v3.test.js @@ -18,10 +18,11 @@ describe('ol.parser.gml_v3', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('linearring'); expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4], [5, 6], @@ -34,10 +35,11 @@ describe('ol.parser.gml_v3', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('linestring'); expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]); @@ -60,10 +62,11 @@ describe('ol.parser.gml_v3', function() { var p = new ol.parser.ogc.GML_v3({curve: true}); var obj = p.read(xml); var geom = p.createGeometry_({geometry: obj.geometry}); - p.srsName = 'EPSG:4326'; + p.handleWriteOptions(obj); var node = p.featureNSWiters_['_geometry'].apply(p, [geom]).firstChild; delete p.srsName; + delete p.axisOrientation; expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('linestring'); expect(obj.geometry.coordinates).to.eql([[1, 2], [3, 4]]); @@ -87,10 +90,11 @@ describe('ol.parser.gml_v3', function() { var p = new ol.parser.ogc.GML_v3({multiCurve: false}); var obj = p.read(xml); var geom = p.createGeometry_({geometry: obj.geometry}); - p.srsName = 'EPSG:4326'; + p.handleWriteOptions(obj); var node = p.featureNSWiters_['_geometry'].apply(p, [geom]).firstChild; delete p.srsName; + delete p.axisOrientation; expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multilinestring'); expect(obj.geometry.parts.length).to.eql(2); @@ -103,10 +107,11 @@ describe('ol.parser.gml_v3', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multilinestring'); expect(obj.geometry.parts.length).to.eql(2); @@ -121,10 +126,11 @@ describe('ol.parser.gml_v3', function() { var p = new ol.parser.ogc.GML_v3({curve: true}); var obj = p.read(xml); var geom = p.createGeometry_({geometry: obj.geometry}); - p.srsName = 'EPSG:4326'; + p.handleWriteOptions(obj); var node = p.featureNSWiters_['_geometry'].apply(p, [geom]).firstChild; delete p.srsName; + delete p.axisOrientation; expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multilinestring'); expect(obj.geometry.parts.length).to.eql(2); @@ -149,10 +155,11 @@ describe('ol.parser.gml_v3', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multipoint'); expect(obj.geometry.parts.length).to.eql(3); @@ -177,10 +184,11 @@ describe('ol.parser.gml_v3', function() { var p = new ol.parser.ogc.GML_v3({multiSurface: false}); var obj = p.read(xml); var geom = p.createGeometry_({geometry: obj.geometry}); - p.srsName = 'EPSG:4326'; + p.handleWriteOptions(obj); var node = p.featureNSWiters_['_geometry'].apply(p, [geom]).firstChild; delete p.srsName; + delete p.axisOrientation; expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multipolygon'); expect(obj.geometry.parts.length).to.eql(2); @@ -203,10 +211,11 @@ describe('ol.parser.gml_v3', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multipolygon'); expect(obj.geometry.parts.length).to.eql(2); @@ -220,10 +229,11 @@ describe('ol.parser.gml_v3', function() { var p = new ol.parser.ogc.GML_v3({surface: true}); var obj = p.read(xml); var geom = p.createGeometry_({geometry: obj.geometry}); - p.srsName = 'EPSG:4326'; + p.handleWriteOptions(obj); var node = p.featureNSWiters_['_geometry'].apply(p, [geom]).firstChild; delete p.srsName; + delete p.axisOrientation; expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('multipolygon'); expect(obj.geometry.parts.length).to.eql(2); @@ -236,10 +246,11 @@ describe('ol.parser.gml_v3', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('point'); expect(obj.geometry.coordinates).to.eql([1, 2]); @@ -251,10 +262,11 @@ describe('ol.parser.gml_v3', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = parser.createGeometry_({geometry: obj.geometry}); - parser.srsName = 'EPSG:4326'; + parser.handleWriteOptions(obj); var node = parser.featureNSWiters_['_geometry'].apply(parser, [geom]).firstChild; delete parser.srsName; + delete parser.axisOrientation; expect(goog.dom.xml.loadXml(parser.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('polygon'); done(); @@ -266,10 +278,11 @@ describe('ol.parser.gml_v3', function() { var p = new ol.parser.ogc.GML_v3({surface: true}); var obj = p.read(xml); var geom = p.createGeometry_({geometry: obj.geometry}); - p.srsName = 'EPSG:4326'; + p.handleWriteOptions(obj, {srsName: 'foo'}); var node = p.featureNSWiters_['_geometry'].apply(p, [geom]).firstChild; delete p.srsName; + delete p.axisOrientation; expect(goog.dom.xml.loadXml(p.serialize(node))).to.xmleql(xml); expect(obj.geometry.type).to.eql('polygon'); done(); diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/geometrycollection-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/geometrycollection-coordinates.xml index 9ac91d395f..bec4cf48c4 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/geometrycollection-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/geometrycollection-coordinates.xml @@ -1,16 +1,16 @@ - + - + 1,2 - + 1,2 3,4 - + 1,2 3,2 3,4 1,2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/linearring-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/linearring-coordinates.xml index 8dc456b0d8..a069c8d7dc 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/linearring-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/linearring-coordinates.xml @@ -1,3 +1,3 @@ - + 1,2 3,4 5,6 1,2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/linestring-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/linestring-coordinates.xml index a2c25f91dc..0831331f0b 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/linestring-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/linestring-coordinates.xml @@ -1,3 +1,3 @@ - + 1,2 3,4 diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/multilinestring-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/multilinestring-coordinates.xml index 0e143bf99d..a5d87dbf0c 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/multilinestring-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/multilinestring-coordinates.xml @@ -1,4 +1,4 @@ - + 1,2 2,3 diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/multipoint-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/multipoint-coordinates.xml index fedf5403a3..07063c8a73 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/multipoint-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/multipoint-coordinates.xml @@ -1,4 +1,4 @@ - + 1,2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/multipolygon-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/multipolygon-coordinates.xml index a5c3b123f2..26de3d3422 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/multipolygon-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/multipolygon-coordinates.xml @@ -1,4 +1,4 @@ - + diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/point-coord.xml b/test/spec/ol/parser/ogc/xml/gml_v2/point-coord.xml index 47e4bedfbe..3f1be05b3c 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/point-coord.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/point-coord.xml @@ -1,4 +1,4 @@ - + 1 2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/point-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/point-coordinates.xml index 2d987cc20e..1e3d56dd8e 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/point-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/point-coordinates.xml @@ -1,3 +1,3 @@ - + 1,2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v2/polygon-coordinates.xml b/test/spec/ol/parser/ogc/xml/gml_v2/polygon-coordinates.xml index e86b75be60..5a5085e3cb 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v2/polygon-coordinates.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v2/polygon-coordinates.xml @@ -1,4 +1,4 @@ - + 1,2 5,2 5,6 1,2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/curve.xml b/test/spec/ol/parser/ogc/xml/gml_v3/curve.xml index 4dc1abccbe..c12b9ccab7 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/curve.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/curve.xml @@ -1,4 +1,4 @@ - + 1 2 3 4 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/linearring.xml b/test/spec/ol/parser/ogc/xml/gml_v3/linearring.xml index dc2a1fbd31..49d966a527 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/linearring.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/linearring.xml @@ -1,3 +1,3 @@ - + 1 2 3 4 5 6 1 2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/linestring.xml b/test/spec/ol/parser/ogc/xml/gml_v3/linestring.xml index b6642c1af9..b7f67f80bb 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/linestring.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/linestring.xml @@ -1,3 +1,3 @@ - + 1 2 3 4 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-curve.xml b/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-curve.xml index 13172f8ba9..fdd79f1701 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-curve.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-curve.xml @@ -1,4 +1,4 @@ - + diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-singular.xml b/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-singular.xml index 502392356b..03e71f0d99 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-singular.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/multicurve-singular.xml @@ -1,4 +1,4 @@ - + 1 2 2 3 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/multilinestring-singular.xml b/test/spec/ol/parser/ogc/xml/gml_v3/multilinestring-singular.xml index 34a1f281bb..6877f95ea4 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/multilinestring-singular.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/multilinestring-singular.xml @@ -1,4 +1,4 @@ - + 1 2 2 3 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/multipoint-singular.xml b/test/spec/ol/parser/ogc/xml/gml_v3/multipoint-singular.xml index 43f3bf6599..8ee3026634 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/multipoint-singular.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/multipoint-singular.xml @@ -1,4 +1,4 @@ - + 1 2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/multipolygon-singular.xml b/test/spec/ol/parser/ogc/xml/gml_v3/multipolygon-singular.xml index 05b0de054a..9ea5339d87 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/multipolygon-singular.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/multipolygon-singular.xml @@ -1,4 +1,4 @@ - + diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-singular.xml b/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-singular.xml index c7ed5b6e8c..bf6eb737af 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-singular.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-singular.xml @@ -1,4 +1,4 @@ - + diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-surface.xml b/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-surface.xml index f2291646c4..7fe394769f 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-surface.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/multisurface-surface.xml @@ -1,4 +1,4 @@ - + diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/point.xml b/test/spec/ol/parser/ogc/xml/gml_v3/point.xml index 864891c0c1..8ff86123bb 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/point.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/point.xml @@ -1,3 +1,3 @@ - + 1 2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/polygon.xml b/test/spec/ol/parser/ogc/xml/gml_v3/polygon.xml index 8cc2c1818f..e9c467e02b 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/polygon.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/polygon.xml @@ -1,4 +1,4 @@ - + 1 2 3 2 3 4 1 2 diff --git a/test/spec/ol/parser/ogc/xml/gml_v3/surface.xml b/test/spec/ol/parser/ogc/xml/gml_v3/surface.xml index 3292537b0f..4bfea73303 100644 --- a/test/spec/ol/parser/ogc/xml/gml_v3/surface.xml +++ b/test/spec/ol/parser/ogc/xml/gml_v3/surface.xml @@ -1,4 +1,4 @@ - +