Refactor GeoRSS Layer to support 'real' GeoRSS :) (geo:lat, geo:lon).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@783 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -14,13 +14,14 @@
|
|||||||
var map, layer;
|
var map, layer;
|
||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
|
OpenLayers.ProxyHost = '/proxy/';
|
||||||
map = new OpenLayers.Map('map', {maxResolution:'auto'});
|
map = new OpenLayers.Map('map', {maxResolution:'auto'});
|
||||||
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||||
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
||||||
|
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
|
|
||||||
var newl = new OpenLayers.Layer.GeoRSS( "text", "./georss.xml" );
|
var newl = new OpenLayers.Layer.GeoRSS( "text", "http://earthquake.usgs.gov/eqcenter/recenteqsww/catalogs/eqs7day-M2.5.xml" );
|
||||||
map.addLayer(newl);
|
map.addLayer(newl);
|
||||||
|
|
||||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ OpenLayers.Layer.GeoRSS.prototype =
|
|||||||
OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]);
|
OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]);
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.features = new Array();
|
this.features = new Array();
|
||||||
new Ajax.Request(location,
|
OpenLayers.loadURL(location, null, this, this.parseData);
|
||||||
{ method: 'get', onComplete:this.parseData.bind(this) } );
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,18 +58,25 @@ OpenLayers.Layer.GeoRSS.prototype =
|
|||||||
if (!doc || ajaxRequest.fileType!="XML") {
|
if (!doc || ajaxRequest.fileType!="XML") {
|
||||||
doc = OpenLayers.parseXMLString(ajaxRequest.responseText);
|
doc = OpenLayers.parseXMLString(ajaxRequest.responseText);
|
||||||
}
|
}
|
||||||
var pointlist = doc.getElementsByTagName('point');
|
var itemlist = doc.getElementsByTagName('item');
|
||||||
for (var i = 0; i < pointlist.length; i++) {
|
for (var i = 0; i < itemlist.length; i++) {
|
||||||
var data = {};
|
var data = {};
|
||||||
var location = pointlist[i].firstChild.nodeValue.split(" ");
|
var point = OpenLayers.Util.getNodes(itemlist[i], 'georss:point');
|
||||||
if (location.length != 2)
|
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(" ");
|
||||||
|
} else if (lat.length > 0 && lon.length > 0) {
|
||||||
|
var location = [parseFloat(lat[0].firstChild.nodeValue), parseFloat(lon[0].firstChild.nodeValue)];
|
||||||
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0]));
|
location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0]));
|
||||||
var title = OpenLayers.Util.getNodes(pointlist[i].parentNode, "title")[0].firstChild.nodeValue;
|
var title = OpenLayers.Util.getNodes(itemlist[i], "title")[0].firstChild.nodeValue;
|
||||||
var description = OpenLayers.Util.getNodes(pointlist[i].parentNode, "description")[0].firstChild.nodeValue;
|
var description = OpenLayers.Util.getNodes(itemlist[i], "description")[0].firstChild.nodeValue;
|
||||||
try { var link = OpenLayers.Util.getNodes(pointlist[i].parentNode, "link")[0].firstChild.nodeValue; } catch (e) { }
|
try { var link = OpenLayers.Util.getNodes(itemlist[i], "link")[0].firstChild.nodeValue; } catch (e) { }
|
||||||
data.icon = OpenLayers.Marker.defaultIcon();
|
data.icon = OpenLayers.Marker.defaultIcon();
|
||||||
data.popupSize = new OpenLayers.Size(250, 200);
|
data.popupSize = new OpenLayers.Size(250, 100);
|
||||||
if ((title != null) && (description != null)) {
|
if ((title != null) && (description != null)) {
|
||||||
contentHTML = "<br />";
|
contentHTML = "<br />";
|
||||||
contentHTML += "<div style='margin: -0.5em 0.5em 0.5em 0.5em'>"
|
contentHTML += "<div style='margin: -0.5em 0.5em 0.5em 0.5em'>"
|
||||||
|
|||||||
Reference in New Issue
Block a user