OpenLayers OpenLayers

Ticket #1025: layer.georss.patch

File layer.georss.patch, 4.8 kB (added by crschmidt, 1 year ago)
  • lib/OpenLayers/Layer/GeoRSS.js

    old new  
    106106            }     
    107107        } 
    108108        
    109         /* Try RSS items first, then Atom entries */ 
    110         var itemlist = null; 
    111         try { 
    112             itemlist = doc.getElementsByTagNameNS('*', 'item'); 
    113         } 
    114         catch (e) { 
    115             itemlist = doc.getElementsByTagName('item'); 
    116         } 
    117  
    118         if (itemlist.length == 0) { 
    119             try { 
    120                 itemlist = doc.getElementsByTagNameNS('*', 'entry'); 
    121             } 
    122             catch(e) { 
    123                 itemlist = doc.getElementsByTagName('entry'); 
    124             } 
    125         } 
    126  
    127         for (var i = 0; i < itemlist.length; i++) { 
     109        var format = new OpenLayers.Format.GeoRSS(); 
     110        var features = format.read(doc); 
     111         
     112        for (var i = 0; i < features.length; i++) { 
    128113            var data = {}; 
    129             var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point'); 
    130             var lat = OpenLayers.Util.getNodes(itemlist[i], 'geo:lat'); 
    131             var lon = OpenLayers.Util.getNodes(itemlist[i], 'geo:long'); 
    132             if (point.length > 0) { 
    133                 var location = point[0].firstChild.nodeValue.split(" "); 
    134                  
    135                 if (location.length !=2) { 
    136                     var location = point[0].firstChild.nodeValue.split(","); 
    137                 } 
    138             } else if (lat.length > 0 && lon.length > 0) { 
    139                 var location = [parseFloat(lat[0].firstChild.nodeValue), parseFloat(lon[0].firstChild.nodeValue)]; 
    140             } else { 
    141                 continue; 
    142             } 
    143             location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0])); 
     114            var feature = features[i]; 
     115            var title = feature.attributes.title ?  
     116                         feature.attributes.title : "Untitled"; 
    144117             
    145             /* Provide defaults for title and description */ 
    146             var title = "Untitled"; 
    147             try { 
    148               title = OpenLayers.Util.getNodes(itemlist[i],  
    149                         "title")[0].firstChild.nodeValue; 
    150             } 
    151             catch (e) { title="Untitled"; } 
    152             
    153             /* First try RSS descriptions, then Atom summaries */ 
    154             var descr_nodes = null; 
    155             try { 
    156                 descr_nodes = itemlist[i].getElementsByTagNameNS("*", 
    157                                                 "description"); 
    158             } 
    159             catch (e) { 
    160                 descr_nodes = itemlist[i].getElementsByTagName("description"); 
    161             } 
    162             if (descr_nodes.length == 0) { 
    163                 try { 
    164                     descr_nodes = itemlist[i].getElementsByTagNameNS("*", 
    165                                                 "summary"); 
    166                 } 
    167                 catch (e) { 
    168                     descr_nodes = itemlist[i].getElementsByTagName("summary"); 
    169                 } 
    170             } 
     118            var description = feature.attributes.description ?  
     119                         feature.attributes.description : "No description."; 
     120             
     121            var link = feature.attributes.link ? feature.attributes.link : ""; 
    171122 
    172             var description = "No description."; 
    173             try { 
    174               description = descr_nodes[0].firstChild.nodeValue; 
    175             } 
    176             catch (e) { description="No description."; } 
    177  
    178             /* If no link URL is found in the first child node, try the 
    179                href attribute */ 
    180             try { 
    181               var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].firstChild.nodeValue; 
    182             }  
    183             catch (e) { 
    184               try { 
    185                 var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].getAttribute("href"); 
    186               } 
    187               catch (e) {} 
    188             } 
    189  
     123            var location = feature.geometry.getBounds().getCenterLonLat(); 
     124             
     125             
    190126            data.icon = this.icon == null ?  
    191127                                     OpenLayers.Marker.defaultIcon() :  
    192128                                     this.icon.clone(); 
    193129             
    194             data.popupSize = this.popupSize ? this.popupSize.clone() : new OpenLayers.Size(250, 120); 
    195             if ((title != null) && (description != null)) { 
     130            data.popupSize = this.popupSize ?  
     131                             this.popupSize.clone() : 
     132                             new OpenLayers.Size(250, 120); 
     133             
     134            if (title || description) { 
    196135                contentHTML = '<div class="olLayerGeoRSSClose">[x]</div>';  
    197136                contentHTML += '<div class="olLayerGeoRSSTitle">'; 
    198137                if (link) contentHTML += '<a class="link" href="'+link+'" target="_blank">';