diff --git a/lib/OpenLayers/Format/GML/Base.js b/lib/OpenLayers/Format/GML/Base.js index f331b7d2ef..fed96e7f30 100644 --- a/lib/OpenLayers/Format/GML/Base.js +++ b/lib/OpenLayers/Format/GML/Base.js @@ -101,6 +101,18 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { * of featuretypes. */ singleFeatureType: null, + + /** + * Property: autoConfig + * {Boolean} Indicates if the format was configured without a , + * but auto-configured and during read. + * Subclasses making use of auto-configuration should make + * the first call to the method (usually in the read method) + * with true as 3rd argument, so the auto-configured featureType can be + * reset and the format can be reused for subsequent reads with data from + * different featureTypes. Set to false after read if you want to keep the + * auto-configured values. + */ /** * Property: regExes @@ -110,7 +122,8 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { trimSpace: (/^\s*|\s*$/g), removeSpace: (/\s*/g), splitSpace: (/\s+/), - trimComma: (/\s*,\s*/g) + trimComma: (/\s*,\s*/g), + featureMember: (/^(.*:)?featureMembers?$/) }, /** @@ -125,9 +138,9 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { * * Valid options properties: * featureType - {Array(String) or String} Local (without prefix) feature - * typeName(s) (required). - * featureNS - {String} Feature namespace (required). - * geometryName - {String} Geometry element name. + * typeName(s) (required for write). + * featureNS - {String} Feature namespace (required for write). + * geometryName - {String} Geometry element name (required for write). */ initialize: function(options) { OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); @@ -156,7 +169,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { data = data.documentElement; } var features = []; - this.readNode(data, {features: features}); + this.readNode(data, {features: features}, true); if(features.length == 0) { // look for gml:featureMember elements var elements = this.getElementsByTagNameNS( @@ -164,7 +177,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { ); if(elements.length) { for(var i=0, len=elements.length; i diff --git a/tests/Format/GML/v3.html b/tests/Format/GML/v3.html index 9858b94491..49b4905106 100644 --- a/tests/Format/GML/v3.html +++ b/tests/Format/GML/v3.html @@ -212,6 +212,26 @@ t.eq(attributes["LAND_KM"], "143986.61", "read LAND_KM"); } + function test_read_autoconfig(t) { + t.plan(7); + var doc = readXML("v3/topp-states-wfs.xml"); + var format = new OpenLayers.Format.GML.v3(); + var features = format.read(doc.documentElement); + + t.eq(features.length, 3, "read 3 features"); + var feature = features[0]; + t.eq(feature.fid, "states.1", "read fid"); + t.eq(feature.geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPolygon", + "read multipolygon geometry"); + t.eq(format.featureType, "states", "featureType correctly auto-configured"); + t.eq(format.featureNS, "http://www.openplans.org/topp", "featureNS correctly auto-configured"); + + t.eq(format.autoConfig, true, "autoConfig set to true"); + format.autoConfig = false; + format.read(doc.documentElement); + t.eq(format.autoConfig, false, "now that featureNS is set, the format does not auto-configure again"); + } + function test_emptyAttribute(t) { t.plan(4); var str =