OpenLayers OpenLayers

Ticket #731: georss.patch

File georss.patch, 2.2 kB (added by crschmidt, 1 year ago)

add option for not parsing layer name from feed title

  • tests/Layer/test_GeoRSS.html

    old new  
    2828            t.eq( layer.name, "Crschmidt's Places At Platial", "Layer name is correct." ); 
    2929        } ); 
    3030    } 
     31     
     32    function test_Layer_GeoRSS_dontUseFeedTitle (t) { 
     33        t.plan( 1 ); 
     34        layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt, {'useFeedTitle': false} ); 
     35        t.delay_call( 1, function() {   
     36            t.eq( layer.name, "Test Layer", "Layer name is correct when not used from feed." ); 
     37        } ); 
     38    } 
     39     
    3140    function test_01_Layer_GeoRSS_AtomParsing (t) { 
    3241        t.plan( 6 ); 
    3342        layer = new OpenLayers.Layer.GeoRSS('Test Layer', atom_xml ); 
  • lib/OpenLayers/Layer/GeoRSS.js

    old new  
    4242     */ 
    4343    icon: null, 
    4444     
     45    /**  
     46     * APIProperty: useFeedTitle  
     47     * {Boolean} Set layer.name to the first <title> element in the feed. Default is true.  
     48     */ 
     49    useFeedTitle: true, 
     50     
    4551    /** 
    4652    * Constructor: OpenLayers.Layer.GeoRSS 
    4753    * Create a GeoRSS Layer. 
     
    8086            doc = OpenLayers.parseXMLString(ajaxRequest.responseText); 
    8187        } 
    8288         
    83         this.name = null; 
    84         try { 
    85             this.name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue; 
     89        if (this.useFeedTitle) { 
     90            var name = null; 
     91            try { 
     92                name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue; 
     93            } 
     94            catch (e) { 
     95                name = doc.getElementsByTagName('title')[0].firstChild.nodeValue; 
     96            } 
     97            if (name) { 
     98                this.setName(name); 
     99            }     
    86100        } 
    87         catch (e) { 
    88             this.name = doc.getElementsByTagName('title')[0].firstChild.nodeValue; 
    89         } 
    90101        
    91102        /* Try RSS items first, then Atom entries */ 
    92103        var itemlist = null;