json - Looping through GeoJSON items from GeoRSS with jQuery -
i have georss feed, trying parse jquery create geojson array can add mapbox map leaflet.
i think have managed turn georss geojson ok, can;t seem work out how loop through each item can add map. if take out loop part single point plotted onto map - recent entry rss feed.
any pointers appreciated!
here's code i'm running:
$(document).ready(function(){ $.get('http://shifting-sands.com/feed/', function(rssdata) { var $xml = $(rssdata); $xml.find("title").each(function() { var $this = $(this), item = { title: $this.find("title").text(), link: $this.find("link").text(), description: $this.find("description").text(), pubdate: $this.find("pubdate").text(), latitude: $this.find("lat").text(), longitude: $this.find("long").text() }
function displayposts(rssdata){ $.each(rssdata.rss.channel.item, function(i,item){
//read in lat , long of each photo , stores in variable. lat = item.latitude; long = item.longitude; title = item.title; clickurl = item.link; //get url image. var htmlstring = '<a href="' + clickurl + '">' + title + '</a>'; var contentstring = '<div id="content">' + htmlstring + '</div>'; //create new marker position using leaflet api. var rssmarker = l.marker([lat, long]).addto(map); //create new info window using google maps api rssmarker.bindpopup(contentstring).openpopup(); }); } }); });
});
create geojson feature collection:
var featurecollection = { type: 'featurecollection', features: [] };
and in each loop iteration, push feature onto it.
featurecollection.features.push({ type: 'feature', properties: {}, // properties want in feature geometry: [long, lat] });
Comments
Post a Comment