diff --git a/lib/OpenLayers/Layer/GeoRSS.js b/lib/OpenLayers/Layer/GeoRSS.js index 5c2c010b34..c87735b93d 100644 --- a/lib/OpenLayers/Layer/GeoRSS.js +++ b/lib/OpenLayers/Layer/GeoRSS.js @@ -48,6 +48,12 @@ OpenLayers.Layer.GeoRSS = OpenLayers.Class(OpenLayers.Layer.Markers, { */ popupSize: null, + /** + * APIProperty: useFeedTitle + * {Boolean} Set layer.name to the first element in the feed. Default is true. + */ + useFeedTitle: true, + /** * Constructor: OpenLayers.Layer.GeoRSS * Create a GeoRSS Layer. @@ -86,12 +92,17 @@ OpenLayers.Layer.GeoRSS = OpenLayers.Class(OpenLayers.Layer.Markers, { doc = OpenLayers.parseXMLString(ajaxRequest.responseText); } - this.name = null; - try { - this.name = doc.getElementsByTagNameNS('*', 'title')[0].firstChild.nodeValue; - } - catch (e) { - this.name = doc.getElementsByTagName('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); + } } /* Try RSS items first, then Atom entries */ diff --git a/tests/Layer/test_GeoRSS.html b/tests/Layer/test_GeoRSS.html index e1b32f0c72..be2878e86b 100644 --- a/tests/Layer/test_GeoRSS.html +++ b/tests/Layer/test_GeoRSS.html @@ -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 );