From f8c6863fa7337e3c3c44bd7005bb10d4b9078fb1 Mon Sep 17 00:00:00 2001 From: Julien Enselme Date: Fri, 17 Feb 2017 16:28:52 +0100 Subject: [PATCH] Add GML2 serializer for Point --- src/ol/format/gml2.js | 10 ++++++++++ test/spec/ol/format/gml.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/ol/format/gml2.js b/src/ol/format/gml2.js index c57bae5391..74d9c256bc 100644 --- a/src/ol/format/gml2.js +++ b/src/ol/format/gml2.js @@ -498,6 +498,16 @@ ol.format.GML2.prototype.writeMultiCurveOrLineString_ = function(node, geometry, * @private */ ol.format.GML2.prototype.writePoint_ = function(node, geometry, objectStack) { + var context = objectStack[objectStack.length - 1]; + var srsName = context['srsName']; + if (srsName) { + node.setAttribute('srsName', srsName); + } + var coordinates = this.createCoordinatesNode_(node.namespaceURI); + node.appendChild(coordinates); + var point = geometry.getCoordinates(); + var coord = this.getCoords_(point, srsName); + ol.format.XSD.writeStringTextNode(coordinates, coord); }; diff --git a/test/spec/ol/format/gml.test.js b/test/spec/ol/format/gml.test.js index 4d31b029a3..1d99f12209 100644 --- a/test/spec/ol/format/gml.test.js +++ b/test/spec/ol/format/gml.test.js @@ -196,6 +196,33 @@ describe('ol.format.GML2', function() { expect(node).to.xmleql(ol.xml.parse(expected)); }); + + it('can serialize a Point', function() { + var expected = + '' + + ' ' + + ' ' + + ' ' + + ' 2,1.1' + + ' ' + + ' ' + + ' ' + + ' '; + + var feature = new ol.Feature({ + geometry: new ol.geom.Point([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)); + }); }); });