/* * Timemap.js Copyright 2008 Nick Rabinowitz. * Licensed under the MIT License (see LICENSE.txt) */ /** * @fileOverview * GeoRSS Loader * * @author Nick Rabinowitz (www.nickrabinowitz.com) */ /*globals GXml, TimeMap, TimeMapDataset */ /** * @class * GeoRSS loader factory - inherits from remote loader. * *
This is a loader class for GeoRSS feeds. Parsing is complicated by the * diversity of GeoRSS formats; this parser handles:
*and looks for geographic information in the following formats:
*At the moment, this only supports points; polygons, polylines, and boxes * will be added at some later point.
* * @example Usage in TimeMap.init(): datasets: [ { title: "GeoRSS Dataset", type: "georss", // Data to be loaded in GeoRSS options: { url: "mydata.rss" // GeoRSS file to load - must be a local URL } } ] * * @param {Object} options All options for the loader:* {Array} url URL of GeoRSS file to load (NB: must be local address) * {Function} preloadFunction Function to call on data before loading * {Function} transformFunction Function to call on individual items before loading ** @return {TimeMap.loaders.remote} Remote loader configured for GeoRSS */ TimeMap.loaders.georss = function(options) { var loader = new TimeMap.loaders.remote(options); loader.parse = TimeMap.loaders.georss.parse; return loader; } /** * Static function to parse GeoRSS * * @param {XML text} rss GeoRSS to be parsed * @return {TimeMapItem Array} Array of TimeMapItems */ TimeMap.loaders.georss.parse = function(rss) { var items = [], data, node, placemarks, pm; node = GXml.parse(rss); // get TimeMap utilty functions // assigning to variables should compress better var util = TimeMap.util; var getTagValue = util.getTagValue, getNodeList = util.getNodeList, makePoint = util.makePoint, makePoly = util.makePoly, formatDate = util.formatDate, nsMap = util.nsMap; // define namespaces nsMap.georss = 'http://www.georss.org/georss'; nsMap.gml = 'http://www.opengis.net/gml'; nsMap.geo = 'http://www.w3.org/2003/01/geo/wgs84_pos#'; nsMap.kml = 'http://www.opengis.net/kml/2.2'; // determine whether this is an Atom feed or an RSS feed var feedType = (node.firstChild.tagName == 'rss') ? 'rss' : 'atom'; // look for placemarks var tName = (feedType == 'rss' ? "item" : "entry"); placemarks = getNodeList(node, tName); for (var i=0; i