From 650837b207661f9ef3687e6065d959d539d7b5d1 Mon Sep 17 00:00:00 2001 From: Julien Enselme Date: Fri, 17 Feb 2017 16:39:48 +0100 Subject: [PATCH] Add GML2 serializer for MultiPoint --- src/ol/format/gml2.js | 38 ++++++++++++++++++++++++++++++++- test/spec/ol/format/gml.test.js | 31 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/ol/format/gml2.js b/src/ol/format/gml2.js index 74d9c256bc..32c878ea86 100644 --- a/src/ol/format/gml2.js +++ b/src/ol/format/gml2.js @@ -517,7 +517,31 @@ ol.format.GML2.prototype.writePoint_ = function(node, geometry, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.GML2.prototype.writeMultiPoint_ = function(node, geometry, objectStack) { +ol.format.GML2.prototype.writeMultiPoint_ = function(node, geometry, + objectStack) { + var context = objectStack[objectStack.length - 1]; + var srsName = context['srsName']; + if (srsName) { + node.setAttribute('srsName', srsName); + } + var points = geometry.getPoints(); + ol.xml.pushSerializeAndPop({node: node, srsName: srsName}, + ol.format.GML2.POINTMEMBER_SERIALIZERS_, + ol.xml.makeSimpleNodeFactory('pointMember'), points, + objectStack, undefined, this); +}; + + +/** + * @param {Node} node Node. + * @param {ol.geom.Point} point Point geometry. + * @param {Array.<*>} objectStack Node stack. + * @private + */ +ol.format.GML2.prototype.writePointMember_ = function(node, point, objectStack) { + var child = ol.xml.createElementNS(node.namespaceURI, 'Point'); + node.appendChild(child); + this.writePoint_(child, point, objectStack); }; @@ -612,3 +636,15 @@ ol.format.GML2.RING_SERIALIZERS_ = { 'innerBoundaryIs': ol.xml.makeChildAppender(ol.format.GML2.prototype.writeRing_) } }; + + +/** + * @type {Object.>} + * @private + */ +ol.format.GML2.POINTMEMBER_SERIALIZERS_ = { + 'http://www.opengis.net/gml': { + 'pointMember': ol.xml.makeChildAppender( + ol.format.GML2.prototype.writePointMember_) + } +}; diff --git a/test/spec/ol/format/gml.test.js b/test/spec/ol/format/gml.test.js index 1d99f12209..f04615499f 100644 --- a/test/spec/ol/format/gml.test.js +++ b/test/spec/ol/format/gml.test.js @@ -223,6 +223,37 @@ describe('ol.format.GML2', function() { expect(node).to.xmleql(ol.xml.parse(expected)); }); + + it('can serialize a Multi Point', function() { + var expected = + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 2,1.1' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' '; + + var feature = new ol.Feature({ + geometry: new ol.geom.MultiPoint([[1.1, 2]]) + }); + feature.setId(1); + var objectStack = [{ + featureNS: featureNS, + srsName: 'EPSG:4326' + }]; + format.writeFeatureElement(node, feature, objectStack); + + expect(node).to.xmleql(ol.xml.parse(expected)); + }); }); });