We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've constructed this code based on the principles of Daniel Schiffmans 'exercise_18_15_new_bubbles_xml.pde' on Github.
All is going well, except that I am having difficulty applying it using Unfolding Maps to display train locations from an XML file.
I wish to display either a 'SimplePointMarker' (from the Unfolding Maps library) or a simple ellipse for each train location. My difficulty is with the mapping. I can map one train with no issues but unsure how to map all within the array.
I have tried a few things like making an array of train locations separately and making another object to handle mapping but both have failed.
The code is posted below. The core issue lies on line 80.
The XML data is contained in this link. I copied it to a static XML file: https://data.smartdublin.ie/cgi-bin/rtpi/realtimebusinformation?stopid=7602&format=xml
Any help would be greatly appreciated. Thank you :)
*I edited the code to be more simple in my response below
Answers
Here is a simplified version using a static XML file rather than a stream. The text from the xml file is posted directly below the code.
As a stop gap, have mapped the coordinates to roughly the correct locations. But once you zoom in/out, this mapping does not correspond.
Anyone with any tips on how to get this to work with 'Simplepointmarkers' or other wise where the coordinates are preserved regardless of panning/zooming would be much appreciated. Thank you :)
I did not try out your code, but a couple of remarks on first sight:
ScreenPosition pos = map.getScreenPosition(trains[i].location)
and draw something at that screen position.Hope that helps.
Thanks tnagel. I know that is a core built in feature. Maybe I didn't phrase the question well. Basically I am having trouble putting it into an array and making it work like you describe.
The Unfolding maps library example files seem to deal with various methods of placing arrays of markers based on CSV, Json and RSS. However, my example is using an XML feed. Anything I try based on those examples seems to fail. That's why I haphazardly arranged the previous code as a workaround while I try to get it to work.
Sorry if I was unclear. Thanks :)
I tried another technique. No joy. I tried to follow along with this tutorial, and did my best to substitute the CSV techniques he uses for XML. https://vimeo.com/90091197
I deleted the trains object to simplify. It should simply print out the static XML coordinates to the map.
I can get a print out of the readings (line 62) no problem, but the markers do not print to screen.
println("Train Code: " + trainCode + ", Latitude: " + latitude + ", Longitude: " + longitude);
One thing to note is that when the "StamenMapProvider.Toner" (line 39) was included it threw up an error saying the it did not exist. Also the 'OPENGL' in the size function threw an error so I changed it to 'P2D', as that seems to work in all other unfolding maps.
I'm not sure where I am going wrong. My code is as follows:
I tried a different techique based on your reply to a query from a user about appling a SQL database to the application: https://forum.processing.org/two/discussion/9300/mapping-coordinates-from-database-using-unfolding
This seems to work but I'll now try and get timer running to update it. Here the code, in case it's of use to anyone in future:
And now all seems to update and run okay based on a timer object: