Allowing for multiple feature types in a GML doc. Thanks bartvde for the patch and tests. r=me (closes #1838)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9149 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-03-31 21:22:48 +00:00
parent 0c1fe31b0a
commit ef23accd13
2 changed files with 39 additions and 3 deletions

View File

@@ -48,7 +48,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* APIProperty: featureType
* {String} The local (without prefix) feature typeName.
* {Array(String) or String} The local (without prefix) feature typeName(s).
*/
featureType: null,
@@ -94,6 +94,13 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
*/
geometryTypes: null,
/**
* Property: singleFeatureType
* {Boolean} True if there is only 1 featureType, and not an array
* of featuretypes.
*/
singleFeatureType: null,
/**
* Property: regExes
* Compiled regular expressions for manipulating strings.
@@ -116,7 +123,8 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
* this instance.
*
* Valid options properties:
* featureType - {String} Local (without prefix) feature typeName (required).
* featureType - {Array(String) or String} Local (without prefix) feature
* typeName(s) (required).
* featureNS - {String} Feature namespace (required).
* geometryName - {String} Geometry element name.
*/
@@ -126,6 +134,7 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
if(options && options.featureNS) {
this.setNamespace("feature", options.featureNS);
}
this.singleFeatureType = !options || (typeof options.featureType === "string");
},
/**
@@ -322,7 +331,11 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
// geometry or attributes.
var name;
var local = node.localName || node.nodeName.split(":").pop();
if(local == this.featureType) {
if (!this.singleFeatureType &&
(OpenLayers.Util.indexOf(this.featureType, local) != -1)) {
name = "_typeName";
}
else if(local == this.featureType) {
name = "_typeName";
} else {
// Assume attribute elements have one child node and that the child
@@ -350,6 +363,10 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
var feature = new OpenLayers.Feature.Vector(
container.components[0], container.attributes
);
if (!this.singleFeatureType) {
feature.type = node.nodeName.split(":").pop();
feature.namespace = node.namespaceURI;
}
var fid = node.getAttribute("fid") ||
this.getAttributeNS(node, this.namespaces["gml"], "id");
if(fid) {