-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamicline.html
53 lines (44 loc) · 1.56 KB
/
dynamicline.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Dynamically Drawing a Line</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<script src='//api.tiles.mapbox.com/mapbox.js/v1.5.0/mapbox.js'></script>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.5.0/mapbox.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>
var map = L.mapbox.map('map', 'jonahadkins.map-xyxnaoxk')
.setView([0, 0], 3);
// add a new line to the map, but one with no points - yet
var polyline = L.polyline([]).addTo(map);
// keep a tally of how many points we've added to the map
var pointsAdded = 0;
// start adding new points to the map
add();
function add() {
// addLatLng takes a new latLng location and puts it at the end of the
// line. You could pull points from your data or generate them - this
// example just makes a sine wave with some math.
polyline.addLatLng(
L.latLng(
Math.cos(pointsAdded / 20) * 30,
pointsAdded));
//L.latLng(-72.92,41.30);
//L.latLng(85.35,27.7);
//L.latLng(31.20,30.00);
// pan the map along with where the line is being added. optional, of course
map.setView([0, pointsAdded], 3);
// then, if we haven't already added a lot of points, queue up the page
// to call add() in a 100 milliseconds
if (++pointsAdded < 360) window.setTimeout(add, 100);
}
</script>
</body>
</html>