From f662d496825784d8f7e287d7aa51ec54df216469 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 12 Sep 2007 02:18:33 +0000 Subject: [PATCH] Add useFeedTitle option to georss layer -- defaults to true -- to determine whether to use the remote title or the local name. (Closes #731) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4226 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/GeoRSS.js | 23 +++++++++++++++++------ tests/Layer/test_GeoRSS.html | 9 +++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) 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 );