From c530f872f9d566beb89f7c4ee4fe784dd116b2e1 Mon Sep 17 00:00:00 2001 From: Andreas Watermeyer Date: Tue, 7 Apr 2015 10:32:26 +0200 Subject: [PATCH 1/4] #3328 - GML3: Writing features with multiple geometries --- src/ol/format/gml/gml3format.js | 2 +- .../wfs/TransactionUpdateMultiGeoms.xml | 30 +++++++++++++++ test/spec/ol/format/wfsformat.test.js | 38 +++++++++++++++++++ test/test-extensions.js | 1 + 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml diff --git a/src/ol/format/gml/gml3format.js b/src/ol/format/gml/gml3format.js index 3d9a7a2d5d..528c8c343b 100644 --- a/src/ol/format/gml/gml3format.js +++ b/src/ol/format/gml/gml3format.js @@ -1072,7 +1072,7 @@ ol.format.GML3.prototype.writeFeatureElement = if (!goog.isNull(value)) { keys.push(key); values.push(value); - if (key == geometryName) { + if (key == geometryName || value instanceof ol.geom.Geometry) { if (!(key in context.serializers[featureNS])) { context.serializers[featureNS][key] = ol.xml.makeChildAppender( this.writeGeometryElement, this); diff --git a/test/spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml b/test/spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml new file mode 100644 index 0000000000..a65488f311 --- /dev/null +++ b/test/spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml @@ -0,0 +1,30 @@ + + + + + + + + + -12279454 6741885 -12064207 + 6732101 -11941908 6595126 + -12240318 6507071 -12416429 + 6604910 + + + + + + + + + -12000000 6700000 -12000001 6700001 -12000002 6700002 + + + + + + + diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index db52d424c5..b9c1fe717a 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -328,6 +328,42 @@ describe('ol.format.WFS', function() { }); }); + + describe('when writing out a Transaction request', function() { + var text; + before(function(done) { + afterLoadText('spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml', function(xml) { + text = xml; + done(); + }); + }); + + it('handles multiple geometries', function() { + var format = new ol.format.WFS(); + var updateFeature = new ol.Feature(); + updateFeature.setGeometryName('the_geom'); + updateFeature.setGeometry(new ol.geom.MultiLineString([[ + [-12279454, 6741885], + [-12064207, 6732101], + [-11941908, 6595126], + [-12240318, 6507071], + [-12416429, 6604910] + ]])); + updateFeature.set('geom2',new ol.geom.MultiLineString([[ + [-12000000, 6700000], + [-12000001, 6700001], + [-12000002, 6700002] + ]])); + var serialized = format.writeTransaction([updateFeature], [], null, { + featureNS: 'http://foo', + featureType: 'FAULTS', + featurePrefix: 'foo', + gmlOptions: {srsName: 'EPSG:900913'} + }); + expect(serialized).to.xmleql(ol.xml.parse(text)); + }); + }); + describe('when writing out a Transaction request', function() { var text; before(function(done) { @@ -396,6 +432,8 @@ describe('ol.format.WFS', function() { }); }); + + describe('when writing out a GetFeature request', function() { var text; before(function(done) { diff --git a/test/test-extensions.js b/test/test-extensions.js index c9cdac18a5..9bd0c62204 100644 --- a/test/test-extensions.js +++ b/test/test-extensions.js @@ -207,6 +207,7 @@ if (node2Attr[name] === undefined) { errors.push('Attribute name ' + node1Attr[name].name + ' expected for element ' + node1.nodeName); + break; } // test attribute namespace // we do not care about the difference between an empty string and From 5fb7a8bc3412e10485fa7b35c8e29d667a634763 Mon Sep 17 00:00:00 2001 From: awaterme Date: Thu, 8 Oct 2015 16:52:32 +0200 Subject: [PATCH 2/4] #3328: Reformatted details. --- test/spec/ol/format/wfsformat.test.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index b9c1fe717a..6fdd6ecdbd 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -332,10 +332,12 @@ describe('ol.format.WFS', function() { describe('when writing out a Transaction request', function() { var text; before(function(done) { - afterLoadText('spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml', function(xml) { - text = xml; - done(); - }); + afterLoadText('spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml', + function(xml) { + text = xml; + done(); + } + ); }); it('handles multiple geometries', function() { @@ -349,7 +351,7 @@ describe('ol.format.WFS', function() { [-12240318, 6507071], [-12416429, 6604910] ]])); - updateFeature.set('geom2',new ol.geom.MultiLineString([[ + updateFeature.set('geom2', new ol.geom.MultiLineString([[ [-12000000, 6700000], [-12000001, 6700001], [-12000002, 6700002] From 4c207d9460dbb6f7d71ba65725c6591ecbd3babc Mon Sep 17 00:00:00 2001 From: Andreas Watermeyer Date: Thu, 8 Oct 2015 17:09:48 +0200 Subject: [PATCH 3/4] #3328: Reformat once again --- test/spec/ol/format/wfsformat.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 6fdd6ecdbd..89cf3e4aae 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -330,10 +330,9 @@ describe('ol.format.WFS', function() { describe('when writing out a Transaction request', function() { - var text; - before(function(done) { - afterLoadText('spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml', - function(xml) { + var text, filename = 'spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml'; + before(function (done) { + afterLoadText(filename, function (xml) { text = xml; done(); } From 687a65aa9558b5b4fc58a11587b5a8b7b36c1e4f Mon Sep 17 00:00:00 2001 From: Andreas Watermeyer Date: Thu, 8 Oct 2015 17:21:15 +0200 Subject: [PATCH 4/4] #3328: reformatted fixjsstyle --- test/spec/ol/format/wfsformat.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 89cf3e4aae..613bf245a3 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -331,11 +331,11 @@ describe('ol.format.WFS', function() { describe('when writing out a Transaction request', function() { var text, filename = 'spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml'; - before(function (done) { - afterLoadText(filename, function (xml) { - text = xml; - done(); - } + before(function(done) { + afterLoadText(filename, function(xml) { + text = xml; + done(); + } ); });