diff --git a/lib/OpenLayers/Protocol/WFS.js b/lib/OpenLayers/Protocol/WFS.js index 89df923470..ca4ee5e9d7 100644 --- a/lib/OpenLayers/Protocol/WFS.js +++ b/lib/OpenLayers/Protocol/WFS.js @@ -47,7 +47,7 @@ OpenLayers.Protocol.WFS = function(options) { * * This function is designed to auto-configure , , * and for WFS 1.1.0. Note that - * srsName matching with the WMS layer will not work with WFS 1.0.0.. + * srsName matching with the WMS layer will not work with WFS 1.0.0. * * Parameters: * layer - {} WMS layer that has a matching WFS diff --git a/lib/OpenLayers/Protocol/WFS/v1.js b/lib/OpenLayers/Protocol/WFS/v1.js index 669c02990b..905dadcf60 100644 --- a/lib/OpenLayers/Protocol/WFS/v1.js +++ b/lib/OpenLayers/Protocol/WFS/v1.js @@ -43,7 +43,7 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, { /** * Property: geometryName * {String} Name of the geometry attribute for features. Default is - * "the_geom". + * "the_geom" for WFS 1.0, and null for higher versions. */ geometryName: "the_geom", @@ -102,19 +102,16 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, { * for this featureType). * featurePrefix - {String} Feature namespace alias (optional - only used * for writing if featureNS is provided). Default is 'feature'. - * geometryName - {String} Name of geometry attribute. If featureNS is not - * configured, the default is null to avoid failing on BBOX filters, - * and it will be set on . Otherwise, the default is 'the_geom'. + * geometryName - {String} Name of geometry attribute. The default is + * 'the_geom' for WFS 1.0, and null for higher versions. If + * null, it will be set to the name of the first geometry found in the + * first read operation. * multi - {Boolean} If set to true, geometries will be casted to Multi * geometries before they are written in a transaction. No casting will * be done when reading features. */ initialize: function(options) { OpenLayers.Protocol.prototype.initialize.apply(this, [options]); - if (!options.geometryName && !options.featureNS) { - // poorly configured protocol - try to not fail on BBOX filters - this.geometryName = null; - } if(!options.format) { this.format = OpenLayers.Format.WFST(OpenLayers.Util.extend({ version: this.version, @@ -126,6 +123,9 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, { schema: this.schema }, this.formatOptions)); } + if (!options.geometryName && parseFloat(this.format.version) > 1.0) { + this.setGeometryName(null); + } }, /** diff --git a/tests/Protocol/WFS.html b/tests/Protocol/WFS.html index b142b1d34d..cc56e459bc 100644 --- a/tests/Protocol/WFS.html +++ b/tests/Protocol/WFS.html @@ -111,7 +111,8 @@ var protocol = new OpenLayers.Protocol.WFS({ url: "http://some.url.org", featurePrefix: "topp", - featureType: "tasmania_roads" + featureType: "tasmania_roads", + geometryName: null }); protocol.parseResponse({responseText: document.getElementById("query_response").firstChild.nodeValue}); @@ -299,7 +300,7 @@ } function test_fromWMSLayer(t) { - t.plan(8); + t.plan(9); var map = new OpenLayers.Map("map", { projection: "EPSG:1234" }); @@ -313,6 +314,7 @@ t.eq(protocol.featureType, "states", "typeName correctly extracted"); t.eq(protocol.srsName, "EPSG:1234", "srsName set correctly"); t.eq(protocol.version, "1.1.0", "version set correctly"); + t.eq(protocol.format.geometryName, null, "format's geometryName set to null"); layer.params["LAYERS"] = ["topp:street_centerline", "topp:states"]; layer.projection = new OpenLayers.Projection("EPSG:900913");