-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.html
executable file
·188 lines (165 loc) · 5.42 KB
/
route.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Individual Assessment</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
.overlay {
position: absolute;
top: 20px;
left: 20px;
}
.overlay button {
font:10000 35px/40px 'Helvetica Neue', Arial, Helvetica, sans-serif;
background-color: #000000;
color: #fff;
display: inline-block;
margin: 0;
padding: 10px 20px;
border: none;
cursor: pointer;
border-radius: 3px;
}
.overlay button:hover {
background-color:#4ea0da;
}
</style>
<style type='text/css'>
#info {
display: block;
position: relative;
margin: 0px auto;
width: 50%;
padding: 10px;
border: none;
border-radius: 3px;
font-size: 20px;
font-weight:bold;
text-align: center;
color: #fff;
background: #222;
}
</style>
<nav id="menu"></nav>
<div id='map'></div>
<div class='overlay'>
<button id='replay'>Replay</button>
</div>
<pre id='info'></pre>
<script src='d3.min.js' charset='utf-8'></script>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiYm93ZW56IiwiYSI6ImNqcXozdGhvcTAwejk0OXJ1dXdjOHF2OWYifQ.HQbdYg7FZiEdy7QoiTsMVQ';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/bowenz/cjt3g4e342mai1fqtzuys8iej',
center: [0.173236, 51.569900],
zoom: 9.2
});
map.on('load', function () {
// We use D3 to fetch the JSON here so that we can parse and use it separately
//
var layers = map.getStyle().layers;
var labelLayerId;
for (var i = 0; i < layers.length; i++) {
if (layers[i].type === 'symbol' && layers[i].layout['text-field']) {
labelLayerId = layers[i].id;
break;
}
}
map.addLayer({
'id': '3d-buildings',
'source': 'composite',
'source-layer': 'building',
'filter': ['==', 'extrude', 'true'],
'type': 'fill-extrusion',
'minzoom': 15,
'paint': {
'fill-extrusion-color': '#aaa',
// use an 'interpolate' expression to add a smooth transition effect to the
// buildings as the user zooms in
'fill-extrusion-height': [
"interpolate", ["linear"], ["zoom"],
15, 0,
15.05, ["get", "height"]
],
'fill-extrusion-base': [
"interpolate", ["linear"], ["zoom"],
15, 0,
15.05, ["get", "min_height"]
],
'fill-extrusion-opacity': .6
}
}, labelLayerId);
d3.json("route_line.json", function(err, data) {
if (err) throw err;
// save full coordinate list for later
var coordinates = data.features[0].geometry.coordinates;
// start by showing just the first coordinate
data.features[0].geometry.coordinates = [coordinates[0]];
// add it to the map
map.addSource('trace', { type: 'geojson', data: data });
map.addLayer({
"id": "trace",
"type": "line",
"source": "trace",
"paint": {
"line-color": "yellow",
"line-opacity": 0.75,
"line-width": 5
}
});
// setup the viewport
map.jumpTo({ 'center': coordinates[0], 'zoom': 16 });
map.setPitch(45);
// on a regular basis, add more coordinates from the saved list and update the map
var i = 0;
var timer = window.setInterval(function() {
if (i < coordinates.length) {
data.features[0].geometry.coordinates.push(coordinates[i]);
map.getSource('trace').setData(data);
map.panTo(coordinates[i]);
document.getElementById('info').innerHTML =
"Current Location is (Lon,Lat,Alt)"+'<br />'+
JSON.stringify(coordinates[i]);
i++;
} else {
window.clearInterval(timer);
}
}, 24);
document.getElementById('replay').addEventListener('click', function() {
// Set the coordinates of the original point back to origin
// start by showing just the first coordinate
data.features[0].geometry.coordinates = [coordinates[0]];
map.jumpTo({ 'center': coordinates[0], 'zoom': 16 });
// Update the source layer
map.getSource('trace').setData(data);
// Reset the counter
i = 0;
var timer = window.setInterval(function() {
if (i < coordinates.length) {
data.features[0].geometry.coordinates.push(coordinates[i]);
map.getSource('trace').setData(data);
map.panTo(coordinates[i]);
document.getElementById('info').innerHTML =
"Current Location is (Lon,Lat,Alt)"+'<br />'+
JSON.stringify(coordinates[i]);
i++;
} else {
window.clearInterval(timer);
}
}, 24);
});
});
});
</script>
</body>
</html>