JSFiddle - React, Tailwind, and code Playground
by nathansnider
HTML
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.css">
<script src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
<script src="https://rawgit.com/MrMufflon/Leaflet.Elevation/master/dist/leaflet.elevation-0.0.4.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/MrMufflon/Leaflet.Elevation/master/dist/leaflet.elevation-0.0.4.css">
<script src="https://rawgithub.com/mpetazzoni/leaflet-gpx/master/gpx.js"></script>
<div class="map" id="demo-map"></div>
<footer>
<ul class="info">
<li>Distance: <span class="distance"></span> meter</li>—
<li>Duration: <span class="duration"></span>
</li>
<!-- — <li>Pace: <span class="pace"></span>/meter</li> -->
<!-- — <li>Avg HR: <span class="avghr"></span> bpm</li> -->—
<li>Elevation: +<span class="elevation-gain"></span> meter, -<span class="elevation-loss"></span> meter (net: <span class="elevation-net"></span> meter)</li>— Inspired by <a href="https://github.com/mpetazzoni/leaflet-gpx">leaflet-gpx</a>.
<br>
</ul>
</footer>
CSS
body {
width: 1100px;
margin: 0 auto;
}
.gpx {
border: 5px #aaa solid;
border-radius: 5px;
box-shadow: 0 0 3px 3px #ccc;
width: 1100px;
height: 550px;
, margin: 0;
}
.gpx header {
padding: 0.5em;
}
.gpx h4 {
margin: 0;
padding: 0;
font-weight: bold;
}
.gpx .start {
font-size: smaller;
color: #444;
}
.gpx .map {
border: 1px #888 solid;
border-left: none;
border-right: none;
width: 1100px;
height: 430px;
margin: 0;
}
.gpx footer {
background: #f0f0f0;
padding: 0.5em;
}
.gpx ul.info {
list-style: none;
margin: 0;
padding: 0;
font-size: smaller;
}
.gpx ul.info li {
color: #666;
padding: 2px;
display: inline;
}
.gpx ul.info li span {
color: black;
}
JavaScript
function display_gpx(elt) {
if (!elt) return;
var url = elt.getAttribute('data-gpx-source');
var mapid = elt.getAttribute('data-map-target');
if (!url || !mapid) return;
function _t(t) {
return elt.getElementsByTagName(t)[0];
}
function _c(c) {
return elt.getElementsByClassName(c)[0];
}
var map = L.map(mapid);
L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'iles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
}).addTo(map);
new L.GPX("gpsfile.gpx", {
async: true,
marker_options: {
startIconUrl: './lib/leaflet-gpx/pin-icon-start.png',
endIconUrl: './lib/leaflet-gpx/pin-icon-end.png',
shadowUrl: './lib/leaflet-gpx/pin-shadow.png'
},
}).on('loaded', function (e) {
var gpx = e.target;
map.fitBounds(gpx.getBounds());
_t('h3').textContent = gpx.get_name();
_c('start').textContent = gpx.get_start_time().toDateString() + ', ' + gpx.get_start_time().toLocaleTimeString();
_c('end').textContent = gpx.get_end_time().toDateString() + ', ' + gpx.get_end_time().toLocaleTimeString();
_c('distance').textContent = gpx.get_distance().toFixed(2);
_c('duration').textContent = gpx.get_duration_string(gpx.get_moving_time());
<!-- _c('pace').textContent = gpx.get_duration_string(gpx.get_moving_pace(), true); -->
<!-- _c('avghr').textContent = gpx.get_average_hr(); -->
_c('elevation-gain').textContent = (gpx.get_elevation_gain()).toFixed(0);
_c('elevation-loss').textContent = (gpx.get_elevation_loss()).toFixed(0);
_c('elevation-net').textContent = (gpx.get_elevation_gain() -...