From e86396059911f33af97f76192a69d84084ee7ada Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 10 Jun 2022 18:17:26 +0200 Subject: [PATCH] Support reading polygons with curve rings --- src/ol/format/GML3.js | 32 ++++++++++++++++++++++++ src/ol/format/GML32.js | 8 +++++- test/browser/spec/ol/format/gml.test.js | 33 +++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/ol/format/GML3.js b/src/ol/format/GML3.js index 3cca0a2a47..28ab6ee76f 100644 --- a/src/ol/format/GML3.js +++ b/src/ol/format/GML3.js @@ -134,6 +134,27 @@ class GML3 extends GMLBase { } } + /** + * @param {Element} node Node. + * @param {Array<*>} objectStack Object stack. + * @return {Array|undefined} Polygon. + */ + readFlatCurveRing(node, objectStack) { + /** @type {Array} */ + const lineStrings = pushParseAndPop( + [], + this.MULTICURVE_PARSERS, + node, + objectStack, + this + ); + const flatCoordinates = []; + for (let i = 0, ii = lineStrings.length; i < ii; ++i) { + extend(flatCoordinates, lineStrings[i].getFlatCoordinates()); + } + return flatCoordinates; + } + /** * @param {Element} node Node. * @param {Array<*>} objectStack Object stack. @@ -1162,6 +1183,17 @@ GML3.prototype.SEGMENTS_PARSERS = { }, }; +/** + * @const + * @type {Object>} + */ +GMLBase.prototype.RING_PARSERS = { + 'http://www.opengis.net/gml': { + 'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing), + 'Ring': makeReplacer(GML3.prototype.readFlatCurveRing), + }, +}; + /** * Encode an array of features in GML 3.1.1 Simple Features. * diff --git a/src/ol/format/GML32.js b/src/ol/format/GML32.js index 6519564e99..7063b538a6 100644 --- a/src/ol/format/GML32.js +++ b/src/ol/format/GML32.js @@ -4,7 +4,12 @@ import GML2 from './GML2.js'; import GML3 from './GML3.js'; import GMLBase from './GMLBase.js'; -import {makeArrayPusher, makeChildAppender, makeReplacer} from '../xml.js'; +import { + makeArrayExtender, + makeArrayPusher, + makeChildAppender, + makeReplacer, +} from '../xml.js'; import {writeStringTextNode} from '../format/xsd.js'; /** @@ -249,6 +254,7 @@ GML32.prototype.POLYGONMEMBER_PARSERS = { GML32.prototype.RING_PARSERS = { 'http://www.opengis.net/gml/3.2': { 'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing), + 'Ring': makeReplacer(GML32.prototype.readFlatCurveRing), }, }; diff --git a/test/browser/spec/ol/format/gml.test.js b/test/browser/spec/ol/format/gml.test.js index d793d26be4..efd4e7dcb9 100644 --- a/test/browser/spec/ol/format/gml.test.js +++ b/test/browser/spec/ol/format/gml.test.js @@ -2290,6 +2290,39 @@ describe('ol.format.GML32', function () { ''; expect(serialized.firstElementChild).to.xmleql(parse(expected)); }); + + it('can read a polygon with a ring of curves', function () { + const text = ` + + + + + + + + 1 2 3 4 + + + 5 6 7 8 + + + + + + + + `; + const g = readGeometry(format, text); + expect(g).to.be.an(Polygon); + expect(g.getCoordinates()).to.eql([ + [ + [1, 2, 0], + [3, 4, 0], + [5, 6, 0], + [7, 8, 0], + ], + ]); + }); }); describe('envelope', function () {