Giter Club home page Giter Club logo

gpxviewer's Introduction

gpxviewer

This original version of this project is hosted on Google Code at http://code.google.com/p/gpxviewer/.

This fork adds support for version 3 of the Google Maps API, and the coding style of the library has been changed a bit for clarity. From the Google Code page:

The GPX viewer is a 100% client-side JavaScript GPX file viewer that uses Google Maps to map waypoints and tracklogs.

GPX files are a standard GPS data format that is supported by many software applications. It is an XML based data format which lends itself nicely to being parsed in JavaScript.

Since it is written entirely in JavaScript, this script can be added to any web page with minimal effort and little or no server code. Just copy a GPX file to your web site, make a web page with an embedded Google Map, include the script, and initialize it.

This script is meant to be customized to some extent. The default formatting for Waypoints is to show the available GPS data, but since it is Javascript, you can easily customize it to suite your needs.

Usage

Load the Google Maps JavaScript API v3, preferably at the end of the <body> of your document. (See Google's documentation if you need help.)

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

Make sure your page has a <div> to place the map, like this:

<div id="map" style="width: 100%; height: 100%;"></div>

Next you need to pass your GPX data to the GPXParser object - a quick way to do this is to perform an AJAX request using jQuery to retreive a GPX file hosted on the same web server as the map page.

(Note that you can't load a file from another server due to the same origin policy.)

You can grab jQuery from Google as well:

<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js">
</script>

Once these pieces are in place, loading JavaScript like this example should do the trick:

function loadGPXFileIntoGoogleMap(map, filename) {
    $.ajax({url: filename,
        dataType: "xml",
        success: function(data) {
          var parser = new GPXParser(data, map);
          parser.setTrackColour("#ff0000");     // Set the track line colour
          parser.setTrackWidth(5);          // Set the track line width
          parser.setMinTrackPointDelta(0.001);      // Set the minimum distance between track points
          parser.centerAndZoom(data);
          parser.addTrackpointsToMap();         // Add the trackpoints
          parser.addRoutepointsToMap();         // Add the routepoints
          parser.addWaypointsToMap();           // Add the waypoints
        }
    });
}

$(document).ready(function() {
    var mapOptions = {
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map"),
        mapOptions);
    loadGPXFileIntoGoogleMap(map, "pocotrail.xml");
});

Acknowledgements

Thanks to Kaz Okuda for the original version of this library.

The blog post describing the original version.

License

This project is licensed under the GNU GPL v3 license.

gpxviewer's People

Contributors

aurmil avatar joushx avatar peplin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gpxviewer's Issues

Route support?

hello

the lib does not seem to support rte / rtept nodes
or is there a problem with my file?

<?xml version="1.0" encoding="utf-8"?>
<gpx version="1.1" creator="Movescount - http://www.movescount.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.cluetrust.com/XML/GPXDATA/1/0 http://www.cluetrust.com/Schemas/gpxdata10.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns="http://www.topografix.com/GPX/1/1">
   <rte>
      <name>Test</name>
      <rtept lat="47.080059" lon="15.401038">
         <ele>344</ele>
      </rtept>
      <rtept lat="47.08006" lon="15.400902">
         <ele>344</ele>
      </rtept>
      <rtept lat="47.080074" lon="15.400745">
         <ele>344</ele>
      </rtept>
...
   </rte>
</gpx>

thanks,
regards

Viewing elevation/time

Just an FYI -- I needed a bit of extra functionality, specifically the ability to see the time/elevation at any point along the track. So for each polyline I added an onclick handler that opens an info window, centered on the nearest track point neighbor to the click location, that shows the time/elevation for that point. The nearest neighbor is found by storing all points in a quadtree (https://github.com/d3/d3-quadtree).

If you'd like to include these changes, I can submit a pull request for you. If not, that's fine too.

https://github.com/pcurrier/gpxviewer

No track lines

Thanks for a great script. It works really well. But it doesn't draw tracks on the map on Mac OS, using Safari, Chrome or Firefox. Perhaps there is a problem with my gpx file?

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="AvPlan" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">
<metadata>  <link href="http://www.avsoft.com.au">
<text>AvSoft</text>
</link><time>2016-04-12T22:52:08Z</time>
</metadata><wpt lon="130.975556" lat="-25.186111">
<ele>1626</ele>
<name>YAYE</name>
<desc>AYERS ROCK</desc>
<type>AD</type>
</wpt>
<wpt lon="130.968149" lat="-25.335986">
<ele>0</ele>
<name>2520.159S13058.089E</name>
<desc>2520.159S13058.089E</desc>
<type>U</type>
</wpt>
<wpt lon="131.087441" lat="-25.296806">
<ele>0</ele>
<name>2517.808S1315.246E</name>
<desc>2517.808S1315.246E</desc>
<type>U</type>
</wpt>
<wpt lon="130.968149" lat="-25.335986">
<ele>0</ele>
<name>2520.159S13058.089E</name>
<desc>2520.159S13058.089E</desc>
<type>U</type>
</wpt>
<wpt lon="130.786428" lat="-25.272357">
<ele>0</ele>
<name>2516.341S13047.186E</name>
<desc>2516.341S13047.186E</desc>
<type>U</type>
</wpt>
<wpt lon="130.710479" lat="-25.268761">
<ele>0</ele>
<name>2516.126S13042.629E</name>
<desc>2516.126S13042.629E</desc>
<type>U</type>
</wpt>
<wpt lon="130.707696" lat="-25.352517">
<ele>0</ele>
<name>2521.151S13042.462E</name>
<desc>2521.151S13042.462E</desc>
<type>U</type>
</wpt>
<wpt lon="130.710479" lat="-25.268761">
<ele>0</ele>
<name>2516.126S13042.629E</name>
<desc>2516.126S13042.629E</desc>
<type>U</type>
</wpt>
<wpt lon="130.786428" lat="-25.272357">
<ele>0</ele>
<name>2516.341S13047.186E</name>
<desc>2516.341S13047.186E</desc>
<type>U</type>
</wpt>
<wpt lon="130.975556" lat="-25.186111">
<ele>1626</ele>
<name>YAYE</name>
<desc>AYERS ROCK</desc>
<type>AD</type>
</wpt>
<wpt lon="132.324317" lat="-24.647583">
<ele>1824</ele>
<name>Y0OU</name>
<desc>WALLARA RANCH STATION</desc>
<type>ALA</type>
</wpt>
<wpt lon="133.408333" lat="-24.016667">
<ele>0</ele>
<name>LWG</name>
<desc>LAWRENCE GORGE</desc>
<type>VFA</type>
</wpt>
<wpt lon="133.900833" lat="-23.808333">
<ele>1789</ele>
<name>YBAS</name>
<desc>ALICE SPRINGS</desc>
<type>AD</type>
</wpt>
<rte>

..and it goes on...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.