[OpenLayers-Commits] r4226 - in trunk/openlayers: lib/OpenLayers/Layer tests/Layer

commits at openlayers.org commits at openlayers.org
Tue Sep 11 22:18:34 EDT 2007


Author: crschmidt
Date: 2007-09-11 22:18:33 -0400 (Tue, 11 Sep 2007)
New Revision: 4226

Modified:
   trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js
   trunk/openlayers/tests/Layer/test_GeoRSS.html
Log:
Add useFeedTitle option to georss layer -- defaults to true -- to determine
whether to use the remote title or the local name. (Closes #731)


Modified: trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js	2007-09-12 01:58:27 UTC (rev 4225)
+++ trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js	2007-09-12 02:18:33 UTC (rev 4226)
@@ -48,6 +48,12 @@
      */
     popupSize: null, 
     
+    /** 
+     * APIProperty: useFeedTitle 
+     * {Boolean} Set layer.name to the first <title> element in the feed. Default is true. 
+     */
+    useFeedTitle: true,
+    
     /**
     * Constructor: OpenLayers.Layer.GeoRSS
     * Create a GeoRSS Layer.
@@ -86,13 +92,18 @@
             doc = OpenLayers.parseXMLString(ajaxRequest.responseText);
         }
         
-        this.name = null;
-        try {
-            this.name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue;
+        if (this.useFeedTitle) {
+            var name = null;
+            try {
+                name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue;
+            }
+            catch (e) {
+                name = doc.getElementsByTagName('title')[0].firstChild.nodeValue;
+            }
+            if (name) {
+                this.setName(name);
+            }    
         }
-        catch (e) {
-            this.name = doc.getElementsByTagName('title')[0].firstChild.nodeValue;
-        }
        
         /* Try RSS items first, then Atom entries */
         var itemlist = null;

Modified: trunk/openlayers/tests/Layer/test_GeoRSS.html
===================================================================
--- trunk/openlayers/tests/Layer/test_GeoRSS.html	2007-09-12 01:58:27 UTC (rev 4225)
+++ trunk/openlayers/tests/Layer/test_GeoRSS.html	2007-09-12 02:18:33 UTC (rev 4226)
@@ -28,6 +28,15 @@
             t.eq( layer.name, "Crschmidt's Places At Platial", "Layer name is correct." );
         } );
     }
+    
+    function test_Layer_GeoRSS_dontUseFeedTitle (t) {
+        t.plan( 1 );
+        layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt, {'useFeedTitle': false} );
+        t.delay_call( 1, function() {  
+            t.eq( layer.name, "Test Layer", "Layer name is correct when not used from feed." );
+        } );
+    }
+    
     function test_01_Layer_GeoRSS_AtomParsing (t) {
         t.plan( 6 );
         layer = new OpenLayers.Layer.GeoRSS('Test Layer', atom_xml );



More information about the Commits mailing list