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

commits at geoext.org commits at geoext.org
Mon Jul 20 22:37:06 CEST 2009


Author: sbenthall
Date: 2009-07-20 22:37:06 +0200 (Mon, 20 Jul 2009)
New Revision: 1280

Modified:
   core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js
   core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
   core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.js
Log:
WMSCapabilitiesReader now adds markup with Attribution metadata to layers' attribution property. r=ahocevar (Closes #118)


Modified: core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 08:34:59 UTC (rev 1279)
+++ core/trunk/geoext/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 20:37:06 UTC (rev 1280)
@@ -59,6 +59,14 @@
 
 Ext.extend(GeoExt.data.WMSCapabilitiesReader, Ext.data.DataReader, {
 
+
+    /** api: config[attributionCls]
+     *  ``String`` CSS class name for the attribution DOM elements.
+     *  Element class names append "-link", "-image", and "-title" as
+     *  appropriate.  Default is "gx-attribution".
+     */
+    attributionCls: "gx-attribution",
+
     /** private: method[read]
      *  :param request: ``Object`` The XHR object which contains the parsed XML
      *      document.
@@ -91,24 +99,68 @@
         }
         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) {
                 records.push(new this.recordType(Ext.apply(layer, {
                     layer: new OpenLayers.Layer.WMS(
                         layer.title || layer.name,
                         url,
-                        {layers: layer.name}
+                        {layers: layer.name}, {
+                            attribution: layer.attribution ?
+                                this.attributionMarkup(layer.attribution) :
+                                undefined
+                        }
                     )
                 })));
             }
         }
-
+        
         return {
             totalRecords: records.length,
             success: true,
             records: records
         };
 
+    },
+
+    /** private: method[attributionMarkup]
+     *  :param attribution: ``Object`` The attribution property of the layer
+     *      object as parsed from a WMS Capabilities document
+     *  :return: ``String`` HTML markup to display attribution
+     *      information.
+     *  
+     *  Generates attribution markup using the Attribution metadata
+     *      from WMS Capabilities
+     */
+    attributionMarkup : function(attribution){
+        var markup = [];
+        
+        if (attribution.logo){
+            markup.push("<img class='"+this.attributionCls+"-image' "
+                        + "src='" + attribution.logo.href + "' />");
+        }
+        
+        if (attribution.title) {
+            markup.push("<span class='"+ this.attributionCls + "-title'>"
+                        + attribution.title
+                        + "</span>");
+        }
+        
+        if(attribution.href){
+            for(var i = 0; i < markup.length; i++){
+                markup[i] = "<a class='"
+              + this.attributionCls + "-link' "
+                    + "href="
+                    + attribution.href
+                    + ">"
+                    + markup[i]
+                    + "</a>";
+            }
+        }
+
+        return markup.join(" ");
     }
 });

Modified: core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html	2009-07-20 08:34:59 UTC (rev 1279)
+++ core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.html	2009-07-20 20:37:06 UTC (rev 1280)
@@ -33,7 +33,7 @@
                  'field values set from configuration are correct');
         }
         function test_read(t) {
-            t.plan(13);
+            t.plan(16);
 
             var reader = new GeoExt.data.WMSCapabilitiesReader();
 
@@ -72,6 +72,12 @@
             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");
+            
+            // 3 tests -- attribution markup
+            var attribution = layer.attribution;
+            t.ok(attribution.indexOf("http://foo/logo.png") !== -1, "attribution markup has a logo");
+            t.ok(attribution.indexOf("Foo Authority") !== -1, "attribution markup has a title");
+            t.ok(attribution.indexOf("http://foo/about/") !== -1, "attribution has a link");
 
         }
     </script>

Modified: core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.js
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 08:34:59 UTC (rev 1279)
+++ core/trunk/geoext/tests/lib/GeoExt/data/WMSCapabilitiesReader.js	2009-07-20 20:37:06 UTC (rev 1280)
@@ -4132,6 +4132,14 @@
       'AUTHORITY["EPSG","4326"]]-->' +
             '<LatLonBoundingBox minx="-74.08769307536667" miny="40.660618924633326" maxx="-73.84653192463333" maxy="40.90178007536667"/>' +
             '<BoundingBox SRS="EPSG:4326" minx="-74.02722" miny="40.684221" maxx="-73.907005" maxy="40.878178"/>' +
+            '<Attribution>' +
+              '<Title>Foo Authority</Title>' +
+              '<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/about/" />' +
+              '<LogoURL width="24" height="24">' +
+                '<Format>image/png</Format>' +
+                '<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://foo/logo.png" />' +
+              '</LogoURL>' +
+            '</Attribution>' +
             '<Style>' +
               '<Name>tiger_roads</Name>' +
               '<Title>Default Styler</Title>' +



More information about the Commits mailing list