[Commits] r256 - sandbox/opengeo/geoexplorer/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Tue Mar 24 00:39:10 CET 2009


Author: tschaub
Date: 2009-03-24 00:39:10 +0100 (Tue, 24 Mar 2009)
New Revision: 256

Modified:
   sandbox/opengeo/geoexplorer/lib/GeoExt/data/WMSCapabilitiesReader.js
Log:
making the wms capabilities reader look a bit more like other readers

Modified: sandbox/opengeo/geoexplorer/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- sandbox/opengeo/geoexplorer/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-03-23 22:52:13 UTC (rev 255)
+++ sandbox/opengeo/geoexplorer/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-03-23 23:39:10 UTC (rev 256)
@@ -1,30 +1,102 @@
+/**
+ * Copyright (c) 2008 The Open Planning Project
+ */
+
 Ext.namespace("GeoExt.data");
 
-GeoExt.data.WMSCapabilitiesReader = function(opts){
-    GeoExt.data.WMSCapabilitiesReader.superclass.constructor.apply(this, arguments);
-    this.recordType = this.recordType || Ext.data.Record.create([
-        {name: 'name', type: 'string'},
-        {name: 'abstract', type: 'string'},
-        {name: 'title', type: 'string'},
-        {name: 'prefix', type: 'string', defaultValue: ""},
-        {name: 'llbbox', type: 'auto'},
-        {name: 'styles', type: 'auto'},
-        {name: 'formats', type: 'auto'},
-        {name: 'queryable', type: 'boolean'}
-    ]);
+/**
+ * Class: GeoExt.data.WMSCapabilitiesReader
+ * Data reader class to provide an array of {Ext.data.Record} objects given
+ *     a WMS GetCapabilities response for use by an {Ext.data.Store}
+ *     object.
+ *
+ * Extends:
+ *  - Ext.data.DataReader
+ */
+
+/**
+ * Constructor: GeoExt.data.WMSCapabilitiesReader
+ * Create a new attributes reader object.
+ *
+ * Parameters:
+ * meta - {Object} Reader configuration.
+ * recordType - {Array | Ext.data.Record} An array of field configuration
+ *     objects or a record object.  Default is <GeoExt.data.LayerRecord>.
+ *     TODO: only works with LayerRecord right now (see #27).
+ *
+ * Configuration options (meta properties):
+ * format - {OpenLayers.Format} A parser for transforming the XHR response
+ *     into an array of objects representing attributes.  Defaults to
+ *     an {OpenLayers.Format.WMSCapabilities} parser.
+ */
+GeoExt.data.WMSCapabilitiesReader = function(meta, recordType) {
+    meta = meta || {};
+    if(!meta.format) {
+        meta.format = new OpenLayers.Format.WMSCapabilities();
+    }
+    GeoExt.data.WMSCapabilitiesReader.superclass.constructor.call(
+        this, meta, recordType || meta.fields || GeoExt.data.LayerRecord
+    );
 };
 
 Ext.extend(GeoExt.data.WMSCapabilitiesReader, Ext.data.DataReader, {
-    read: function (response) {
+
+    /**
+     * Method: read
+     * This method is only used by a DataProxy which has retrieved data from a
+     *     remote server.
+     *
+     * Parameters:
+     * request - {Object} The XHR object which contains the parsed XML
+     *     document.
+     * 
+     * Returns:
+     * {Object} A data block which is used by an {Ext.data.Store} as a cache
+     *     of Ext.data.Records.
+     */
+    read: function(request) {
+        var data = request.responseXML;
+        if(!data || !data.documentElement) {
+            data = request.responseText;
+        }
+        return this.readRecords(data);
+    },
+
+    /**
+     * Method: readRecords
+     * Create a data block containing Ext.data.Records from an XML document.
+     *
+     * Parameters:
+     * data - {DOMElement | Strint | Object} A document element or XHR response
+     *     string.  As an alternative to fetching capabilities data from a remote
+     *     source, an object representing the capabilities can be provided given
+     *     that the structure mirrors that returned from the capabilities parser.
+     *
+     * Returns:
+     * {Object} A data block which is used by an {Ext.data.Store} as a cache of
+     *     Ext.data.Records.
+     */
+    readRecords: function(data) {
         
-        var fmt = new OpenLayers.Format.WMSCapabilities();
-        var caps = fmt.read(response.responseXML);
-        var records = [];
-        
-        for (var i = 0; i < caps.capability.layers.length; i++){
-            var l = caps.capability.layers[i];
-            if (l.name){
-                records.push(new this.recordType(l));
+        if(typeof data === "string" || data.nodeType) {
+            data = this.meta.format.read(data).featureTypes[0].properties;
+        }
+        var url = data.capability.request.getmap.href;
+        var records = [], layer;        
+        for(var i=0, len=data.capability.layers.length; i<len i++){
+            layer = data.capability.layers[i];
+            if(layer.name) {
+                // this is specific to the LayerRecord
+                // TODO: make more generic when #27 is addressed
+                records.push(new this.recordType(
+                    new OpenLayers.Layer.WMS(
+                        layer.title || layer.name,
+                        url,
+                        {layers: layer.name}
+                        {isBaseLayer: false} // TODO: decide where to fix this
+                    ),
+                    layer // tack on remaining properties
+                ));
             }
         }
 
@@ -33,5 +105,6 @@
             success: true,
             records: records
         };
+
     }
 });



More information about the Commits mailing list