-
Notifications
You must be signed in to change notification settings - Fork 5
/
longest.html
152 lines (125 loc) · 4.03 KB
/
longest.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Indian Railways Longest Route</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.15.0/mapbox-gl.js'></script>
<script type="text/javascript" src="//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script>
<!-- <script src='stations.js'></script> -->
<script src='station_time.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.15.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZ2VvaGFja2VyIiwiYSI6ImFIN0hENW8ifQ.GGpH9gLyEg0PZf3NPQ7Vrg';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/geohacker/cim0ng7dq00jxcglvn6jsjiqs', //stylesheet location
center: [82.705, 21.841], // starting position
zoom: 4, // starting zoom
hash: true,
minZoom: 4
});
var index = 0;
var start = null;
map.on('style.load', function () {
map.addSource('point', {
"type": "geojson",
"data": station_time.features[0]
});
map.addLayer({
"id": "point",
"source": "point",
"type": "circle",
"paint": {
"circle-radius": 10,
"circle-color": "#050df2",
"circle-blur": 1
},
});
map.addLayer({
"id": "pointInner",
"source": "point",
"type": "circle",
"paint": {
"circle-radius": 2,
"circle-color": "white"
},
});
map.addLayer({
"id": "pointLabel",
"source": "point",
"type": "symbol",
"layout": {
"text-field": "{name}, {time}, Day {day}",
"text-size": 12,
"text-anchor": "left",
"text-font": ["Open Sans Semibold"],
"text-max-width": 15
},
"paint": {
"text-translate": [5, 0],
"text-halo-color": "white",
"text-halo-width": 1
}
});
generatePoints();
});
function animateMarker(timestamp) {
if (!start) start = timestamp;
var interval = timestamp - start;
if (interval > 1300) {
start = timestamp;
if (index === route.features.length) {
index = 0;
}
var currentPoint = getPoint();
if (currentPoint.properties.name) {
}
map.getSource('point').setData(currentPoint);
index = index + 1;
}
// Request the next frame of the animation.
requestAnimationFrame(animateMarker);
}
function getPoint() {
return route.features[index];
}
var route = {
"type": "FeatureCollection",
"features": []
};
function generatePoints() {
var stationsLength = station_time.features.length;
for (var i = 0; i < stationsLength; i++) {
var time = station_time.features[i].properties.time.split(':');
var splitTime = time[0] + ":" + time[1];
station_time.features[i].properties.time = splitTime;
route.features.push(station_time.features[i]);
if (i !== stationsLength -1) {
var point1 = station_time.features[i];
var point2 = station_time.features[i+1];
var midpoint = turf.midpoint(point1, point2);
var midpoint2 = turf.midpoint(midpoint, point2);
// route.features.push(midpoint);
// route.features.push(midpoint2);
}
}
animateMarker(0);
}
// Google Analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-75475863-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>