Add GeoRSS layer and example. Only support for georss:point for the time being. Probably has a fair number of cases where it can fail, but it works for a first run, and the community can build from here :)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@778 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
143
lib/OpenLayers/Layer/GeoRSS.js
Normal file
143
lib/OpenLayers/Layer/GeoRSS.js
Normal file
@@ -0,0 +1,143 @@
|
||||
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
|
||||
* text of the license. */
|
||||
// @require: OpenLayers/Layer/Markers.js
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
OpenLayers.Layer.GeoRSS = Class.create();
|
||||
OpenLayers.Layer.GeoRSS.prototype =
|
||||
Object.extend( new OpenLayers.Layer.Markers(), {
|
||||
|
||||
/** store url of text file
|
||||
* @type str */
|
||||
location:null,
|
||||
|
||||
/** @type Array(OpenLayers.Feature) */
|
||||
features: null,
|
||||
|
||||
/** @type OpenLayers.Feature */
|
||||
selectedFeature: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String} location
|
||||
*/
|
||||
initialize: function(name, location) {
|
||||
OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]);
|
||||
this.location = location;
|
||||
this.features = new Array();
|
||||
new Ajax.Request(location,
|
||||
{ method: 'get', onComplete:this.parseData.bind(this) } );
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
destroy: function() {
|
||||
this.clearFeatures();
|
||||
this.features = null;
|
||||
OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
/** WFS layer is never a base class.
|
||||
* @type Boolean
|
||||
*/
|
||||
isBaseLayer: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @param {?} ajaxRequest
|
||||
*/
|
||||
parseData: function(ajaxRequest) {
|
||||
var doc = ajaxRequest.responseXML;
|
||||
if (!doc || ajaxRequest.fileType!="XML") {
|
||||
doc = OpenLayers.parseXMLString(ajaxRequest.responseText);
|
||||
}
|
||||
var pointlist = doc.getElementsByTagName('point');
|
||||
for (var i = 0; i < pointlist.length; i++) {
|
||||
var data = {};
|
||||
var location = pointlist[i].firstChild.nodeValue.split(" ");
|
||||
if (location.length != 2)
|
||||
continue;
|
||||
location = new OpenLayers.LonLat(parseFloat(location[1]), parseFloat(location[0]));
|
||||
var title = OpenLayers.Util.getNodes(pointlist[i].parentNode, "title")[0].firstChild.nodeValue;
|
||||
var description = OpenLayers.Util.getNodes(pointlist[i].parentNode, "description")[0].firstChild.nodeValue;
|
||||
try { var link = OpenLayers.Util.getNodes(pointlist[i].parentNode, "link")[0].firstChild.nodeValue; } catch (e) { }
|
||||
data.icon = OpenLayers.Marker.defaultIcon();
|
||||
data.popupSize = new OpenLayers.Size(250, 200);
|
||||
if ((title != null) && (description != null)) {
|
||||
contentHTML = "<br />";
|
||||
contentHTML += "<div style='margin: -0.5em 0.5em 0.5em 0.5em'>"
|
||||
|
||||
contentHTML += "<div style='height: 1.3em; overflow: hidden'>";
|
||||
contentHTML += "<span style='font-size: 1.2em; font-weight: bold'>";
|
||||
if (link) contentHTML += "<a href='"+link+"' target='_blank'>";
|
||||
contentHTML += title;
|
||||
if (link) contentHTML += "</a>";
|
||||
contentHTML += "</span>";
|
||||
contentHTML += "</div>";
|
||||
|
||||
|
||||
contentHTML += "<span style='font-size: 0.7em; align:center'>";
|
||||
contentHTML += description;
|
||||
contentHTML += "</span>";
|
||||
|
||||
contentHTML += "</div>"
|
||||
data['popupContentHTML'] = contentHTML;
|
||||
|
||||
//data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>';
|
||||
}
|
||||
var feature = new OpenLayers.Feature(this, location, data);
|
||||
this.features.append(feature);
|
||||
var marker = feature.createMarker();
|
||||
marker.events.register('click', feature, this.markerClick);
|
||||
this.addMarker(marker);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
markerClick: function(evt) {
|
||||
sameMarkerClicked = (this == this.layer.selectedFeature);
|
||||
this.layer.selectedFeature = (!sameMarkerClicked) ? this : null;
|
||||
for(var i=0; i < this.layer.map.popups.length; i++) {
|
||||
this.layer.map.removePopup(this.layer.map.popups[i]);
|
||||
}
|
||||
if (!sameMarkerClicked) {
|
||||
var popup = this.createPopup();
|
||||
Event.observe(popup.div, "click",
|
||||
function() {
|
||||
for(var i=0; i < this.layer.map.popups.length; i++) {
|
||||
this.layer.map.removePopup(this.layer.map.popups[i]);
|
||||
}
|
||||
}.bindAsEventListener(this));
|
||||
this.layer.map.addPopup(popup);
|
||||
}
|
||||
Event.stop(evt);
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
clearFeatures: function() {
|
||||
if (this.features != null) {
|
||||
while(this.features.length > 0) {
|
||||
var feature = this.features[0];
|
||||
this.features.remove(feature);
|
||||
feature.destroy();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Layer.GeoRSS"
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user