diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index d08b6e0e30..6c3d3935c5 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -680,8 +680,18 @@ ol.format.GML.readFlatCoordinatesFromNode_ = function(node, objectStack) { * @return {Array.|undefined} Flat coordinates. */ ol.format.GML.readFlatPos_ = function(node, objectStack) { - var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, ''); - var flatCoordinates = goog.array.map(s.split(/\s+/), parseFloat); + var s = ol.xml.getAllTextContent(node, false); + var re = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\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'); @@ -691,7 +701,13 @@ ol.format.GML.readFlatPos_ = function(node, objectStack) { axisOrientation = proj.getAxisOrientation(); } if (axisOrientation === 'neu') { - flatCoordinates = flatCoordinates.reverse(); + 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) { diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 330c900dbb..0b251f0257 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -547,7 +547,7 @@ ol.format.WFS.writeGetFeature_ = function(node, featureTypes, objectStack) { /** * @param {olx.format.WFSWriteGetFeatureOptions} options Options. - * @return {ArrayBuffer|Node|Object|string} Result. + * @return {Node} Result. */ ol.format.WFS.prototype.writeGetFeature = function(options) { var node = ol.xml.createElementNS('http://www.opengis.net/wfs', @@ -598,7 +598,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) { * @param {Array.} updates The features to update. * @param {Array.} deletes The features to delete. * @param {olx.format.WFSWriteTransactionOptions} options Write options. - * @return {ArrayBuffer|Node|Object|string} Result. + * @return {Node} Result. */ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, options) { diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 473fbcc9a6..0040f3ade2 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -33,6 +33,19 @@ describe('ol.format.GML', function() { expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); + it('can read and write a point geometry in EPSG:4326', function() { + var text = + '' + + ' 2 1' + + ''; + var g = readGeometry(formatWGS84, text); + expect(g).to.be.an(ol.geom.Point); + expect(g.getCoordinates()).to.eql([1, 2, 0]); + var serialized = formatWGS84.writeGeometry(g); + expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + }); + }); describe('linestring', function() { @@ -50,6 +63,19 @@ describe('ol.format.GML', function() { expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); + it('can read and write a linestring geometry in EPSG:4326', function() { + var text = + '' + + ' 2 1 4 3' + + ''; + var g = readGeometry(formatWGS84, text); + expect(g).to.be.an(ol.geom.LineString); + expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]); + var serialized = formatWGS84.writeGeometry(g); + expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + }); + }); describe('axis order', function() {