[Commits] r1279 - in sandbox/camptocamp/geobretagne: lib/GeoExt/data tests/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Mon Jul 20 10:34:59 CEST 2009


Author: fvanderbiest
Date: 2009-07-20 10:34:59 +0200 (Mon, 20 Jul 2009)
New Revision: 1279

Modified:
   sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js
Log:
added patch from ticket #118 so that our layerstore can take advantage of all the fields contained in the capabilities document when adding OGC layers

Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 07:43:02 UTC (rev 1278)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 08:34:59 UTC (rev 1279)
@@ -40,15 +40,25 @@
                 {name: "name", type: "string"},
                 {name: "abstract", type: "string"},
                 {name: "queryable", type: "boolean"},
-                {name: "formats"},
-                {name: "styles"},
-                {name: "llbbox"},
-                {name: "minScale"},
-                {name: "maxScale"},
-                {name: "prefix"},
-                {name: "attribution"},
-                {name: "keywords"},
-                {name: "metadataURLs"}
+                {name: "opaque", type: "boolean"},
+                {name: "noSubsets", type: "boolean"},
+                {name: "cascaded", type: "int"},
+                {name: "fixedWidth", type: "int"},
+                {name: "fixedHeight", type: "int"},
+                {name: "minScale", type: "float"},
+                {name: "maxScale", type: "float"},
+                {name: "prefix", type: "string"},
+                {name: "formats"}, // array
+                {name: "styles"}, // array
+                {name: "srs"}, // object
+                {name: "dimensions"}, // object
+                {name: "bbox"}, // object
+                {name: "llbbox"}, // array
+                {name: "attribution"}, // object
+                {name: "keywords"}, // array
+                {name: "identifiers"}, // object
+                {name: "authorityURLs"}, // object
+                {name: "metadataURLs"} // array
             ]
         );
     }
@@ -72,9 +82,48 @@
         }
         return this.readRecords(data);
     },
