diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 6c1a3cb112..54b56f58bf 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -1269,6 +1269,30 @@ ol.format.GML.writeMultiPoint_ = function(node, geometry, }; +/** + * @param {Node} node Node. + * @param {ol.geom.MultiLineString} geometry MultiLineString geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.writeMultiLineString_ = function(node, geometry, + objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + if (goog.isDefAndNotNull(srsName)) { + node.setAttribute('srsName', srsName); + } + var lines = geometry.getLineStrings(); + for (var i = 0, ii = lines.length; i < ii; ++i) { + ol.xml.pushSerializeAndPop({node: node, srsName: srsName}, + ol.format.GML.LINESTRINGMEMBER_SERIALIZERS_, + ol.xml.makeSimpleNodeFactory('lineStringMember'), [lines[i]], + objectStack); + } +}; + + /** * @param {Node} node Node. * @param {ol.geom.LinearRing} ring LinearRing geometry. @@ -1321,6 +1345,23 @@ ol.format.GML.writePointMember_ = function(node, point, objectStack) { }; +/** + * @param {Node} node Node. + * @param {ol.geom.LineString} line LineString geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML.writeLineStringMember_ = function(node, line, objectStack) { + var context = objectStack[objectStack.length - 1]; + goog.asserts.assert(goog.isObject(context)); + var srsName = goog.object.get(context, 'srsName'); + ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ + ({node: node, srsName: srsName, writeSrsName: false}), + ol.format.GML.GEOMETRY_SERIALIZERS_, + ol.format.GML.GEOMETRY_NODE_FACTORY_, [line], []); +}; + + /** * @param {Node} node Node. * @param {ol.geom.Polygon} polygon Polygon geometry. @@ -1377,6 +1418,18 @@ ol.format.GML.POINTMEMBER_SERIALIZERS_ = { }; +/** + * @type {Object.>} + * @private + */ +ol.format.GML.LINESTRINGMEMBER_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'lineStringMember': ol.xml.makeChildAppender( + ol.format.GML.writeLineStringMember_) + } +}; + + /** * @type {Object.>} * @private @@ -1444,6 +1497,8 @@ ol.format.GML.GEOMETRY_SERIALIZERS_ = { 'Point': ol.xml.makeChildAppender(ol.format.GML.writePoint_), 'MultiPoint': ol.xml.makeChildAppender(ol.format.GML.writeMultiPoint_), 'LineString': ol.xml.makeChildAppender(ol.format.GML.writeLineString_), + 'MultiLineString': ol.xml.makeChildAppender( + ol.format.GML.writeMultiLineString_), 'LinearRing': ol.xml.makeChildAppender(ol.format.GML.writeLinearRing_), 'Polygon': ol.xml.makeChildAppender(ol.format.GML.writePolygon_), 'Surface': ol.xml.makeChildAppender(ol.format.GML.writeSurface_), diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 8a1bfdc1ee..da05ccd515 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -306,7 +306,7 @@ describe('ol.format.GML', function() { describe('multilinestring', function() { - it('can read a singular multilinestring geometry', function() { + it('can read and write a singular multilinestring geometry', function() { var text = '' + @@ -325,6 +325,8 @@ describe('ol.format.GML', function() { 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]]]); + var serialized = format.writeGeometry(g); + expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); }); it('can read a plural multilinestring geometry', function() {