Created
October 12, 2009 09:27
-
-
Save andrewn/208286 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Method: createFeatureFromItem | |
* Return a feature from a GeoRSS Item. | |
* | |
* Parameters: | |
* item - {DOMElement} A GeoRSS item node. | |
* | |
* Returns: | |
* {<OpenLayers.Feature.Vector>} A feature representing the item. | |
*/ | |
createFeatureFromItem: function(item) { | |
var geometry = this.createGeometryFromItem(item); | |
/* Provide defaults for title and description */ | |
var title = this.getChildValue(item, "*", "title", this.featureTitle); | |
/* First try RSS descriptions, then Atom summaries */ | |
var description = this.getChildValue( | |
item, "*", "description", | |
this.getChildValue(item, "*", "content", | |
this.getChildValue(item, "*", "summary", this.featureDescription))); | |
/* If no link URL is found in the first child node, try the | |
href attribute */ | |
var link = this.getChildValue(item, "*", "link"); | |
if(!link) { | |
try { | |
link = this.getElementsByTagNameNS(item, "*", "link")[0].getAttribute("href"); | |
} catch(e) { | |
link = null; | |
} | |
} | |
var id = this.getChildValue(item, "*", "id", null); | |
// Everything in this object becomes 'feature.attributes' | |
// and URL is not fetched or stored | |
var data = { | |
"title": title, | |
"description": description, | |
"link": link | |
}; | |
var feature = new OpenLayers.Feature.Vector(geometry, data); | |
feature.fid = id; | |
return feature; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment