1+ {{ $file := .Get "file" }}
2+ {{ $height := .Get "height" | default "500px" }}
3+ {{ $mapStyle := .Get "style" | default "outdoors" }}
4+ {{ $routeColor := .Get "color" | default "#ff0000" }}
5+ {{ $gpxResource := .Page.Resources.GetMatch $file }}
6+
7+ {{ if $gpxResource }}
8+ < div class ="gpx-container ">
9+ < div id ="map-{{ anchorize $file }} " style ="height: {{ $height }}; width: 100%; "> </ div >
10+ < div id ="stats-{{ anchorize $file }} " class ="gpx-stats "> </ div >
11+ < a href ="{{ $gpxResource.RelPermalink }} " download class ="gpx-download-link "> Download GPX</ a >
12+ </ div >
13+
14+ < link rel ="stylesheet " href ="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css " />
15+ < script src ="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js "> </ script >
16+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.7.0/gpx.min.js "> </ script >
17+
18+ < style >
19+ . gpx-container {
20+ margin : 2rem 0 ;
21+ border : 1px solid # 333;
22+ }
23+ # map- { { anchorize $file } } {
24+ background: # 1a1a1a;
25+ }
26+ . gpx-stats {
27+ display : flex;
28+ gap : 0 ;
29+ background : # 000;
30+ border-top : 1px solid # 333;
31+ font-family : -apple-system, BlinkMacSystemFont, "Segoe UI" , Roboto, sans-serif;
32+ }
33+ . gpx-stat {
34+ flex : 1 ;
35+ text-align : center;
36+ padding : 1rem ;
37+ border-right : 1px solid # 333;
38+ }
39+ . gpx-stat : last-child {
40+ border-right : none;
41+ }
42+ . gpx-stat-value {
43+ font-size : 1.5rem ;
44+ font-weight : 600 ;
45+ color : # fff;
46+ font-variant-numeric : tabular-nums;
47+ }
48+ . gpx-stat-label {
49+ color : # 999;
50+ font-size : 0.75rem ;
51+ text-transform : uppercase;
52+ letter-spacing : 0.5px ;
53+ margin-top : 0.25rem ;
54+ }
55+ . gpx-download-link {
56+ display : block;
57+ text-align : center;
58+ padding : 0.75rem ;
59+ background : # 000;
60+ color : # fff;
61+ text-decoration : none;
62+ border-top : 1px solid # 333;
63+ font-size : 0.85rem ;
64+ transition : background 0.2s ;
65+ }
66+ . gpx-download-link : hover {
67+ background : # 1a1a1a;
68+ }
69+ @media ( max-width : 768px ) {
70+ . gpx-stats {
71+ flex-direction : column;
72+ }
73+ . gpx-stat {
74+ border-right : none;
75+ border-bottom : 1px solid # 333;
76+ }
77+ . gpx-stat : last-child {
78+ border-bottom : none;
79+ }
80+ }
81+ </ style >
82+
83+ < script >
84+ ( function ( ) {
85+ var mapId = 'map-{{ anchorize $file }}' ;
86+ var statsId = 'stats-{{ anchorize $file }}' ;
87+ var mapStyle = '{{ $mapStyle }}' ;
88+ var routeColor = '{{ $routeColor }}' ;
89+
90+ var map = L . map ( mapId ) ;
91+
92+ // Map style selection
93+ var tileConfig = {
94+ 'outdoors' : {
95+ url : 'https://tiles.stadiamaps.com/tiles/outdoors/{z}/{x}/{y}{r}.png' ,
96+ attribution : '© Stadia Maps, © OpenMapTiles, © OpenStreetMap contributors' ,
97+ maxZoom : 20
98+ } ,
99+ 'osm' : {
100+ url : 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ,
101+ attribution : '© OpenStreetMap contributors' ,
102+ maxZoom : 19
103+ } ,
104+ 'topo' : {
105+ url : 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png' ,
106+ attribution : '© OpenStreetMap contributors, SRTM | © OpenTopoMap' ,
107+ maxZoom : 17
108+ } ,
109+ 'satellite' : {
110+ url : 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' ,
111+ attribution : '© Esri' ,
112+ maxZoom : 19
113+ } ,
114+ 'terrain' : {
115+ url : 'https://tiles.stadiamaps.com/tiles/stamen_terrain/{z}/{x}/{y}{r}.png' ,
116+ attribution : '© Stamen Design, © OpenStreetMap contributors' ,
117+ maxZoom : 18
118+ }
119+ } ;
120+
121+ var config = tileConfig [ mapStyle ] || tileConfig [ 'outdoors' ] ;
122+
123+ L . tileLayer ( config . url , {
124+ attribution : config . attribution ,
125+ maxZoom : config . maxZoom
126+ } ) . addTo ( map ) ;
127+
128+ new L . GPX ( '{{ $gpxResource.RelPermalink }}' , {
129+ async : true ,
130+ marker_options : {
131+ startIconUrl : 'https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.7.0/pin-icon-start.png' ,
132+ endIconUrl : 'https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.7.0/pin-icon-end.png' ,
133+ shadowUrl : 'https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.7.0/pin-shadow.png'
134+ } ,
135+ polyline_options : {
136+ color : routeColor ,
137+ opacity : 0.8 ,
138+ weight : 4
139+ }
140+ } ) . on ( 'loaded' , function ( e ) {
141+ map . fitBounds ( e . target . getBounds ( ) , {
142+ padding : [ 50 , 50 ]
143+ } ) ;
144+
145+ var gpx = e . target ;
146+ var distance = ( gpx . get_distance ( ) / 1000 ) . toFixed ( 1 ) ;
147+ var elevGain = Math . round ( gpx . get_elevation_gain ( ) ) ;
148+ var elevLoss = Math . round ( gpx . get_elevation_loss ( ) ) ;
149+
150+ document . getElementById ( statsId ) . innerHTML =
151+ '<div class="gpx-stat"><div class="gpx-stat-value">' + distance + ' km</div><div class="gpx-stat-label">Distance</div></div>' +
152+ '<div class="gpx-stat"><div class="gpx-stat-value">↑ ' + elevGain + ' m</div><div class="gpx-stat-label">Elevation Gain</div></div>' +
153+ '<div class="gpx-stat"><div class="gpx-stat-value">↓ ' + elevLoss + ' m</div><div class="gpx-stat-label">Elevation Loss</div></div>' ;
154+ } ) . addTo ( map ) ;
155+ } ) ( ) ;
156+ </ script >
157+ {{ end }}
0 commit comments