OS OpenSpace [logo]

OS OpenSpace Forum » OS OpenSpace » Newbie Area

Thread: GeoRSS

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 9 - Pages: 1 - Last Post: 18-Mar-2012 13:21 by: pw240639
pw240639

Posts: 20
Registered: 07/08/08
GeoRSS
Posted: 29-Jan-2012 10:21
  Click to reply to this thread Reply

Up till now, I have used XML for my geo-located data in my OpenSpace apps with success despite my lack of Javascript skills but now I need to move to GeoRSS feeds.
I do not see any good examples, tutorials or documentation that help me as a newbie.

Here is one of my GeoRSS responses:

http://api.collectionsbase.org.uk/os/?queryType=lucene&startPage=1&count=50&q=partner_code:NHS&fq[]=dcterms.isPartOf%3ADSH&fq[]={!geofilt}&sfield=latlon&pt=52.586833,-2.126992&d=200&format=georss&q_op=AND&projection=4326

How do I upload this GeoRSS data into an OpenSpace map ?

An example would be most helpful,

Phil Walker

OS OpenSpace Team

Posts: 1,112
Registered: 31/01/08
Re: GeoRSS
Posted: 01-Feb-2012 09:16   in response to: pw240639
  Click to reply to this thread Reply

Hi 'pw240639'

Openlayers has a GeoRSS function to create points have a look here for details - http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Layer/GeoRSS-js.html#OpenLayers.Layer.GeoRSS.formatOptions

However in addition to the Openlayers GeoRSS function we would recommend that you have a look at the following Openlayers GeoRSS examples (you’ll need to view the page source) –
http://openlayers.org/dev/examples/georss.html
http://openlayers.org/dev/examples/georss-markers.html

The following thread might also be of help to you –
https://openspace.ordnancesurvey.co.uk/openspaceforum/thread.jspa?threadID=99

Finally it may be beneficial for you to contact the company that make that georss API available so that you can check that you are running the correct query – we have noticed that the projection in your link is 4326 (WGS 84), we had more luck with the query when we changed this to 27700 (BNG) – So it looks like the API supports BNG projection.

Kind regards

Tamsyn
OS OpenSpace Team

pw240639

Posts: 20
Registered: 07/08/08
Re: GeoRSS
Posted: 01-Feb-2012 20:32   in response to: OS OpenSpace Team
  Click to reply to this thread Reply

Many thanks.

I hope this will answer my problems!

Cheers,
Phil

pw240639

Posts: 20
Registered: 07/08/08
Re: GeoRSS
Posted: 03-Feb-2012 13:37   in response to: OS OpenSpace Team
  Click to reply to this thread Reply

Hi Tamsyn,

I am afraid I need a bit more help, as a newbie.

On the two OpenLayers examples you sent, the maps are "WMS". I up to now use OpenSpace maps. Is there a difference?

Also unfortunately in the thread you send , https://openspace.ordnancesurvey.co.uk/openspaceforum/thread.jspa?threadID=99 , kes1's example is no longer available, so I can't understand his comment:

"I suspect it's to do with needing to reuse the vector layer already created on the map but I can't seem to get this to work with the openlayers georss feature type."

Cheers,
Phil

OS OpenSpace Team

Posts: 1,112
Registered: 31/01/08
Re: GeoRSS
Posted: 06-Feb-2012 13:18   in response to: pw240639
  Click to reply to this thread Reply

Hi Phil,

Using the http://openlayers.org/dev/examples/georss-markers.html example the following section:

map = new OpenLayers.Map('map', {maxResolution:'auto'});
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);

Can be switched out for:

osMap = new OpenSpace.Map('map');
osMap.setCenter(new OpenSpace.MapPoint(438760,114760), 8);

(using whichever coordinates and zoom level you wish). Presuming that there is only 1 GeoRSS feed to be used then only one needs to be added (the example uses 2 feeds styled in different ways + a layer switcher).

HTH's

Kind regards

Tamsyn

OS OpenSpace Team

pw240639

Posts: 20
Registered: 07/08/08
Re: GeoRSS
Posted: 10-Feb-2012 11:39   in response to: OS OpenSpace Team
  Click to reply to this thread Reply

Thanks,

This definitely helped!

Now for the next problem, see my post in "Sidebars"

Phil

pw240639

Posts: 20
Registered: 07/08/08
Re: GeoRSS
Posted: 02-Mar-2012 10:35   in response to: OS OpenSpace Team
  Click to reply to this thread Reply

Hi Tamsyn,

I have followed your Georss changes at my webpage:.

http://www.sundial.pwp.blueyonder.co.uk/OpenSpace/DSHSNPmaps-v3.html

My Georss snippet is:

var newl = new OpenLayers.Layer.GeoRSS( 'GeoRSS', 'georss.xml');
osMap.addLayer(newl);

I am confused. The OpenLayer Georss example shows markers, infowindows etc but
in my version , there is no markers etc on the map .The HTML appears correct . My Georss XML file looks OK and Firefox does not show any errors.

Is the OpenSpace different from the OpenLayers example?

How has the Georss parser produce gml.pos, title, links for each item?

Where can I see the results of an OpenLayers.Layer.GeoRSS function ?

How can I examine the DOM to see what is going wrong?

