auto-configure featureType and featureNS. p=bartvde (closes #3367)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@12110 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -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 <featureNS>,
|
||||
* but auto-configured <featureNS> and <featureType> during read.
|
||||
* Subclasses making use of <featureType> auto-configuration should make
|
||||
* the first call to the <readNode> 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<len; ++i) {
|
||||
this.readNode(elements[i], {features: features});
|
||||
this.readNode(elements[i], {features: features}, true);
|
||||
}
|
||||
} else {
|
||||
// look for gml:featureMembers elements (this is v3, but does no harm here)
|
||||
@@ -173,13 +186,50 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
);
|
||||
if(elements.length) {
|
||||
// there can be only one
|
||||
this.readNode(elements[0], {features: features});
|
||||
this.readNode(elements[0], {features: features}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return features;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: readNode
|
||||
* Shorthand for applying one of the named readers given the node
|
||||
* namespace and local name. Readers take two args (node, obj) and
|
||||
* generally extend or modify the second.
|
||||
*
|
||||
* Parameters:
|
||||
* node - {DOMElement} The node to be read (required).
|
||||
* obj - {Object} The object to be modified (optional).
|
||||
* first - {Boolean} Should be set to true for the first node read. This
|
||||
* is usually the readNode call in the read method. Without this being
|
||||
* set, auto-configured properties will stick on subsequent reads.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} The input object, modified (or a new one if none was provided).
|
||||
*/
|
||||
readNode: function(node, obj, first) {
|
||||
// on subsequent calls of format.read(), we want to reset auto-
|
||||
// configured properties and auto-configure again.
|
||||
if (first === true && this.autoConfig === true) {
|
||||
this.featureType = null;
|
||||
delete this.namespaceAlias[this.featureNS];
|
||||
delete this.namespaces["feature"];
|
||||
this.featureNS = null;
|
||||
}
|
||||
// featureType auto-configuration
|
||||
if (!this.featureNS && (!(node.prefix in this.namespaces) &&
|
||||
node.parentNode.namespaceURI == this.namespaces["gml"] &&
|
||||
this.regExes.featureMember.test(node.parentNode.nodeName))) {
|
||||
this.featureType = node.nodeName.split(":").pop();
|
||||
this.setNamespace("feature", node.namespaceURI);
|
||||
this.featureNS = node.namespaceURI;
|
||||
this.autoConfig = true;
|
||||
}
|
||||
return OpenLayers.Format.XML.prototype.readNode.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
* Contains public functions, grouped by namespace prefix, that will
|
||||
|
||||
Reference in New Issue
Block a user