Use Format.GeoRSS to do the work in Layer.GeoRSS. (Closes #1025)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5400 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-12-13 23:23:02 +00:00
parent 5824170f10
commit c3c2895e8c

View File

@@ -106,93 +106,32 @@ OpenLayers.Layer.GeoRSS = OpenLayers.Class(OpenLayers.Layer.Markers, {
}
}
/* Try RSS items first, then Atom entries */
var itemlist = null;
try {
itemlist = doc.getElementsByTagNameNS('*', 'item');
}
catch (e) {
itemlist = doc.getElementsByTagName('item');
}
if (itemlist.length == 0) {
try {
itemlist = doc.getElementsByTagNameNS('*', 'entry');
}
catch(e) {
itemlist = doc.getElementsByTagName('entry');
}
}
for (var i = 0; i < itemlist.length; i++) {
var format = new OpenLayers.Format.GeoRSS();
var features = format.read(doc);
for (var i = 0; i < features.length; i++) {
var data = {};
var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point');
var lat = OpenLayers.Util.getNodes(itemlist[i], 'geo:lat');
var lon = OpenLayers.Util.getNodes(itemlist[i], 'geo:long');
if (point.length > 0) {
var location = point[0].firstChild.nodeValue.split(" ");
if (location.length !=2) {
var location = point[0].firstChild.nodeValue.split(",");
}
} else if (lat.length > 0 && lon.length > 0) {
var location = [parseFloat(lat[0].firstChild.nodeValue), parseFloat(lon[0].firstChild.nodeValue)];
} else {
continue;
}
location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0]));
var feature = features[i];
var title = feature.attributes.title ?
feature.attributes.title : "Untitled";
/* Provide defaults for title and description */
var title = "Untitled";
try {
title = OpenLayers.Util.getNodes(itemlist[i],
"title")[0].firstChild.nodeValue;
}
catch (e) { title="Untitled"; }
/* First try RSS descriptions, then Atom summaries */
var descr_nodes = null;
try {
descr_nodes = itemlist[i].getElementsByTagNameNS("*",
"description");
}
catch (e) {
descr_nodes = itemlist[i].getElementsByTagName("description");
}
if (descr_nodes.length == 0) {
try {
descr_nodes = itemlist[i].getElementsByTagNameNS("*",
"summary");
}
catch (e) {
descr_nodes = itemlist[i].getElementsByTagName("summary");
}
}
var description = "No description.";
try {
description = descr_nodes[0].firstChild.nodeValue;
}
catch (e) { description="No description."; }
/* If no link URL is found in the first child node, try the
href attribute */
try {
var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].firstChild.nodeValue;
}
catch (e) {
try {
var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].getAttribute("href");
}
catch (e) {}
}
var description = feature.attributes.description ?
feature.attributes.description : "No description.";
var link = feature.attributes.link ? feature.attributes.link : "";
var location = feature.geometry.getBounds().getCenterLonLat();
data.icon = this.icon == null ?
OpenLayers.Marker.defaultIcon() :
this.icon.clone();
data.popupSize = this.popupSize ? this.popupSize.clone() : new OpenLayers.Size(250, 120);
if ((title != null) && (description != null)) {
data.popupSize = this.popupSize ?
this.popupSize.clone() :
new OpenLayers.Size(250, 120);
if (title || description) {
var contentHTML = '<div class="olLayerGeoRSSClose">[x]</div>';
contentHTML += '<div class="olLayerGeoRSSTitle">';
if (link) {