-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
67 lines (52 loc) · 1.79 KB
/
index.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
<html>
<head>
<title>Leaflet.Boatmarker Demo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css">
<style>
html, body {
padding:0px;
margin:0px;
height:100%;
width:100%;
}
#map {
width:100%;
height:100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script>
<script src="leaflet.boatmarker.min.js"></script>
<script>
// create a map in the "map" div, set the view to a given place and zoom
var map = L.map("map").setView([54.199343, 12.020497], 13);
// add an OpenStreetMap tile layer
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", {
attribution: "© <a href=\"http://osm.org/copyright\">OpenStreetMap</a> contributors"
}).addTo(map);
// add the boatmarker at a startpoint
var boatMarker = L.boatMarker(map.getCenter(), {
color: "#f1c40f"
}).addTo(map);
boatMarker.setHeading(60);
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
var heading = 60;
// start simulation
window.setInterval(function() {
var speed = getRandomArbitrary(8.0, 16.0);
var direction = getRandomArbitrary((heading - 50) % 360, (heading - 40) % 360);
if(heading > 30)
heading -= 0.5;
boatMarker.setHeadingWind(heading, speed, direction);
var destination = turf.destination(boatMarker.toGeoJSON(), 0.02, 60, "kilometers");
boatMarker.setLatLng(destination.geometry.coordinates.reverse());
}, 488);
</script>
</body>
</html>