Paikkatietotyöpaja2011 kovanen

Post on 26-Jun-2015

2.317 views 0 download

Tags:

Transcript of Paikkatietotyöpaja2011 kovanen

Finnish Geodetic Institute Department of Geoinformatics and Cartography

Presenting trains in real-time in OpenLayers via GeoRSS

Janne Kovanen

GI Norden June 8–9, 2011, Turku, Finland

2 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

GeoRSS

  An geographical syntax in RSS feeds (XML)   The coordinate reference system is WGS84   A coordinate conversion to a plane coordinate

reference system is mostly required

  Notice! In web browsers you typically see the interpretation of a RSS feed reader   view-source:http://188.117.35.14/TrainRSS/

TrainService.svc/trainInfo?train=P704

  Updating from an app requires a proxy   Several exists (web )

3 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

GeoRSS and GeoRSS-Simple

  For Atom 1.0, RSS 2.0 and RSS 1.0   GML content   <georss:where>

<gml:Point> <gml:pos>45.256 -71.92</gml:pos> </gml:Point> </georss:where>

  Too complex? Simpler alternative:   <georss:point>60.1 54.2</georss:point>   <georss:line>45.256 -110.45 46.46 -109.48 43.84 -109.86</

georss:line>   <georss:polygon>45.256 -110.45 46.46 -109.48 43.84 -109.86

45.256 -110.45</georss:polygon>

4 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

OpenLayers and GeoRSS

  OpenLayers.Layer.GeoRSS   Extends a layer for markers   As such OL downloads the feed only ones   Features are stored as OpenLayers.Feature   Does not contains methods for handling features!

  OpenLayers.Format.GeoRSS   Format for reading GeoRSS   Only reads such as a title, description and geometry   Features are handled as OpenLayers.Feature.Vector

  OpenLayers.LonLat vs. OpenLayers.Geometry

5 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

“Trains on a map” interface All trains <rss version="2.0"> <channel xmlns:georss="http://www.georss.org/georss"> <title>Train Feed</title> <description>All trains feed</description> <lastBuildDate>Tue, 20 Sep 2011 15:00:35 +0300</lastBuildDate> <category>Train System</category> <item> <guid isPermaLink="false">H355</guid> <category>1</category><title>H 355</title> <description>Summary</description> <pubDate>Tue, 20 Sep 2011 15:00:35 +0300</pubDate> <georss:point>60.6302800000001 26.8929000000001</georss:point> <from>KTS</from><to>KV</to> <status>1</status><dir>345</dir> </item> ... </channel> </rss>

http://www.apps4finland.fi/fi/data/junat-kartalla-palvelun-rajapinta/

6 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

Demo 1: Static one time feed

// Use some proxy. Add the IP address to the proxy file before this OpenLayers.ProxyHost = “/cgi-bin/proxy.cgi?url=”; // Initialize OpenLayers function init() {

var map = new OpenLayers.Map('map'); // Create the background map layers etc (the other demo) // Create the train layer var newTrainLayer = new OpenLayers.Layer.GeoRSS( “Train Feed”, “http://188.117.35.14/TrainRSS/TrainService.svc/AllTrains”, {projection: new OpenLayers.Projection(“EPSG:4326”)});

map.addLayer(newTrainLayer); // Add controls etc. }

7 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

“Trains on a map” interface Detailed information on trains <rss version="2.0”> <channel xmlns:georss="http://www.georss.org/georss"> <title>P 704</title> <description>Train information feed for train P 704</description> <lastBuildDate>Fri, 16 Sep 2011 13:57:05 +0300</lastBuildDate> <category>1</category> <georss:point>62.2989900000001 27.1673200000001</georss:point> <speed>33</speed> <heading>355</heading> <startStation>OL</startStation> <endStation>KUO</endStation> <status>1</status> <reasonCode/> <lateness>0</lateness> … </channel> </rss>

8 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

“Trains on a map” interface Detailed information on trains <rss version="2.0”> <channel xmlns:georss="http://www.georss.org/georss"> <title>P 704</title> <description>Train information feed for train P 704</description> <lastBuildDate>Fri, 16 Sep 2011 13:57:05 +0300</lastBuildDate> <category>1</category> <georss:point>62.2989900000001 27.1673200000001</georss:point> <speed>33</speed> <heading>355</heading> <startStation>OL</startStation> <endStation>KUO</endStation> <status>1</status> <reasonCode/> <lateness>0</lateness> … </channel> </rss>

