修正WFS服务1.1.0版本的GetCapabilities信息解析问题
修正WFS服务1.1.0版本的GetCapabilities信息解析不完正的问题:
参考:http://trac.osgeo.org/openlayers/ticket/3285
/**
* @requires OpenLayers/Format/WFSCapabilities.js
* @requires OpenLayers/Format/OWSCommon/v1_1_0.js
*/
/**
* Class: OpenLayers.Format.WFSCapabilities/v1_1_0
* Read WFS Capabilities version 1.1.0.
*
* Inherits from:
* - <OpenLayers.Format.WFSCapabilities>
*/
OpenLayers.Format.WFSCapabilities.v1_1_0 = OpenLayers.Class(
OpenLayers.Format.OWSCommon.v1_1_0, {
/**
* Property: version
* {String} The parser version ("1.1.0").
*/
version: "1.1.0",
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
ows: "http://www.opengis.net/ows",
wfs: "http://www.opengis.net/wfs",
xlink: "http://www.w3.org/1999/xlink"
},
/**
* Property: defaultPrefix
* {String} The default namespace alias for creating element nodes.
*/
defaultPrefix: "wfs",
/**
* Constructor: OpenLayers.Format.WFSCapabilities.v1_1_0
* Create a new parser for WFS capabilities version 1.1.0.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
this.options = options;
},
/**
* APIMethod: read
* Read capabilities data from a string, and return info about the WFS.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Information about the WFS service.
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var capabilities = {};
this.readNode(data, capabilities);
capabilities.version = this.version;
return capabilities;
},
/**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
* name. The function will be applied in the scope of this parser
* with two arguments: the node being read and a context object passed
* from the parent.
*/
readers: {
"wfs": {
"WFS_Capabilities": function(node, obj) {
this.readChildNodes(node, obj);
},
"FeatureTypeList": function(node, obj) {
obj.featureTypeList = {};
obj.featureTypeList.featureTypes = [];
this.readChildNodes(node, obj.featureTypeList);
},
"FeatureType": function(node, obj) {
var featureType = {
};
this.readChildNodes(node, featureType);
obj.featureTypes.push(featureType);
},
"Name": function(node, obj) {
var name = this.getChildValue(node);
if (name) {
var parts = name.split(":");
obj.name = parts.pop();
if (parts.length > 0) {
obj.featureNS = this.lookupNamespaceURI(node, parts[0]);
}
}
},
"Title": function(node, obj) {
obj.title = this.getChildValue(node);
},
"FeatureNS": function(node, obj) {
obj.featureNS = this.getChildValue(node);
},
"DefaultSRS": function(node, obj) {
var defaultSRS = this.getChildValue(node);
if (defaultSRS) {
obj.defaultSrs = defaultSRS;
}
},
"OutputFormats": function(node, obj) {
obj.outputFormats = [];
this.readChildNodes(node, obj.outputFormats);
},
"Format": function(node, obj) {
obj.push(this.getChildValue(node));
}
},
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
},
CLASS_NAME: "OpenLayers.Format.WFSCapabilities.v1_1_0"
});
转载自:https://blog.csdn.net/zhangjie617/article/details/6602651