-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrajectory_plotter.js
More file actions
70 lines (49 loc) · 1.29 KB
/
trajectory_plotter.js
File metadata and controls
70 lines (49 loc) · 1.29 KB
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
/*
JS Requirements:
<script src='https://api.mapbox.com/mapbox.js/v2.2.4/mapbox.js'></script>
CSS Requirements:
<link href='https://api.mapbox.com/mapbox.js/v2.2.4/mapbox.css' rel='stylesheet' />
*/
/* A data point */
var Point = (function(latitude, longitude) {
return {
latitude: latitude,
longitude: longitude
}
});
var Trajectory = (function(points) {
if(points != null){
var points = points;
} else {
var points = [];
}
var polyline = L.polyline([]);
var currentIndex = 0;
var plotPoint = function() {
var lat_lon = L.latLng(points[currentIndex].latitude, points[currentIndex].longitude);
polyline.addLatLng(lat_lon);
currentIndex++;
};
var hasPoints = function() {
return (points.length != currentIndex + 1);
}
return {
plotPoint: plotPoint,
hasPoints: hasPoints,
polyline: polyline
}
});
var TrajectoryModule = (function(token, data) {
L.mapbox.accessToken = token;
var map = L.mapbox.map('map', 'mapbox.streets')
.setView([0, 0], 3);
var trajectory = Trajectory(data);
console.log(trajectory);
// Add a new line to the map with no points.
trajectory.polyline.addTo(map);
var plotRecursively = function() {
trajectory.plotPoint();
window.setTimeout(plotRecursively, 100);
};
plotRecursively();
});