9 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

“Trains on a map” interface Detailed information on trains <rss version="2.0"><channel xmlns:georss="http://www.georss.org/georss"><title>IC 71</title><description>Train information feed for train IC 71</description><lastBuildDate>Mon, 19 Sep 2011 11:41:47 +0300</lastBuildDate><category>1</category><georss:point>62.2989900000001 27.1673200000001</georss:point><speed>33</speed><heading>355</heading><startStation>HKI</startStation><endStation>KAJ</endStation><status>1</status><reasonCode> </reasonCode><lateness>0</lateness><item><guid isPermaLink="false">HKI</guid><title>HKI</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime/><scheduledDepartTime>08:12</scheduledDepartTime><eta/><etd>08:12</etd><stationCode>HKI</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">PSL</guid><title>PSL</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>08:17</scheduledTime><scheduledDepartTime>08:18</scheduledDepartTime><eta>08:17</eta><etd>08:18</etd><stationCode>PSL</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">TKL</guid><title>TKL</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>08:27</scheduledTime><scheduledDepartTime>08:28</scheduledDepartTime><eta>08:27</eta><etd>08:28</etd><stationCode>TKL</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">LH</guid><title>LH</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>09:06</scheduledTime><scheduledDepartTime>09:08</scheduledDepartTime><eta>09:06</eta><etd>09:08</etd><stationCode>LH</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">KV</guid><title>KV</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>09:38</scheduledTime><scheduledDepartTime>09:52</scheduledDepartTime><eta>09:38</eta><etd>09:52</etd><stationCode>KV</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">MR</guid><title>MR</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>10:30</scheduledTime><scheduledDepartTime>10:31</scheduledDepartTime><eta>10:30</eta><etd>10:31</etd><stationCode>MR</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">MI</guid><title>MI</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>10:55</scheduledTime><scheduledDepartTime>10:58</scheduledDepartTime><eta>10:55</eta><etd>10:58</etd><stationCode>MI</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">HAU</guid><title>HAU</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>11:21</scheduledTime><scheduledDepartTime>11:22</scheduledDepartTime><eta>11:21</eta><etd>11:22</etd><stationCode>HAU</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">PM</guid><title>PM</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>11:41</scheduledTime><scheduledDepartTime>11:46</scheduledDepartTime><eta>11:41</eta><etd>11:46</etd><stationCode>PM</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">SNJ</guid><title>SNJ</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>12:14</scheduledTime><scheduledDepartTime>12:15</scheduledDepartTime><eta>12:14</eta><etd>12:15</etd><stationCode>SNJ</stationCode><completed>0</completed><status>5</

>09:06</scheduledTime><scheduledDepartTime>09:08</scheduledDepartTime><eta>09:06</eta><etd>09:08</etd><stationCode>LH</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">KV</guid><title>KV</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>09:38</scheduledTime><scheduledDepartTime>09:52</scheduledDepartTime><eta>09:38</eta><etd>09:52</etd><stationCode>KV</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">MR</guid><title>MR</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>10:30</scheduledTime><scheduledDepartTime>10:31</scheduledDepartTime><eta>10:30</eta><etd>10:31</etd><stationCode>MR</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">MI</guid><title>MI</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>10:55</scheduledTime><scheduledDepartTime>10:58</scheduledDepartTime><eta>10:55</eta><etd>10:58</etd><stationCode>MI</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">HAU</guid><title>HAU</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>11:21</scheduledTime><scheduledDepartTime>11:22</scheduledDepartTime><eta>11:21</eta><etd>11:22</etd><stationCode>HAU</stationCode><completed>1</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">PM</guid><title>PM</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>11:41</scheduledTime><scheduledDepartTime>11:46</scheduledDepartTime><eta>11:41</eta><etd>11:46</etd><stationCode>PM</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">SNJ</guid><title>SNJ</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>12:14</scheduledTime><scheduledDepartTime>12:15</scheduledDepartTime><eta>12:14</eta><etd>12:15</etd><stationCode>SNJ</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">KUO</guid><title>KUO</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>12:43</scheduledTime><scheduledDepartTime>12:47</scheduledDepartTime><eta>12:43</eta><etd>12:47</etd><stationCode>KUO</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">SIJ</guid><title>SIJ</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>13:05</scheduledTime><scheduledDepartTime>13:06</scheduledDepartTime><eta>13:05</eta><etd>13:06</etd><stationCode>SIJ</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">LNA</guid><title>LNA</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>13:32</scheduledTime><scheduledDepartTime>13:33</scheduledDepartTime><eta>13:32</eta><etd>13:33</etd><stationCode>LNA</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">ILM</guid><title>ILM</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>13:48</scheduledTime><scheduledDepartTime>13:50</scheduledDepartTime><eta>13:48</eta><etd>13:50</etd><stationCode>ILM</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">SKV</guid><title>SKV</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>14:13</scheduledTime><scheduledDepartTime>14:14</scheduledDepartTime><eta>14:13</eta><etd>14:14</etd><stationCode>SKV</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item><item><guid isPermaLink="false">KAJ</guid><title>KAJ</title><description>Summary</description><pubDate>Mon, 19 Sep 2011 11:41:47 +0300</pubDate><scheduledTime>14:40</scheduledTime><scheduledDepartTime/><eta>14:40</eta><etd/><stationCode>KAJ</stationCode><completed>0</completed><status>5</status><georss:point>0 0</georss:point></item></channel></rss>

