1

is it possible to integrate GeoRSS in Leaflet and how? Couldn't find any hint.

For example this georss:

http://www.geonames.org/recent-changes.xml

Which looks like..

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<rss xmlns:georss="http://www.georss.org/georss" version="2.0">
<channel>
<title>GeoNames.org recent changes</title>
<link>http://www.geonames.org/recent-changes.html</link>
<description>50 most recent modifications</description>
<item>
<title>Museo Archeologico Statale</title>
<link>http://www.geonames.org/10628777/museo-archeologico-statale.html</link>
<guid>http://www.geonames.org/10628777/museo-archeologico-statale.html#revision=-1</guid>
<description>created</description>
<pubDate>Wed, 19 Aug 2015 16:52:43 +0200</pubDate>
<georss:point>39.08025 17.13105</georss:point>
</item>
<item>
<title>Palazzo Morelli</title>
<link>http://www.geonames.org/10628776/palazzo-morelli.html</link>
<guid>http://www.geonames.org/10628776/palazzo-morelli.html#revision=-1</guid>
<description>created</description>
<pubDate>Wed, 19 Aug 2015 16:52:19 +0200</pubDate>
<georss:point>39.08081 17.13135</georss:point>
</item>

<!-- More Entries Through Here -->

</channel>
</rss>
2

Building from the comment by @elrobis here is an example using jQuery for getting the georss and adding simple markers to a map:

<html>
<head>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
</head>
<body>
    <div id="map" style="width: 700px; height: 500px"></div>

    <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>

    <script>
        var lat = 39;
        var lng = 17;
        var zoom = 2;
        var map = L.map('map').setView([lat,lng],zoom);

        // set up the ajax call
        function getXML(url) {
            return $.get(url)
        }

        // fire and handle the result
        getXML('http://www.geonames.org/recent-changes.xml').done(function(xml){
            var output = {}; // restructure the xml as an object
            $(xml).find('item').each(function() {
                var nodes = $(this).children();
                $.each(nodes, function(i,node){
                    var name = node.tagName;
                    var value = node.textContent;
                    output[name] = value;
                });
                // build markers from the output and add to the map
                var marker = L.marker([output['georss:point'].split(' ')[0], output['georss:point'].split(' ')[1]]);
                var popupContent = output.description; 
                marker.bindPopup(popupContent)
                marker.addTo(map);
            });
        })

    </script>
</body>
</html>
  • BTW...would it be possible to update the marker layer every x second? Only the marker layer not a whole reload of the page, cause that would change the view. Thanks – hoge6b01 Aug 21 '15 at 10:23
  • I also added some more content to the popups. Got a problem with the link inside the popup. It apears blueish but does not get the right link. Any idea how I need to change the code? Here the [JSFiddle] (jsfiddle.net/a76m16ev) – hoge6b01 Aug 21 '15 at 13:49
  • 1
    the links just needed a bit of formatting, I prefer single quotes then you can use double quotes in the html: jsfiddle.net/a76m16ev/1 – toms Aug 21 '15 at 16:16
  • 1
    for updating markers, you could use setInterval or setTimout. You would have to remove the markers before adding them again - maybe with a layerGroup. It would be better to know if there were changes during the interval - maybe they publish that? – toms Aug 21 '15 at 16:22
  • 1
    I noticed that the service itself is sometimes down. You can use one of the previous fiddles to confirm that you have data from the feed. Here it is with timeout: jsfiddle.net/a76m16ev/4 – toms Sep 2 '15 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.