2
* Copyright (c) 2008-2010 The Open Source Geospatial Foundation
4
* Published under the BSD license.
5
* See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
9
Ext.namespace("GeoExt.tree");
12
* module = GeoExt.tree
13
* class = WMSCapabilitiesLoader
14
* base_link = `Ext.tree.TreeLoader <http://www.extjs.com/deploy/dev/docs/?class=Ext.tree.TreeLoader>`_
18
* .. class:: WMSCapabilitiesLoader
20
* A loader that will load all layers of a Web Map Service (WMS).
22
GeoExt.tree.WMSCapabilitiesLoader = function(config) {
23
Ext.apply(this, config);
24
GeoExt.tree.WMSCapabilitiesLoader.superclass.constructor.call(this);
27
Ext.extend(GeoExt.tree.WMSCapabilitiesLoader, Ext.tree.TreeLoader, {
31
* The online resource of the Web Map Service.
35
/** api: config[layerOptions]
37
* Optional options to set on the WMS layers which will be created by
42
/** api: config[layerParams]
44
* Optional parameters to set on the WMS layers which will be created by
49
/** private: property[requestMethod]
50
* ``String`` WMS GetCapabilities request needs to be done using HTTP GET
54
/** private: method[getParams]
55
* Private getParams override.
57
getParams: function(node) {
58
return {'service': 'WMS', 'request': 'GetCapabilities'};
61
/** private: method[processResponse]
62
* :param response: ``Object`` The XHR object
63
* :param node: ``Ext.tree.TreeNode``
64
* :param callback: ``Function``
65
* :param scope: ``Object``
67
* Private processResponse override.
69
processResponse : function(response, node, callback, scope){
70
//var capabilities = new OpenLayers.Format.WMSCapabilities().read(
71
// response.responseXML || response.responseText);
72
var data = response.responseText;
73
if (data.substring(0,6) == 'Status') {
74
// Proxy has had a problem, so bail-out
76
var capabilities = new OpenLayers.Format.WMSCapabilities().read(data);
77
this.processLayer(capabilities.capability,
78
capabilities.capability.request.getmap.href, node);
80
if (typeof callback == "function") {
81
callback.apply(scope || node, [node]);
85
/** private: method[createWMSLayer]
86
* :param layer: ``Object`` The layer object from the WMS GetCapabilities
88
* :param url: ``String`` The online resource of the WMS
89
* :return: ``OpenLayers.Layer.WMS`` or ``null`` The WMS layer created or
92
* Create a WMS layer which will be attached as an attribute to the
95
createWMSLayer: function(layer, url) {
97
return new OpenLayers.Layer.WMS( layer.title, url,
98
OpenLayers.Util.extend({formats: layer.formats[0],
99
layers: layer.name}, this.layerParams),
100
OpenLayers.Util.extend({minScale: layer.minScale,
101
queryable: layer.queryable, maxScale: layer.maxScale,
103
}, this.layerOptions));
109
/** private: method[processLayer]
110
* :param layer: ``Object`` The layer object from the WMS GetCapabilities
112
* :param url: ``String`` The online resource of the WMS
113
* :param node: ``Ext.tree.TreeNode``
115
* Recursive function to create the tree nodes for the layer structure
116
* of a WMS GetCapabilities response.
118
processLayer: function(layer, url, node) {
119
Ext.each(layer.nestedLayers, function(el) {
120
var n = this.createNode({text: el.title || el.name,
121
// use nodeType 'node' so no AsyncTreeNodes are created
123
layer: this.createWMSLayer(el, url),
124
leaf: (el.nestedLayers.length === 0)});
128
if (el.nestedLayers) {
129
this.processLayer(el, url, n);