diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 610bc1476f..a6a8c2cda2 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -9,6 +9,7 @@ goog.require('ol.extent'); goog.require('ol.format.XML'); goog.require('ol.geom.GeometryCollection'); goog.require('ol.geom.LineString'); +goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.MultiPoint'); goog.require('ol.geom.Point'); goog.require('ol.geom.Polygon'); @@ -97,7 +98,7 @@ ol.format.GML.readPoint_ = function(node, objectStack) { * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @private - * @return {ol.geom.MultiPoint|undefined} Point. + * @return {ol.geom.MultiPoint|undefined} MultiPoint. */ ol.format.GML.readMultiPoint_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); @@ -113,6 +114,28 @@ ol.format.GML.readMultiPoint_ = function(node, objectStack) { }; +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + * @return {ol.geom.MultiLineString|undefined} MultiLineString. + */ +ol.format.GML.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); + if (goog.isDefAndNotNull(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. @@ -120,11 +143,25 @@ ol.format.GML.readMultiPoint_ = function(node, objectStack) { */ ol.format.GML.pointMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); - goog.asserts.assert(node.localName == 'pointMember'); + goog.asserts.assert(node.localName == 'pointMember' || + node.localName == 'pointMembers'); ol.xml.parse(ol.format.GML.POINTMEMBER_PARSERS_, node, objectStack); }; +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @private + */ +ol.format.GML.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); +}; + + /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. @@ -478,6 +515,8 @@ ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS( 'Point': ol.xml.makeArrayPusher(ol.format.GML.readPoint_), 'MultiPoint': ol.xml.makeArrayPusher(ol.format.GML.readMultiPoint_), 'LineString': ol.xml.makeArrayPusher(ol.format.GML.readLineString_), + 'MultiLineString': ol.xml.makeArrayPusher( + ol.format.GML.readMultiLineString_), 'LinearRing' : ol.xml.makeArrayPusher(ol.format.GML.readLinearRing_), 'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_), 'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_), @@ -517,7 +556,22 @@ ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_ = ol.xml.makeParsersNS( */ ol.format.GML.MULTIPOINT_PARSERS_ = ol.xml.makeParsersNS( ol.format.GML.NAMESPACE_URIS_, { - 'pointMember': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_) + 'pointMember': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_), + 'pointMembers': ol.xml.makeArrayPusher(ol.format.GML.pointMemberParser_) + }); + + +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.MULTILINESTRING_PARSERS_ = ol.xml.makeParsersNS( + ol.format.GML.NAMESPACE_URIS_, { + 'lineStringMember': ol.xml.makeArrayPusher( + ol.format.GML.lineStringMemberParser_), + 'lineStringMembers': ol.xml.makeArrayPusher( + ol.format.GML.lineStringMemberParser_) }); @@ -533,6 +587,18 @@ ol.format.GML.POINTMEMBER_PARSERS_ = ol.xml.makeParsersNS( }); +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GML.LINESTRINGMEMBER_PARSERS_ = ol.xml.makeParsersNS( + ol.format.GML.NAMESPACE_URIS_, { + 'LineString': ol.xml.makeArrayPusher( + ol.format.GML.readLineString_) + }); + + /** * @const * @type {Object.>} diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 4d5d5c2fcf..9b54fa465e 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -180,6 +180,71 @@ describe('ol.format.GML', function() { expect(g.getCoordinates()).to.eql([[1, 2, 0], [2, 3, 0], [3, 4, 0]]); }); + it('can read a plural multipoint geometry', function() { + var text = + '' + + ' ' + + ' ' + + ' 1 2' + + ' ' + + ' ' + + ' 2 3' + + ' ' + + ' ' + + ' 3 4' + + ' ' + + ' ' + + ''; + var g = format.readGeometry(text); + expect(g).to.be.an(ol.geom.MultiPoint); + expect(g.getCoordinates()).to.eql([[1, 2, 0], [2, 3, 0], [3, 4, 0]]); + }); + + }); + + describe('multilinestring', function() { + + it('can read a singular multilinestring geometry', function() { + var text = + '' + + ' ' + + ' ' + + ' 1 2 2 3' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 3 4 4 5' + + ' ' + + ' ' + + ''; + var g = format.readGeometry(text); + 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]]]); + }); + + it('can read a plural multilinestring geometry', function() { + var text = + '' + + ' ' + + ' ' + + ' 1 2 2 3' + + ' ' + + ' ' + + ' 3 4 4 5' + + ' ' + + ' ' + + ''; + var g = format.readGeometry(text); + 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]]]); + }); + }); }); @@ -190,5 +255,6 @@ describe('ol.format.GML', function() { goog.require('ol.format.GML'); goog.require('ol.geom.LineString'); goog.require('ol.geom.MultiPoint'); +goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.Point'); goog.require('ol.geom.Polygon');