Merge pull request #1329 from bartvde/gpx-trkpt

Add GPX tracks example
This commit is contained in:
Bart van den Eijnden
2013-12-02 10:03:46 -08:00
3 changed files with 127 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="gpx4j" 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">
<trk>
<name>290311</name>
<desc>(null)</desc>
<trkseg>
<trkpt lat="39.114318" lon="-0.425692">
<ele>126.951324</ele>
<time>2011-03-29T14:45:52Z</time>
</trkpt>
<trkpt lat="39.114226" lon="-0.425648">
<ele>122.974365</ele>
<time>2011-03-29T14:46:03Z</time>
</trkpt>
<trkpt lat="39.114226" lon="-0.425648">
<ele>122.974365</ele>
<time>2011-03-29T14:46:07Z</time>
</trkpt>
<trkpt lat="39.114134" lon="-0.425608">
<ele>120.310211</ele>
<time>2011-03-29T14:46:09Z</time>
</trkpt>
<trkpt lat="39.114239" lon="-0.425657">
<ele>117.177261</ele>
<time>2011-03-29T14:46:18Z</time>
</trkpt>
<trkpt lat="39.114317" lon="-0.425718">
<ele>116.083771</ele>
<time>2011-03-29T14:46:21Z</time>
</trkpt>
<trkpt lat="39.114412" lon="-0.425789">
<ele>115.956726</ele>
<time>2011-03-29T14:46:25Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>

50
examples/gpx-trkpt.html Normal file
View File

@@ -0,0 +1,50 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="../css/ol.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
<title>GPX tracks example</title>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
<div class="row-fluid">
<div class="span4">
<h4 id="title">GPX tracks example</h4>
<p id="shortdesc">Example of using the GPX parser to display tracks.</p>
<div id="docs">
<p>See the <a href="gpx-trkpt.js" target="_blank">gpx-trkpt.js source</a> to see how this is done.</p>
</div>
<div id="tags">GPX trackpoint tracks</div>
</div>
</div>
</div>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="loader.js?id=gpx-trkpt" type="text/javascript"></script>
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
</body>
</html>

40
examples/gpx-trkpt.js Normal file
View File

@@ -0,0 +1,40 @@
goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.parser.GPX');
goog.require('ol.proj');
goog.require('ol.source.OSM');
goog.require('ol.source.Vector');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
parser: new ol.parser.GPX(),
url: 'data/gpx/gpx4j.xml'
}),
style: new ol.style.Style({
symbolizers: [
new ol.style.Stroke({
color: 'red',
opacity: 1
})
]
})
});
var map = new ol.Map({
layers: [raster, vector],
renderer: ol.RendererHint.CANVAS,
target: 'map',
view: new ol.View2D({
center: ol.proj.transform([-0.425692, 39.114318], 'EPSG:4326', 'EPSG:3857'),
zoom: 19
})
});