Ticket #157: geoext-157.patch

File geoext-157.patch, 7.7 kB (added by ahocevar, 1 year ago)

applies to current trunk, includes patch for #162

  • tests/lib/GeoExt/data/WMSCapabilitiesReader.html

    old new  
    1919            // 1 test 
    2020            t.eq(fields.items.length, 24, 'number of default items is correct'); 
    2121 
    22  
    2322            var reader = new GeoExt.data.WMSCapabilitiesReader({},[ 
    2423                {name: "foo"}, 
    2524                {name: "bar"} 
     
    3332                 'field values set from configuration are correct'); 
    3433        } 
    3534        function test_read(t) { 
    36             t.plan(36); 
     35            t.plan(37); 
     36             
     37            // test a reader with the only two default LayerRecord fields 
     38            var reader = new GeoExt.data.WMSCapabilitiesReader({}, []); 
    3739 
     40            var records = reader.read({responseXML: doc}); 
     41 
     42            //1 test 
     43            t.eq(records.records[0].fields.items.length, 2, 'LayerRecord with 2 default fields'); 
     44             
     45            var record = records.records[2];  
     46            //2 tests -- testing the fields of a record  
     47            t.eq(record.get("title"), "tiger:tiger_roads", "correct layer title");  
     48            t.eq(record.get("abstract"), undefined, "correct undefined abstract which is not part of fields");  
     49 
     50            // test a reader with all default fields  
     51  
    3852            var reader = new GeoExt.data.WMSCapabilitiesReader({ 
    3953                layerOptions: { 
    4054                    singleTile: true 
    4155                } 
    42             }); 
    43  
    44             var records = reader.read({responseXML: doc}); 
    45  
    46             //1 test 
    47             t.eq(records.totalRecords, 22, 'readRecords returns correct number of records'); 
    48              
     56            });  
     57            var records = reader.read({responseXML : doc});  
     58  
    4959            var record, layer; 
    5060 
    51             //1 test -- testing value of record id 
    52             record = records.records[2]; 
    53             t.ok(record.id == record.get("layer").id, "[2] correct record id"); 
    54  
    5561            //22 tests -- testing the fields of a record 
    5662            record = records.records[2]; 
    5763            t.eq(record.get("name"), "tiger:tiger_roads", "[2] correct layer name"); 
  • lib/GeoExt/data/WMSCapabilitiesReader.js

    old new  
    2525 *          to the ``OpenLayers.Layer.WMS`` constructor. 
    2626 *      :param recordType: ``Array | Ext.data.Record`` An array of field 
    2727 *          configuration objects or a record object.  Default is 
    28  *          :class:`GeoExt.data.LayerRecord` with the following additional 
    29  *          fields: name (string), abstract (string), queryable (string), 
    30  *          formats, styles, llbbox, minScale, maxScale, prefix, attribution, 
    31  *          keywords, metadataURLs. The type of these fields is the same as 
    32  *          for the matching fields in the object returned from 
     28 *          :class:`GeoExt.data.LayerRecord` with the following fields: 
     29 *          name, title, abstract, queryable, opaque, noSubsets, cascaded, 
     30 *          fixedWidth, fixedHeight, minScale, maxScale, prefix, formats, 
     31 *          styles, srs, dimensions, bbox, llbbox, attribution, keywords, 
     32 *          identifiers, authorityURLs, metadataURLs. 
     33 *          The type of these fields is the same as for the matching fields in 
     34 *          the object returned from 
    3335 *          ``OpenLayers.Format.WMSCapabilities::read()``. 
    3436 *    
    3537 *      Data reader class to create an array of 
     
    4143    if(!meta.format) { 
    4244        meta.format = new OpenLayers.Format.WMSCapabilities(); 
    4345    } 
    44     if(!(typeof recordType === "function")) { 
     46    if(typeof recordType !== "function") { 
    4547        recordType = GeoExt.data.LayerRecord.create( 
    4648            recordType || meta.fields || [ 
    4749                {name: "name", type: "string"}, 
     50                {name: "title", type: "string"}, 
    4851                {name: "abstract", type: "string"}, 
    4952                {name: "queryable", type: "boolean"}, 
    5053                {name: "opaque", type: "boolean"}, 
     
    161164            data = this.meta.format.read(data); 
    162165        } 
    163166        var version = data.version; 
    164         var capability = data.capability
    165         var url = capability.request.getmap.href; 
    166         var layers = capability.layers; 
    167         var exceptions = this.serviceExceptionFormat( 
    168             capability.exception.formats 
    169         ); 
    170         var records = [], layer
     167        var capability = data.capability || {}
     168        var url = capability.request && capability.request.getmap && 
     169            capability.request.getmap.href;  
     170        var layers = capability.layers;  
     171        var formats = capability.exception ? capability.exception.formats : []; 
     172        var exceptions = this.serviceExceptionFormat(formats); 
     173        var records = []
    171174         
    172         for(var i=0, len=capability.layers.length; i<len; i++){ 
    173             layer = layers[i]; 
    174             if(layer.name) { 
    175                 var options = { 
    176                     attribution: layer.attribution ? 
    177                         this.attributionMarkup(layer.attribution) : 
    178                         undefined, 
    179                     minScale: layer.minScale, 
    180                     maxScale: layer.maxScale 
    181                 }; 
    182                 if(this.meta.layerOptions) { 
    183                     Ext.apply(options, this.meta.layerOptions); 
     175        if(url && layers) { 
     176            var recordType = this.recordType, fields = recordType.prototype.fields;  
     177            var layer, values, options, field, v; 
     178 
     179            for(var i=0, lenI=layers.length; i<lenI; i++){ 
     180                layer = layers[i]; 
     181                if(layer.name) { 
     182                    values = {}; 
     183                    for(var j=0, lenJ=fields.length; j<lenJ; j++) { 
     184                        field = fields.items[j]; 
     185                        v = layer[field.mapping || field.name] || 
     186                        field.defaultValue; 
     187                        v = field.convert(v); 
     188                        values[field.name] = v; 
     189                    } 
     190                    options = { 
     191                        attribution: layer.attribution ? 
     192                            this.attributionMarkup(layer.attribution) : 
     193                            undefined, 
     194                        minScale: layer.minScale, 
     195                        maxScale: layer.maxScale 
     196                    }; 
     197                    if(this.meta.layerOptions) { 
     198                        Ext.apply(options, this.meta.layerOptions); 
     199                    } 
     200                    values.layer = new OpenLayers.Layer.WMS( 
     201                        layer.title || layer.name, url, { 
     202                            layers: layer.name, 
     203                            exceptions: exceptions, 
     204                            format: this.imageFormat(layer), 
     205                            transparent: this.imageTransparent(layer), 
     206                            version: version 
     207                        }, options 
     208                    ); 
     209                    records.push(new this.recordType(values)); 
    184210                } 
    185                 var l = new OpenLayers.Layer.WMS( 
    186                     layer.title || layer.name, 
    187                     url, 
    188                     { 
    189                         layers: layer.name,  
    190                         exceptions: exceptions, 
    191                         format: this.imageFormat(layer), 
    192                         transparent: this.imageTransparent(layer), 
    193                         version: version 
    194                     },  
    195                     options 
    196                 ); 
    197                 records.push(new this.recordType(Ext.apply(layer, { 
    198                     layer: l 
    199                 }), l.id)); 
    200211            } 
    201212        } 
    202213