-
Notifications
You must be signed in to change notification settings - Fork 3
/
gpx_visualize.html
192 lines (180 loc) · 7.06 KB
/
gpx_visualize.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>GPX Visualizer</title>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython_stdlib.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.css" />
<script src="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gpxparser/dist/GPXParser.min.js"></script>
<style>
html, body, div, span {
margin: 0px;
}
#site {
height: 100vh;
height: 100dvh;
display: flex;
flex-direction: column;
}
#map {
flex: 1;
}
p:not(.maptalks-layer-switcher, .maptalks-layer-switcher *), input:not(.maptalks-layer-switcher, .maptalks-layer-switcher *) {
display: inline;
font-family: Arial, sans-serif;
font-size: 20px;
margin: 5px;
padding: 5px;
border-radius: 0px;
text-decoration: none;
font-weight: normal;
background-color: #f8f8f8;
color: black;
-webkit-appearance: none;
border: 1px solid black;
}
h2 {
font-family: Arial, sans-serif;
font-size: 28px;
text-decoration: none;
font-weight: normal;
margin: 20px;
}
h1 {
font-family: Arial, sans-serif;
font-size: 36px;
font-weight: bold;
margin: 0px 20px 20px;
}
</style>
</head>
<body onload="brython (0)">
<noscript>
<p>JavaScript is required to use this website.</p>
</noscript>
<script>
window.gpxParser = gpxParser
</script>
<script type = "text/python">
from browser import document, ajax, html, window, timer
mt = window.maptalks
Map = mt.Map.new ("map", {
"center": [0, 0],
"zoom": 2,
"maxZoom": 19,
"seamlessZoom": True,
"attribution": {
"content": "© <a href = 'https://esri.com'>esri</a> | <a href='https://carto.com/'>CARTO</a> | <a href = 'https://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
},
"layerSwitcherControl": {
"position": "top-right",
"baseTitle": "Base Layers",
"overlayTitle": "Layers",
"excludeLayers": [],
},
"baseLayer": mt.GroupTileLayer.new ("Base", [
mt.TileLayer.new ("OSM Standard", {
"urlTemplate": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
"maxZoom": 19
}),
mt.TileLayer.new ("ESRI Satellite", {
"visible": False,
"urlTemplate": "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
"maxZoom": 19
}),
mt.TileLayer.new ("Carto Light", {
"visible": False,
"urlTemplate": "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
"subdomains": ["a", "b", "c", "d"],
"maxZoom": 22
}),
mt.TileLayer.new ("Carto Dark", {
"visible": False,
"urlTemplate": "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
"subdomains": ["a", "b", "c", "d"],
"maxZoom": 22
}),
mt.TileLayer.new ("Carto Voyager", {
"visible": False,
"urlTemplate": "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png",
"subdomains": ["a", "b", "c", "d"],
"maxZoom": 22
})
])
})
gpx_layer = mt.VectorLayer.new ("GPX Track", None).addTo (Map)
preview = None
def interactive (toggle):
Map.setOptions ({
"draggable": toggle,
"dragPan": toggle,
"dragRotate": toggle,
"dragPitch": toggle,
"scrollWheelZoom": toggle,
"touchZoom": toggle,
"doubleClickZoom": toggle
})
def load_gpx (ev):
if not document ["gpx"].files:
return
reader = window.FileReader.new ()
reader.bind ("load", lambda ev: process_gpx (ev.target.result))
reader.readAsText (document ["gpx"].files [0])
def process_gpx (gpx_file):
global preview, gpx_layer, Map
gpx = window.gpxParser.new ()
gpx.parse (gpx_file)
if len (gpx.tracks) == 0:
window.alert ("No tracks found in the GPX file.")
document ["gpx"].value = ""
elif len (gpx.tracks) > 1:
window.alert ("Multiple tracks found in the GPX file. Only the first track will be displayed.")
preview = mt.LineString.new (tuple ((i.lon, i.lat) for i in gpx.tracks [0].points), {
"visible": True,
"editable": False,
"draggable": False,
"interactive": False,
"symbol": {
"lineColor": "#0000FF",
"lineWidth": 5
}
})
interactive (False)
temp = dict (Map.getView ())
preview.addTo (gpx_layer, True)
preview_view = dict (Map.getView ())
Map.setView (temp)
gpx_layer.clear ()
zoomout = 0
if temp ["zoom"] > 2:
zoomout = 1500
temp.update ({"zoom": 2})
Map.animateTo (temp, {"duration": 1500, "easing": "inAndOut"})
temp.update ({"center": preview_view ["center"]})
timer.set_timeout (lambda: Map.animateTo (temp, {"duration": 1000, "easing": "inAndOut"}), zoomout)
timer.set_timeout (lambda: Map.animateTo (preview_view, {"duration": 1500, "easing": "inAndOut"}), 1000 + zoomout)
timer.set_timeout (lambda: interactive (True), 2500 + zoomout)
timer.set_timeout (lambda: preview.addTo (gpx_layer, True), 2500 + zoomout)
document ["gpx"].bind ("change", load_gpx)
def animate (ev):
global preview
interactive (False)
if preview is None:
window.alert ("No GPX file loaded.")
return
preview.remove ()
preview.addTo (gpx_layer, True)
interactive (True)
document ["animate"].bind ("click", animate)
</script>
<div id="site">
<span>
<input type="file" id="gpx" accept=".gpx" />
<input type="button" id="animate" value="Animate!" />
</span>
<div id="map"></div>
</div>
</body>
</html>