parse annotation from WFS DescribeFeatureType schemas
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
/**
|
||||
* @requires OpenLayers/Format/XML.js
|
||||
* @requires OpenLayers/Format/OGCExceptionReport.js
|
||||
* @requires OpenLayers/Format/JSON.js
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -17,6 +18,22 @@
|
||||
*/
|
||||
OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
|
||||
OpenLayers.Format.XML, {
|
||||
|
||||
/**
|
||||
* Property: jsonFormat
|
||||
* {OpenLayers.Format.JSON}
|
||||
* Parser instance used to parse JSON for cross browser support. The native
|
||||
* JSON.parse method will be used where available (all except IE<8).
|
||||
*/
|
||||
jsonFormat: null,
|
||||
|
||||
/**
|
||||
* Property: regExes
|
||||
* Compiled regular expressions for manipulating strings.
|
||||
*/
|
||||
regExes: {
|
||||
trimSpace: (/^\s*|\s*$/g)
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: namespaces
|
||||
@@ -52,15 +69,16 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
|
||||
complexTypes: complexTypes,
|
||||
customTypes: customTypes
|
||||
};
|
||||
var i, len;
|
||||
|
||||
this.readChildNodes(node, schema);
|
||||
|
||||
var attributes = node.attributes;
|
||||
var attr, name;
|
||||
for(var i=0, len=attributes.length; i<len; ++i) {
|
||||
for(i=0, len=attributes.length; i<len; ++i) {
|
||||
attr = attributes[i];
|
||||
name = attr.name;
|
||||
if(name.indexOf("xmlns") == 0) {
|
||||
if(name.indexOf("xmlns") === 0) {
|
||||
this.setNamespace(name.split(":")[1] || "", attr.value);
|
||||
} else {
|
||||
obj[name] = attr.value;
|
||||
@@ -71,7 +89,7 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
|
||||
|
||||
// map complexTypes to names of customTypes
|
||||
var complexType, customType;
|
||||
for(var i=0, len=complexTypes.length; i<len; ++i) {
|
||||
for(i=0, len=complexTypes.length; i<len; ++i) {
|
||||
complexType = complexTypes[i];
|
||||
customType = customTypes[complexType.typeName];
|
||||
if(customTypes[complexType.typeName]) {
|
||||
@@ -103,6 +121,7 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
|
||||
obj.properties = sequence.elements;
|
||||
},
|
||||
"element": function(node, obj) {
|
||||
var type;
|
||||
if(obj.elements) {
|
||||
var element = {};
|
||||
var attributes = node.attributes;
|
||||
@@ -112,7 +131,7 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
|
||||
element[attr.name] = attr.value;
|
||||
}
|
||||
|
||||
var type = element.type;
|
||||
type = element.type;
|
||||
if(!type) {
|
||||
type = {};
|
||||
this.readChildNodes(node, type);
|
||||
@@ -122,10 +141,11 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
|
||||
var fullType = type.base || type;
|
||||
element.localType = fullType.split(":").pop();
|
||||
obj.elements.push(element);
|
||||
this.readChildNodes(node, element);
|
||||
}
|
||||
|
||||
if(obj.complexTypes) {
|
||||
var type = node.getAttribute("type");
|
||||
type = node.getAttribute("type");
|
||||
var localType = type.split(":").pop();
|
||||
obj.customTypes[localType] = {
|
||||
"name": node.getAttribute("name"),
|
||||
@@ -133,6 +153,24 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
|
||||
};
|
||||
}
|
||||
},
|
||||
"annotation": function(node, obj) {
|
||||
obj.annotation = {};
|
||||
this.readChildNodes(node, obj.annotation);
|
||||
},
|
||||
"appinfo": function(node, obj) {
|
||||
if (!this.jsonFormat) {
|
||||
this.jsonFormat = new OpenLayers.Format.JSON();
|
||||
}
|
||||
obj.appinfo = this.jsonFormat.read(this.getChildValue(node));
|
||||
},
|
||||
"documentation": function(node, obj) {
|
||||
if (!obj.documentation) {
|
||||
obj.documentation = {};
|
||||
}
|
||||
var lang = node.getAttribute("xml:lang");
|
||||
var value = this.getChildValue(node);
|
||||
obj.documentation[lang] = value.replace(this.regExes.trimSpace, "");
|
||||
},
|
||||
"simpleType": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user