[Commits] r1412 - in core/trunk/geoext: lib/GeoExt/data tests/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Mon Oct 12 10:05:25 CEST 2009


Author: bbinet
Date: 2009-10-12 10:05:25 +0200 (Mon, 12 Oct 2009)
New Revision: 1412

Modified:
   core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js
   core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
Log:
WMSCapabilitiesReader does not take into account its fields configuration. r=ahocevar,tschaub (closes #157)

Modified: core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-10-12 07:08:53 UTC (rev 1411)
+++ core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-10-12 08:05:25 UTC (rev 1412)
@@ -25,11 +25,13 @@
  *          to the ``OpenLayers.Layer.WMS`` constructor.
  *      :param recordType: ``Array | Ext.data.Record`` An array of field
  *          configuration objects or a record object.  Default is
- *          :class:`GeoExt.data.LayerRecord` with the following additional
- *          fields: name (string), abstract (string), queryable (string),
- *          formats, styles, llbbox, minScale, maxScale, prefix, attribution,
- *          keywords, metadataURLs. The type of these fields is the same as
- *          for the matching fields in the object returned from
+ *          :class:`GeoExt.data.LayerRecord` with the following fields:
+ *          name, title, abstract, queryable, opaque, noSubsets, cascaded,
+ *          fixedWidth, fixedHeight, minScale, maxScale, prefix, formats,
+ *          styles, srs, dimensions, bbox, llbbox, attribution, keywords,
+ *          identifiers, authorityURLs, metadataURLs.
+ *          The type of these fields is the same as for the matching fields in
+ *          the object returned from
  *          ``OpenLayers.Format.WMSCapabilities::read()``.
  *   
  *      Data reader class to create an array of
@@ -41,10 +43,11 @@
     if(!meta.format) {
         meta.format = new OpenLayers.Format.WMSCapabilities();
     }
-    if(!(typeof recordType === "function")) {
+    if(typeof recordType !== "function") {
         recordType = GeoExt.data.LayerRecord.create(
             recordType || meta.fields || [
                 {name: "name", type: "string"},
+                {name: "title", type: "string"},
                 {name: "abstract", type: "string"},
                 {name: "queryable", type: "boolean"},
                 {name: "opaque", type: "boolean"},
@@ -161,41 +164,50 @@
             data = this.meta.format.read(data);
         }
         var version = data.version;
-        var capability = data.capability;
-        var url = capability.request.getmap.href;
-        var layers = capability.layers;
+        var capability = data.capability || {};
+        var url = capability.request && capability.request.getmap &&
+            capability.request.getmap.href; 
+        var layers = capability.layers; 
         var formats = capability.exception ? capability.exception.formats : [];
         var exceptions = this.serviceExceptionFormat(formats);
-        var records = [], layer;
+        var records = [];
         
-        for(var i=0, len=capability.layers.length; i<len; i++){
-            layer = layers[i];
-            if(layer.name) {
-                var options = {
-                    attribution: layer.attribution ?
-                        this.attributionMarkup(layer.attribution) :
-                        undefined,
-                    minScale: layer.minScale,
-                    maxScale: layer.maxScale
-                };
-                if(this.meta.layerOptions) {
-                    Ext.apply(options, this.meta.layerOptions);
+        if(url && layers) {
+            var fields = this.recordType.prototype.fields; 
+            var layer, values, options, field, v;
+
+            for(var i=0, lenI=layers.length; i<lenI; i++){
+                layer = layers[i];
+                if(layer.name) {
+                    values = {};
+                    for(var j=0, lenJ=fields.length; j<lenJ; j++) {
+                        field = fields.items[j];
+                        v = layer[field.mapping || field.name] ||
+                        field.defaultValue;
+                        v = field.convert(v);
+                        values[field.name] = v;
+                    }
+                    options = {
+                        attribution: layer.attribution ?
+                            this.attributionMarkup(layer.attribution) :
+                            undefined,
+                        minScale: layer.minScale,
+                        maxScale: layer.maxScale
+                    };
+                    if(this.meta.layerOptions) {
+                        Ext.apply(options, this.meta.layerOptions);
+                    }
+                    values.layer = new OpenLayers.Layer.WMS(
+                        layer.title || layer.name, url, {
+                            layers: layer.name,
+                            exceptions: exceptions,
+                            format: this.imageFormat(layer),
+                            transparent: this.imageTransparent(layer),
+                            version: version
+                        }, options
+                    );
+                    records.push(new this.recordType(values, values.layer.id));
                 }
-                var l = new OpenLayers.Layer.WMS(
-                    layer.title || layer.name,
-                    url,
-                    {
-                        layers: layer.name, 
-                        exceptions: exceptions,
-                        format: this.imageFormat(layer),
-                        transparent: this.imageTransparent(layer),
-                        version: version
-                    }, 
-                    options
-                );
-                records.push(new this.recordType(Ext.apply(layer, {
-                    layer: l
-                }), l.id));
             }
         }
         

Modified: core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html	2009-10-12 07:08:53 UTC (rev 1411)
+++ core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html	2009-10-12 08:05:25 UTC (rev 1412)
@@ -19,7 +19,6 @@
             // 1 test
             t.eq(fields.items.length, 24, 'number of default items is correct');
 
-
             var reader = new GeoExt.data.WMSCapabilitiesReader({},[
                 {name: "foo"},
                 {name: "bar"}
@@ -33,19 +32,33 @@
                  'field values set from configuration are correct');
         }
         function test_read(t) {
-            t.plan(36);
+            t.plan(39);
 
+            // test a reader with the only two default LayerRecord fields
+            var reader = new GeoExt.data.WMSCapabilitiesReader({}, []);
+
+            var records = reader.read({responseXML: doc});
+
+            //1 test
+            t.eq(records.records[0].fields.items.length, 2, 'LayerRecord with 2 default fields');
+
+            var record = records.records[2];
+            //2 tests -- testing the fields of a record
+            t.eq(record.get("title"), "tiger:tiger_roads", "correct layer title");
+            t.eq(record.get("abstract"), undefined, "correct undefined abstract which is not part of fields");
+
+            // test a reader with all default fields
+
             var reader = new GeoExt.data.WMSCapabilitiesReader({
                 layerOptions: {
                     singleTile: true
                 }
             });
-
             var records = reader.read({responseXML: doc});
 
             //1 test
             t.eq(records.totalRecords, 22, 'readRecords returns correct number of records');
-            
+
             var record, layer;
 
             //1 test -- testing value of record id



More information about the Commits mailing list