This repository has been archived by the owner on Jun 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapTracking.html
99 lines (86 loc) · 2.75 KB
/
mapTracking.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Rotating and controllable marker</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/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>
L.mapbox.accessToken = 'pk.eyJ1Ijoib2JsaXZpZ2EiLCJhIjoidTRFRlVGQSJ9.2B9SCCTYdsIU8i_NlSRUYQ';
// MIT-licensed code by Benjamin Becquet
// https://github.com/bbecquet/Leaflet.PolylineDecorator
L.RotatedMarker = L.Marker.extend({
options: {
angle: 0
},
_setPos: function(pos) {
L.Marker.prototype._setPos.call(this, pos);
if (L.DomUtil.TRANSFORM) {
// use the CSS transform rule if available
this._icon.style[L.DomUtil.TRANSFORM] += ' rotate(' + this.options.angle + 'deg)';
} else if (L.Browser.ie) {
// fallback for IE6, IE7, IE8
var rad = this.options.angle * L.LatLng.DEG_TO_RAD,
costheta = Math.cos(rad),
sintheta = Math.sin(rad);
this._icon.style.filter += ' progid:DXImageTransform.Microsoft.Matrix(sizingMethod=\'auto expand\', M11=' +
costheta + ', M12=' + (-sintheta) + ', M21=' + sintheta + ', M22=' + costheta + ')';
}
}
});
L.rotatedMarker = function(pos, options) {
return new L.RotatedMarker(pos, options);
};
var map = L.mapbox.map('map', 'examples.map-h67hf2ic', {
keyboard: false
}).setView([37.9, -77], 4);
var marker = L.rotatedMarker(new L.LatLng(37.9, -77), {
icon: L.icon({
iconUrl: 'https://www.mapbox.com/maki/renders/[email protected]',
iconSize: [24, 24],
}),
draggable: true
});
marker.addTo(map);
var direction = 0,
manual = false;
window.setInterval(function() {
var ll = marker.getLatLng();
ll.lat += Math.cos(direction) / 100;
ll.lng += Math.sin(direction) / 100;
marker.options.angle = direction * (180 / Math.PI);
marker.setLatLng(ll);
if (!manual && Math.random() > 0.95) {
direction += (Math.random() - 0.5) / 2;
}
}, 10);
// Add manual control of the airplane with left and right arrow keys, just because
document.body.addEventListener('keydown', function(e) {
if (e.which == 37) {
direction -= 0.1;
manual = true;
}
if (e.which == 39) {
direction += 0.1;
manual = true;
}
}, true);
</script>
</body>
</html>