Steve Purkis
on Mon May 14 2007 17:51:21 GMT+0100 (GMT)
This is an edited version of a post I made earlier on my personal blog.
So, at the last Fotango hack day I finally managed to turn my JavaScript GPX Parser into a Zimki library - you'll find it in my new code repository: http://code.spurkis.org/. Yes, it's free to use & source is available under the LGPL.
It doesn't do much more than turn GPX files into GPX objects (with an option to set the minimum distance between track points so you don't inundate yourself with useless information), and I've only made the server-side JS available for the moment - if you want to see it in use on the client-side, see http://www.spurkis.org/maps, it should handle both GPX 1.0 & GPX 1.1. While it does have unit tests for both versions, I've only used it with the traces made available from my Garmin Venture Cx so far, which annoyingly only lets me get at traces, not waypoints et. al.
Using it is pretty simple (or so I think ;-). Once you've got a Zimki account, create a new JavaScript instance in your dev realm that does something like:
zimki.library.require('code.staging.spurkis.org', 'gpxutils.js');
function handleGpxUpload(args) {
if (args.gpxfile) {
// uploading a new gpx File
zimki.log.debug( 'uploading ' + args.gpxfile.filename );
var file = args.gpxfile.save(args.gpxfile.filename);
// then parse & store it
var gpxContainer = newGPXContainerForFile(file);
return '<html><body>uploaded & parsed GPX File: ' + args.gpxfile.filename + '</body></html>';
}
return <html><body><form method="POST" enctype="multipart/form-data">
<p>GPX File: <input type="file" name="gpxfile" size="30"/></p>
<p><input type="submit" name="submit" value="upload"/></p></form>
<p><a href="/json.listGPX">json.listGPX</a></p>
<p><a href="/json.getGPX">json.getGPX</a><em>?name=uploaded-file-name</em></p>
</body></html>;
}
zimki.publishPath('/', handleGpxUpload);
zimki.publishPath('json.getGPX', handleJsonGetGPX);
zimki.publishPath('json.listGPX', handleJsonListGPX);
You can then go to http://your.realm.zimki.com/ to try it out. If all goes well, that'll let you upload/parse your GPX files as-is and list/get them over a JSON API.
As implied above, the client-side hooks that tie the JSON returned by the GPX API together with the online mapping providers (ie: Yahoo!, Google, Multimap, Mapstraction, etc. etc.) are not yet available. They will be as & when I have time.
Note: originally, I contemplated using Notions' GPX File Viewer but I got bogged down by a few things - I had to rename the GPX files before the browser would deal with them, and all the processing was done client side (ie: it wouldn't store my pre-parsed GPX traces for me). Then I considered porting it, but it doesn't use E4X (b/c it's corss-browser compatible), and it's also tied to Google Maps. So I decided to write this. But it's a good library for client-side JS, so if that's all you need then check it out. Really, I just wanted to play with Zimki a bit more… ;-)
Also, Andy Armstrong's Geo::GPX Perl module proved quite handy while implementing this. I've even nicked some of his test data to save me some time. Thanks Andy!
Anyways, if you do try this library out, let me know what you think!
read more / 0 comments
|