Ticket #157: geoext-157.patch
| File geoext-157.patch, 7.7 kB (added by ahocevar, 1 year ago) |
|---|
-
tests/lib/GeoExt/data/WMSCapabilitiesReader.html
old new 19 19 // 1 test 20 20 t.eq(fields.items.length, 24, 'number of default items is correct'); 21 21 22 23 22 var reader = new GeoExt.data.WMSCapabilitiesReader({},[ 24 23 {name: "foo"}, 25 24 {name: "bar"} … … 33 32 'field values set from configuration are correct'); 34 33 } 35 34 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({}, []); 37 39 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 38 52 var reader = new GeoExt.data.WMSCapabilitiesReader({ 39 53 layerOptions: { 40 54 singleTile: true 41 55 } 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 49 59 var record, layer; 50 60 51 //1 test -- testing value of record id52 record = records.records[2];53 t.ok(record.id == record.get("layer").id, "[2] correct record id");54 55 61 //22 tests -- testing the fields of a record 56 62 record = records.records[2]; 57 63 t.eq(record.get("name"), "tiger:tiger_roads", "[2] correct layer name"); -
lib/GeoExt/data/WMSCapabilitiesReader.js
old new 25 25 * to the ``OpenLayers.Layer.WMS`` constructor. 26 26 * :param recordType: ``Array | Ext.data.Record`` An array of field 27 27 * 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 33 35 * ``OpenLayers.Format.WMSCapabilities::read()``. 34 36 * 35 37 * Data reader class to create an array of … … 41 43 if(!meta.format) { 42 44 meta.format = new OpenLayers.Format.WMSCapabilities(); 43 45 } 44 if( !(typeof recordType === "function")) {46 if(typeof recordType !== "function") { 45 47 recordType = GeoExt.data.LayerRecord.create( 46 48 recordType || meta.fields || [ 47 49 {name: "name", type: "string"}, 50 {name: "title", type: "string"}, 48 51 {name: "abstract", type: "string"}, 49 52 {name: "queryable", type: "boolean"}, 50 53 {name: "opaque", type: "boolean"}, … … 161 164 data = this.meta.format.read(data); 162 165 } 163 166 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.formats169 );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 = []; 171 174 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)); 184 210 } 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: version194 },195 options196 );197 records.push(new this.recordType(Ext.apply(layer, {198 layer: l199 }), l.id));200 211 } 201 212 } 202 213