10 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

Demo 2: Make the trains move // Add the trains layer in the init() through a function call function init() { // …

updateTrains(); }

function updateTrains() { // Do not yet show the trains layer in the layer switcher var newTrainLayer = new OpenLayers.Layer.GeoRSS( “Train Feed”, “http://188.117.35.14/TrainRSS/TrainService.svc/AllTrains”, {projection: new OpenLayers.Projection(“EPSG:4326”),

displayInLayerSwitcher: false}); map.addLayer(newTrainLayer);

// Add a listener for loading newTrainLayer.events.register("loadend", self, function(e) {trainsLoaded(e)});

}

11 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

… Demo 2: Make the trains move // The update interval in milliseconds var trainSetUpdateTimeout = 2000;

function trainsLoaded(event) { if(event.object == null) return; if(trainsLayer != null && trainsLayer != event.object) { map.removeLayer(trainsLayer, false); } trainsLayer = event.object;

// Now show the trains layer on the map and in the layer switcher trainsLayer.setVisibility(true); trainsLayer.displayInLayerSwitcher = true; // Timed update self.setTimeout('updateTrains()', trainSetUpdateTimeout); }

Example 2

12 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

Demo 3: Extending OpenLayers

var TrainRSS = OpenLayers.Class(OpenLayers.Format.XML, { initialize: function(options) { OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); }, …

}

var TrainFeature = OpenLayers.Class(OpenLayers.Feature, { guid: "”, type: 0, speed: 0, heading: 0, status: 0, initialize: function(layer, lonlat, data) { OpenLayers.Feature.prototype.initialize.apply(this, [layer, lonlat, data]);

}, …

}

13 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

… Demo 3: Extending OpenLayers var TrainsRSS = OpenLayers.Class(OpenLayers.Format.GeoRSS, {

layer: null, initialize: function(layer, options) { OpenLayers.Format.GeoRSS.prototype.initialize.apply(this, [options]); this.layer = layer; }, …

},

var TrainsLayer = OpenLayers.Class(OpenLayers.Layer.GeoRSS, { initialize: function(name, location, options) { OpenLayers.Layer.GeoRSS.prototype.initialize.apply(this, [name, location, options]); }, …

},

14 Finnish Geodetic Institute janne.kovanen@fgi.fi

Workshop on Open Location Data 2011

“Trains on a map” interface Train station information <rss version="2.0"> <channel xmlns:georss="http://www.georss.org/georss"> <title /> <description>Station information feed for station KML</description> <lastBuildDate>Thu, 03 Feb 2011 17:18:42 +0200</lastBuildDate> <category>Train System</category> <item> <guid isPermaLink="false">P274</guid> <category>1</category> <title>P 274</title> <description>Summary</description> <pubDate>Thu, 03 Feb 2011 17:18:42 +0200</pubDate> <georss:point>0 0</georss:point> … </item> … </channel> </rss>

http://www.apps4finland.fi/fi/data/junat-kartalla-palvelun-rajapinta/