[Commits] r2132 - in sandbox/bartvde/playground/geoext.ux/ux/WMSTree: . lib lib/GeoExt.ux

commits at geoext.org commits at geoext.org
Tue Apr 27 14:45:30 CEST 2010


Author: bartvde
Date: 2010-04-27 14:45:30 +0200 (Tue, 27 Apr 2010)
New Revision: 2132

Added:
   sandbox/bartvde/playground/geoext.ux/ux/WMSTree/lib/
   sandbox/bartvde/playground/geoext.ux/ux/WMSTree/lib/GeoExt.ux/
   sandbox/bartvde/playground/geoext.ux/ux/WMSTree/lib/GeoExt.ux/WMSLoader.js
   sandbox/bartvde/playground/geoext.ux/ux/WMSTree/tests/
Log:
first try on WMS Loader

Added: sandbox/bartvde/playground/geoext.ux/ux/WMSTree/lib/GeoExt.ux/WMSLoader.js
===================================================================
--- sandbox/bartvde/playground/geoext.ux/ux/WMSTree/lib/GeoExt.ux/WMSLoader.js	                        (rev 0)
+++ sandbox/bartvde/playground/geoext.ux/ux/WMSTree/lib/GeoExt.ux/WMSLoader.js	2010-04-27 12:45:30 UTC (rev 2132)
@@ -0,0 +1,99 @@
+Ext.namespace("GeoExt.ux");
+
+GeoExt.ux.WMSLoader = function(config) {
+    Ext.apply(this, config);
+    // TODO add events?
+    GeoExt.ux.WMSLoader.superclass.constructor.call(this);
+};
+
+Ext.extend(GeoExt.ux.WMSLoader, Ext.util.Observable, {
+
+    url: null,
+
+    load: function(node, callback, scope) {
+        if(this.clearOnLoad){
+            while(node.firstChild){
+                node.removeChild(node.firstChild);
+            }
+        }
+        this.requestData(node, callback, scope || node); 
+    },
+
+    requestData: function(node, callback, scope){
+        if(this.fireEvent("beforeload", this, node, callback) !== false){
+            this.transId = Ext.Ajax.request({
+                method: 'GET',
+                url: this.url,
+                params: {'service': 'WMS', 'request': 'GetCapabilities'},
+                success: this.handleResponse,
+                failure: this.handleFailure,
+                scope: this,
+                argument: {callback: callback, node: node, scope: scope}
+            });
+        } else {
+            // if the load is cancelled, make sure we notify
+            // the node that we are done
+            this.runCallback(callback, scope || node, []);
+        }
+    },
+
+    // private
+    runCallback: function(cb, scope, args){
+        if(Ext.isFunction(cb)){
+            cb.apply(scope, args);
+        }
+    },
+
+    createNode : function(attr){
+        // apply baseAttrs, nice idea Corey!
+        if(this.baseAttrs){
+            Ext.applyIf(attr, this.baseAttrs);
+        }
+        if(this.applyLoader !== false && !attr.loader){
+            attr.loader = this;
+        }
+        if(Ext.isString(attr.uiProvider)){
+           attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
+        }
+        if(attr.nodeType){
+            return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
+        }else{
+            return new Ext.tree.TreeNode(attr);
+        }
+    }, 
+
+    processResponse : function(response, node, callback, scope){
+        var caps = new OpenLayers.Format.WMSCapabilities().read(response.responseXML || response.responseText);
+        if (caps.capability) {
+            this.processLayer(caps.capability, node); 
+        }
+        this.runCallback(callback, scope || node, [node]);
+    }, 
+
+    processLayer: function(layer, node) {
+        Ext.each(layer.nestedLayers, function(el) {
+            var n = this.createNode({text: el.title, 
+                leaf: (el.nestedLayers.length === 0)});
+            if(n){
+                node.appendChild(n);
+            }
+            if (el.nestedLayers) {
+                this.processLayer(el, n);
+            }
+        }, this);
+    },
+
+    handleResponse : function(response){
+        this.transId = false;
+        var a = response.argument;
+        this.processResponse(response, a.node, a.callback, a.scope);
+        this.fireEvent("load", this, a.node, response);
+    },
+
+    handleFailure : function(response){
+        this.transId = false;
+        var a = response.argument;
+        this.fireEvent("loadexception", this, a.node, response);
+        this.runCallback(a.callback, a.scope || a.node, [a.node]);
+    }
+});



More information about the Commits mailing list