diff --git a/src/ol/format/GML3.js b/src/ol/format/GML3.js index e1d6a878d0..3cca0a2a47 100644 --- a/src/ol/format/GML3.js +++ b/src/ol/format/GML3.js @@ -13,6 +13,7 @@ import { XML_SCHEMA_INSTANCE_URI, createElementNS, getAllTextContent, + makeArrayExtender, makeArrayPusher, makeChildAppender, makeReplacer, @@ -189,13 +190,7 @@ class GML3 extends GMLBase { * @return {Array|undefined} flat coordinates. */ readSegment(node, objectStack) { - return pushParseAndPop( - [null], - this.SEGMENTS_PARSERS, - node, - objectStack, - this - ); + return pushParseAndPop([], this.SEGMENTS_PARSERS, node, objectStack, this); } /** @@ -1161,7 +1156,9 @@ GML3.prototype.PATCHES_PARSERS = { */ GML3.prototype.SEGMENTS_PARSERS = { 'http://www.opengis.net/gml': { - 'LineStringSegment': makeReplacer(GML3.prototype.readLineStringSegment), + 'LineStringSegment': makeArrayExtender( + GML3.prototype.readLineStringSegment + ), }, }; diff --git a/src/ol/format/GML32.js b/src/ol/format/GML32.js index 193d9b2378..6519564e99 100644 --- a/src/ol/format/GML32.js +++ b/src/ol/format/GML32.js @@ -169,7 +169,9 @@ GML32.prototype.PATCHES_PARSERS = { */ GML32.prototype.SEGMENTS_PARSERS = { 'http://www.opengis.net/gml/3.2': { - 'LineStringSegment': makeReplacer(GML3.prototype.readLineStringSegment), + 'LineStringSegment': makeArrayExtender( + GML3.prototype.readLineStringSegment + ), }, }; diff --git a/test/browser/spec/ol/format/gml.test.js b/test/browser/spec/ol/format/gml.test.js index 3c28d0c46e..d793d26be4 100644 --- a/test/browser/spec/ol/format/gml.test.js +++ b/test/browser/spec/ol/format/gml.test.js @@ -2252,6 +2252,44 @@ describe('ol.format.GML32', function () { const serialized = format.writeGeometryNode(g); expect(serialized.firstElementChild).to.xmleql(parse(text)); }); + + it('can read and write a curve geometry', function () { + const text = + '' + + ' ' + + ' ' + + ' 1 2 3 4' + + ' ' + + ' ' + + ' 5 6 7 8' + + ' ' + + ' ' + + ''; + const g = readGeometry(format, text); + expect(g).to.be.an(LineString); + expect(g.getCoordinates()).to.eql([ + [1, 2, 0], + [3, 4, 0], + [5, 6, 0], + [7, 8, 0], + ]); + format = new GML32({srsName: 'CRS:84', curve: true}); + const serialized = format.writeGeometryNode(g); + // Conversion back to GML is not lossless, because we don't know + // the mapping of original LineString segements to the OpenLayers + // LineString geometry's coordinates. + const expected = + '' + + ' ' + + ' ' + + ' 1 2 3 4 5 6 7 8' + + ' ' + + ' ' + + ''; + expect(serialized.firstElementChild).to.xmleql(parse(expected)); + }); }); describe('envelope', function () {