+    
+    /** private: method[serviceExceptionFormat]
+     *  :param formats: ``Array`` An array of service exception format strings.
+     *  :return: ``String`` The (supposedly) best service exception format.
+     */
+    serviceExceptionFormat: function(formats) {
+        if (OpenLayers.Util.indexOf(formats, 
+            "application/vnd.ogc.se_inimage")>-1) {
+            return "application/vnd.ogc.se_inimage";
+        }
+        if (OpenLayers.Util.indexOf(formats, 
+            "application/vnd.ogc.se_xml")>-1) {
+            return "application/vnd.ogc.se_xml";
+        }
+        return formats[0];
+    },
+    
+    /** private: method[imageFormat]
+     *  :param formats: ``Object`` The layer's capabilities object.
+     *  :return: ``String`` The (supposedly) best mime type for requesting 
+     *      tiles.
+     */
+    imageFormat: function(layer) {
+        var formats = layer.formats;
+        if (!layer.queryable && 
+            OpenLayers.Util.indexOf(formats, "image/jpeg")>-1) {
+            return "image/jpeg";
+        }
+        if (OpenLayers.Util.indexOf(formats, "image/png")>-1) {
+            return "image/png";
+        }
+        if (OpenLayers.Util.indexOf(formats, "image/png; mode=24bit")>-1) {
+            return "image/png; mode=24bit";
+        }
+        if (OpenLayers.Util.indexOf(formats, "image/gif")>-1) {
+            return "image/gif";
+        }
+        return formats[0];
+    },
 
     /** private: method[readRecords]
-     *  :param data: ``DOMElement | Strint | Object`` A document element or XHR
+     *  :param data: ``DOMElement | String | 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
@@ -85,20 +134,31 @@
      *  Create a data block containing Ext.data.Records from an XML document.
      */
     readRecords: function(data) {
-        
         if(typeof data === "string" || data.nodeType) {
             data = this.meta.format.read(data);
         }
-        var url = data.capability.request.getmap.href;
+        var capability = data.capability;
         var records = [], layer;        
-        for(var i=0, len=data.capability.layers.length; i<len; i++){
-            layer = data.capability.layers[i];
+        for(var i=0, len=capability.layers.length; i<len; i++){
+            layer = capability.layers[i];
             if(layer.name) {
                 records.push(new this.recordType(Ext.apply(layer, {
                     layer: new OpenLayers.Layer.WMS(
                         layer.title || layer.name,
-                        url,
-                        {layers: layer.name}
+                        capability.request.getmap.href,
+                        {
+                            layers: layer.name, 
+                            exceptions: this.serviceExceptionFormat(
+                                capability.exception.formats
+                            ),
+                            format: this.imageFormat(layer),
+                            version: data.version
+                        }, {
+                            minScale: (typeof(layer.minScale)!='undefined') ? 
+                                layer.minScale : null,
+                            maxScale: (typeof(layer.maxScale)!='undefined') ? 
+                                layer.maxScale : null
+                        }
                     )
                 })));
             }

Modified: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html	2009-07-20 07:43:02 UTC (rev 1278)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.html	2009-07-20 08:34:59 UTC (rev 1279)
@@ -17,7 +17,7 @@
             var fields = reader.recordType.prototype.fields;
 
             // 1 test
-            t.eq(fields.items.length, 14, 'number of default items is correct');
+            t.eq(fields.items.length, 24, 'number of default items is correct');
 
 
             var reader = new GeoExt.data.WMSCapabilitiesReader({},[
@@ -33,11 +33,11 @@
                  'field values set from configuration are correct');
         }
         function test_read(t) {
-            t.plan(13);
+            t.plan(29);
 
             var reader = new GeoExt.data.WMSCapabilitiesReader();
 
-            var records = reader.read({responseXML : doc});
+            var records = reader.read({responseXML: doc});
 
             //1 test
             t.eq(records.totalRecords, 22, 'readRecords returns correct number of records');
@@ -65,14 +65,34 @@
                 "[2] correct legend url"
             );
             t.eq(record.get("queryable"), true, "[2] correct queryable attribute");
+            t.eq(record.get("opaque"), true, "[2] correct opaque attribute");
+            t.eq(record.get("cascaded"), 3, "[2] correct cascaded attribute");
+            t.eq(record.get("noSubsets"), true, "[2] correct noSubsets attribute");
+            t.eq(record.get("fixedWidth"), 400, "[2] correct fixedWidth attribute");
+            t.eq(record.get("fixedHeight"), 200, "[2] correct fixedHeight attribute");
+            t.eq(record.get("formats")[0], "image/png", "[2] correct image/png formats attribute");
+            t.eq(record.get("formats")[14], "image/geotiff", "[2] correct image/geotiff formats attribute");
+            t.eq(record.get("formats")[27], "rss", "[2] correct rss formats attribute");
+            t.eq(record.get("srs")[0], "EPSG:WGS84(DD)", "[2] correct srs[0] attribute");
+            t.eq(record.get("srs")[record.get("srs").length-1], "EPSG:42303", "[2] correct srs[nb_srs-1] attribute");
+            t.eq(record.get("prefix"), "tiger", "[2] correct prefix attribute");
+            t.eq(
+                record.get("bbox")["EPSG:4326"].bbox,
+                [-74.02722,40.684221,-73.907005,40.878178],
+                "[2] correct bbox"
+            );
+            t.eq(record.get("authorityURLs").gcmd, "http://www.authority.com", "[2] correct authorityURLs attribute");
+            t.eq(record.get("identifiers").gcmd, "id_value", "[2] correct identifiers attribute");
+            // cannot test "dimensions" until we have nested layers: see http://trac.openlayers.org/ticket/2144
 
-            //4 tests -- Testing the layer field
+            //6 tests -- Testing the layer field
             var layer = record.get("layer");
             t.eq(layer.CLASS_NAME, "OpenLayers.Layer.WMS", "[2] layer field is of type OpenLayers.Layer.WMS");
             t.eq(layer.url, "http://publicus.opengeo.org:80/geoserver/wms?SERVICE=WMS&", "[2] layer field has correct URL");
             t.eq(layer.params.LAYERS, "tiger:tiger_roads","[2] layer field has correct LAYERS parameter");
             t.eq(layer.name, "Manhattan (NY) roads","[2] layer field has correct name");
-
+            t.eq(typeof(layer.minScale), "number","[2] layer minScale has been set");
+            t.eq(typeof(layer.maxScale), "number","[2] layer maxScale has been set");
         }
     </script>
   <body>

Modified: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 07:43:02 UTC (rev 1278)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 08:34:59 UTC (rev 1279)
@@ -4110,10 +4110,12 @@
               '</LegendURL>' +
             '</Style>' +
           '</Layer>' +
-          '<Layer queryable="1">' +
+          '<Layer queryable="1" opaque="1" cascaded="3" noSubsets="1" fixedWidth="400" fixedHeight="200">' +
             '<Name>tiger:tiger_roads</Name>' +
             '<Title>Manhattan (NY) roads</Title>' +
             '<Abstract>Highly simplified road layout of Manhattan in New York..</Abstract>' +
+            '<AuthorityURL name="gcmd"><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.authority.com" /></AuthorityURL>' +
+            '<Identifier authority="gcmd">id_value</Identifier>' +
             '<KeywordList>' +
               '<Keyword>DS_tiger_roads</Keyword>' +
               '<Keyword>tiger_roads</Keyword>' +
@@ -4141,6 +4143,7 @@
                 '<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://publicus.opengeo.org:80/geoserver/wms/GetLegendGraphic?VERSION=1.0.0&amp;FORMAT=image/png&amp;WIDTH=20&amp;HEIGHT=20&amp;LAYER=tiger:tiger_roads"/>' +
               '</LegendURL>' +
             '</Style>' +
+            '<ScaleHint min="37.4177136322228" max="299.341709057782" />' +
           '</Layer>' +
           '<Layer queryable="1">' +
             '<Name>sf:archsites</Name>' +



More information about the Commits mailing list