~dongpo-deng/sahana-eden/test

« back to all changes in this revision

Viewing changes to static/scripts/gis/geoext/lib/GeoExt/widgets/tree/WMSCapabilitiesLoader.js

  • Committer: Deng Dongpo
  • Date: 2010-08-01 09:29:44 UTC
  • Revision ID: dongpo@dhcp-21193.iis.sinica.edu.tw-20100801092944-8t9obt4xtl7otesb
initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
 
3
 *
 
4
 * Published under the BSD license.
 
5
 * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
 
6
 * of the license.
 
7
 */
 
8
 
 
9
Ext.namespace("GeoExt.tree");
 
10
 
 
11
/** api: (define)
 
12
 *  module = GeoExt.tree
 
13
 *  class = WMSCapabilitiesLoader
 
14
 *  base_link = `Ext.tree.TreeLoader <http://www.extjs.com/deploy/dev/docs/?class=Ext.tree.TreeLoader>`_
 
15
 */
 
16
 
 
17
/** api: constructor
 
18
 *  .. class:: WMSCapabilitiesLoader
 
19
 *
 
20
 *      A loader that will load all layers of a Web Map Service (WMS).
 
21
 */
 
22
GeoExt.tree.WMSCapabilitiesLoader = function(config) {
 
23
    Ext.apply(this, config);
 
24
    GeoExt.tree.WMSCapabilitiesLoader.superclass.constructor.call(this);
 
25
};
 
26
 
 
27
Ext.extend(GeoExt.tree.WMSCapabilitiesLoader, Ext.tree.TreeLoader, {
 
28
 
 
29
    /** api: config[url]
 
30
     *  ``String``
 
31
     *  The online resource of the Web Map Service.
 
32
     */
 
33
    url: null,
 
34
 
 
35
    /** api: config[layerOptions]
 
36
     *  ``Object``
 
37
     *  Optional options to set on the WMS layers which will be created by
 
38
     *  this loader.
 
39
     */
 
40
    layerOptions: null,
 
41
 
 
42
    /** api: config[layerParams]
 
43
     *  ``Object``
 
44
     *  Optional parameters to set on the WMS layers which will be created by
 
45
     *  this loader.
 
46
     */
 
47
    layerParams: null,
 
48
 
 
49
    /** private: property[requestMethod]
 
50
     *  ``String`` WMS GetCapabilities request needs to be done using HTTP GET
 
51
     */
 
52
    requestMethod: 'GET',
 
53
 
 
54
    /** private: method[getParams]
 
55
     *  Private getParams override.
 
56
     */
 
57
    getParams: function(node) {
 
58
        return {'service': 'WMS', 'request': 'GetCapabilities'};
 
59
    },
 
60
 
 
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``
 
66
     *
 
67
     *  Private processResponse override.
 
68
     */
 
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
 
75
        } else {
 
76
            var capabilities = new OpenLayers.Format.WMSCapabilities().read(data);
 
77
            this.processLayer(capabilities.capability,
 
78
                capabilities.capability.request.getmap.href, node);
 
79
        }
 
80
        if (typeof callback == "function") {
 
81
            callback.apply(scope || node, [node]);
 
82
        }
 
83
    },
 
84
 
 
85
    /** private: method[createWMSLayer]
 
86
     *  :param layer: ``Object`` The layer object from the WMS GetCapabilities
 
87
     *  parser
 
88
     *  :param url: ``String`` The online resource of the WMS
 
89
     *  :return: ``OpenLayers.Layer.WMS`` or ``null`` The WMS layer created or
 
90
     *  null.
 
91
     *
 
92
     *  Create a WMS layer which will be attached as an attribute to the
 
93
     *  node.
 
94
     */
 
95
    createWMSLayer: function(layer, url) {
 
96
        if (layer.name) {
 
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,
 
102
                    metadata: layer
 
103
                }, this.layerOptions));
 
104
        } else {
 
105
            return null;
 
106
        }
 
107
    },
 
108
 
 
109
    /** private: method[processLayer]
 
110
     *  :param layer: ``Object`` The layer object from the WMS GetCapabilities
 
111
     *  parser
 
112
     *  :param url: ``String`` The online resource of the WMS
 
113
     *  :param node: ``Ext.tree.TreeNode``
 
114
     *
 
115
     *  Recursive function to create the tree nodes for the layer structure
 
116
     *  of a WMS GetCapabilities response.
 
117
     */
 
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
 
122
                nodeType: 'node',
 
123
                layer: this.createWMSLayer(el, url),
 
124
                leaf: (el.nestedLayers.length === 0)});
 
125
            if(n){
 
126
                node.appendChild(n);
 
127
            }
 
128
            if (el.nestedLayers) {
 
129
                this.processLayer(el, url, n);
 
130
            }
 
131
        }, this);
 
132
    }
 
133
 
 
134
});