-
Notifications
You must be signed in to change notification settings - Fork 2
/
leaflet-elevation_geojson-data.html
218 lines (200 loc) · 6.23 KB
/
leaflet-elevation_geojson-data.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<title>DEM-Net and leaflet-elevation.js</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style>
html,
body,
#map,
#app,
#elevation-div {
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
}
#map {
height: 75%;
}
#app {
padding-top: 50px;
}
#elevation-div {
height: 25%;
font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
}
</style>
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- Leaflet (JS/CSS) -->
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<!-- D3.js -->
<script
src="https://unpkg.com/[email protected]/build/d3.min.js"
charset="utf-8"
></script>
<!-- leaflet-gpx -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.4.0/gpx.js"></script>
<!-- leaflet-elevation -->
<link
rel="stylesheet"
href="https://unpkg.com/@raruto/[email protected]/leaflet-elevation.min.css"
/>
<script src="https://unpkg.com/@raruto/[email protected]/leaflet-elevation.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<style>
.height-focus.line,
.height-focus-label {
display: none;
}
.height-focus.circle-lower {
stroke: white;
fill: black;
/*background: url(https://maps.google.com/mapfiles/kml/pal4/icon25.png);*/
stroke-width: 3px;
-webkit-filter: drop-shadow(0 0 5px #000);
filter: drop-shadow(0 0 5px #000);
}
</style>
<style>
.gpx-summary {
font-family: "Lucida Grande", "Lucida Sans Unicode", Verdana, Arial,
Helvetica, sans-serif;
font-size: 12px;
position: absolute;
bottom: 0;
left: 45px;
}
.gpx-summary .summaryvalue {
font-weight: bold;
}
</style>
</head>
<body>
<div id="app">
<input
type="file"
id="fileElem"
accept="application/gpx+xml"
@change="getElevation"
/>
<div id="map"></div>
<div id="elevation-div" class="leaflet-control elevation"></div>
<div id="gpx-summary" class="gpx-summary">
<span class="totlen">
<span class="summarylabel">Total Length: </span>
<span class="summaryvalue">0</span>
</span>
—
<span class="maxele"
><span class="summarylabel">Max Elevation: </span
><span class="summaryvalue">0</span></span
>
—
<span class="minele"
><span class="summarylabel">Min Elevation: </span
><span class="summaryvalue">0</span></span
>
</div>
</div>
<script>
var app = new Vue({
el: "#app",
data: {
message: "Hello Vue!"
},
methods: {
getElevation(e) {
let formData = new FormData();
formData.append("file", fileElem.files[0]);
axios
.post(
"https://localhost:5001/api/elevation/gpx/geojson?dataset=AW3D30&reduceResolution=0",
formData,
{
headers: {
"Content-Type": "multipart/form-data"
}
}
)
.then(result => {
controlElevation.clear();
controlElevation.loadGeoJSON(result.data);
})
.catch(err => alert("error"));
}
}
});
var opts = {
map: {
center: [41.4583, 12.7059],
zoom: 5,
markerZoomAnimation: false,
zoomControl: false
},
zoomControl: {
position: "topleft"
},
otmLayer: {
url: "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png",
options: {
attribution:
'Map data: © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
/*subdomains:"1234"*/
}
},
elevationControl: {
url: "",
options: {
theme: "lime-theme", //default: lime-theme
useHeightIndicator: true, //if false a marker is drawn at map position
interpolation: d3.curveLinear, //see https://github.com/d3/d3/wiki/
collapsed: false, //collapsed mode, show chart on click or mouseover
elevationDiv: "#elevation-div",
detachedView: true
}
},
layersControl: {
options: {
collapsed: false
}
}
};
var map = new L.Map("map", opts.map);
var baseLayers = {};
baseLayers.OTM = new L.TileLayer(
opts.otmLayer.url,
opts.otmLayer.options
);
var controlZoom = new L.Control.Zoom(opts.zoomControl);
var controlElevation = L.control.elevation(opts.elevationControl.options);
var controlLayer = L.control.layers(
baseLayers,
null,
opts.layersControl.options
);
controlZoom.addTo(map);
controlLayer.addTo(map);
controlElevation.loadChart(map);
controlElevation.loadData(opts.elevationControl.url);
map.addLayer(baseLayers.OTM);
map.on("eledata_loaded", function(e) {
var q = document.querySelector.bind(document);
var track = e.track_info;
controlLayer.addOverlay(e.layer, e.name);
q(".totlen .summaryvalue").innerHTML =
track.distance.toFixed(2) + " km";
q(".maxele .summaryvalue").innerHTML =
track.elevation_max.toFixed(2) + " m";
q(".minele .summaryvalue").innerHTML =
track.elevation_min.toFixed(2) + " m";
});
</script>
</body>
</html>