I apologize by advance for the many questions.

Best regards,
Phil Walker

OS OpenSpace Team

Posts: 1,112
Registered: 31/01/08
Re: GeoRSS
Posted: 02-Mar-2012 15:12   in response to: pw240639
  Click to reply to this thread Reply

Hi Phil,

We have had a look and have noticed that in your sidebars thread you link to:
http://www.sundial.pwp.blueyonder.co.uk/OpenSpace/DSHSNPmaps.html which takes a georss feed, parses it and creates markers correctly.

However your latest example: http://www.sundial.pwp.blueyonder.co.uk/OpenSpace/DSHSNPmaps-v3.html is the one that you are having trouble with and although they are different pages you appear to have used slightly different ways to import a georss feed and parse it. If there is no real reason for this perhaps using the first way for both pages would resolve the issue for you?

In relation to your 4 questions:

Is the OpenSpace different from the OpenLayers example?


Well OpenSpace builds on Openlayers – if a function works in Openlayers it should work when calling OpenSpace.

How has the Georss parser produce gml.pos, title, links for each item?

This is more of an Openlayers question and the OpenLayers documentation should be able to provide more information on this.

Where can I see the results of an OpenLayers.Layer.GeoRSS function?

This would be available from the OpenLayer documentation: http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers-js.html. Alternatively you could use Firebug to look at the examples we provided earlier in the thread to see how those Georss functions worked in the browser compared to yours.

How can I examine the DOM to see what is going wrong?

You can examine the DOM using the Firefox plugin Firebug.

I hope you find this information useful?

Kind regards

Tamsyn
OS OpenSpace Team

pw240639

Posts: 20
Registered: 07/08/08
Re: GeoRSS
Posted: 05-Mar-2012 12:51   in response to: pw240639
  Click to reply to this thread Reply

Hi Tamsyn,
Yes. you're right. My sidebars thread is OK but only in some browsers. I normally use Firefox 10 and IE8 and they are no problem but when I check on Chrome and Safari, I get these Javascript errors in Firebug:

at :
var pos=y.childNodes[0].nodeValue;

Chrome: Uncaught TypeError - Cannot read property "childNodes" of undefined
Safari: TypeError:"undefined" is not an object (evaluating" y.childNodes")

I spent some time without understanding the problem and decided rashly that, rather than I should parse my GEORSS feed "manually", I should go for the GeoRSS option.

So yes,if you can clear my original problem, I don't need the GeoRSS option but it should be easier for newbies and I notice that there are a number of readers who have read this thread. However, the Open Layer GeoRSS Docs.are not helpful when there are Javascript errors in the GeoRSS function, as in my latest example.

Will you be producing an OpenSpace GeoRSS example?


Kind regards,
Phil Walker

pw240639

Posts: 20
Registered: 07/08/08
Re: GeoRSS
Posted: 18-Mar-2012 13:21   in response to: pw240639
  Click to reply to this thread Reply

Hi Forum Readers,

I wrote :


"Yes. you're right. My sidebars thread is OK but only in some browsers. I normally use Firefox 10 and IE8 and they are no problem but when I check on Chrome and Safari, I get these Javascript errors in Firebug:

at :
var pos=y.childNodes[0].nodeValue;

Chrome: Uncaught TypeError - Cannot read property "childNodes" of undefined
Safari: TypeError:"undefined" is not an object (evaluating" y.childNodes")"


At last I now know how to correct my error in my GeoRSS thread.Here is the corrected webpage:

http://www.sundial.pwp.blueyonder.co.uk/OpenSpace/DSHSNPmaps-v5.html


and the key snippet from the GeoRSS feed is:

<georss:where>
<gml:Point srsName="urn:ogc:def:crs:EPSG::27700">
<gml:pos>372613 318419</gml:pos>
</gml:Point>
</georss:where>
<georss:where>false</georss:where>


The first problem was to ensure that all browsers were compatible in the way they handle the XML file load. This seems to work:

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
// alert("code for IE7+, Firefox, Chrome, Opera, Safari");
}
else
{// code for IE6, IE5
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
//alert("code for IE6, IE5");

}

xmlhttp.open("GET","georss200212.xml",false);
xmlhttp.send(null);
xmlDoc=xmlhttp.responseXML.documentElement;
}

where "georss200212.xml" is my GeoRSS filename


The second problem was that I didn't understand the way in which GeoRSS namespaces works within tags. These lines worked in my Firefox:

var y = x.getElementsByTagName("gml:pos")[0];
var pos =y.childNodes[0].nodeValue;

whereas the current version uses "getElementsByTagNameNS" which parses separately the namespace, colon and the tag, and works apparently for all browsers.


if (x.getElementsByTagNameNS !== undefined){
var y = x.getElementsByTagNameNS("*","pos")[0];
//alert("ElementsByTagNameNS");
}else{
var y = x.getElementsByTagName("gml:pos")[0];
//alert("ElementsByTagName");
}
var pos =y.childNodes[0].nodeValue;

Any comments on my newbie conclusions would be appreciated.

Phil


Legend
Expert: 51 - 1000 pts
Advanced: 31 - 50 pts
Intermediate: 16 - 30 pts
Novice: 5 - 15 pts
Newbie: 0 - 4 pts
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums