-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractiveMap.html
233 lines (180 loc) · 6.45 KB
/
InteractiveMap.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Map</title>
<link rel="stylesheet" href="stylesmap.css">
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
</head>
<body>
<!-- user buoy creation and info js-->
<script src="userInteraction.js" ></script>
<script src="buoyInfo.js"></script>
<h1>S.A.I.L. SMART AUTONOMOUS INTERACTIVE LOCALIZATION</h1>
<div id="core">
<!-- Map Object -->
<div id="map"></div>
<button id="newBuoy", onClick="insertBuoyData()">Inserisci nuova boa</button>
<div id="buoyInfo" style="display: none;">
<p>BUOY DETAILS</p>
<tr>
<th>BUOY ID</th> <th>LATITUDE</th> <th>LONGITUDE</th>
</tr>
<tr>
<td id="buoyId"></td> <td id="lat"></td> <td id="long"></td>
</tr>
</table>
</div>
</div>
<!-- Leaflet JS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script>
// Inizialize the map ([Long,Lat],zoom)
var map = L.map('map').setView([42.030761, 11.909473],13);
// Add a tile layer
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// Define 3 objects
var circle1 = L.circle([42.021378, 11.931883 ], {
color: 'red',
fillColor: '#red',
radius: 50 // radious of the circle in meters
}).addTo(map);
var circle2 = L.circle([42.028743, 11.866492 ], {
color: 'blue',
fillColor: '#blue',
radius: 50 // radius of the circle in meters
}).addTo(map);
var circle3 = L.circle([ 42.017101, 11.890186], {
color: 'green',
fillColor: '#green',
radius: 50 // radius of the circle in meters
}).addTo(map);
// Define pop up event on object
circle1.on("mouseover", function(e){
var latlng = e.latlng; // get the lat and long of the device
var popup1 = L.popup()
.setLatLng(latlng) // set the Lat and Long of the popup
.setContent('Buoy 1: ' + latlng) // Popup text
.openOn(map);
});
circle1.on("mouseout", function() {
map.closePopup();
});
circle2.on("mouseover", function(e){
var latlng = e.latlng;
var popup2 = L.popup()
.setLatLng(latlng)
.setContent('Buoy 2: ' + latlng)
.openOn(map);
});
circle2.on("mouseout", function() {
map.closePopup();
});
circle3.on("mouseover", function(e){
var latlng = e.latlng;
var popup3 = L.popup()
.setLatLng(latlng)
.setContent('Buoy 3: ' + latlng)
.openOn(map);
});
circle3.on("mouseout", function() {
map.closePopup();
});
circle1.on("click", function(e) {
showBuoyInfo(1, e.latlng);
});
circle2.on("click", function(e) {
showBuoyInfo(2, e.latlng);
});
circle3.on("click", function(e) {
showBuoyInfo(3, e.latlng);
});
var buoyIcon = L.icon({
iconUrl: 'icon/dynamicBuoy.png',
iconSize: [25, 25],
iconAnchor: [0, 0],
popupAnchor: [0, 0],
});
var markerBuoy = L.marker([42.026439, 11.912144], {icon: buoyIcon}).addTo(map);
// add a popup on the marker
markerBuoy.on("mouseover", function(e){
var latlng = e.latlng;
var popup4 = L.popup()
.setLatLng(latlng)
.setContent('StaticBuoy: ' + latlng)
.openOn(map);
});
markerBuoy.on("mouseout", function() {
map.closePopup();
});
// define objects with personalized icon
var myIcon = L.icon({
iconUrl: 'icon/sailingBoat.png',
iconSize: [30, 25],
iconAnchor: [0, 0],
popupAnchor: [0, 0],
});
var marker1 = L.marker([42.035648, 11.882662], {icon: myIcon}).addTo(map);
// add a popup on the marker
marker1.on("mouseover", function(e){
var latlng = e.latlng;
var popup4 = L.popup()
.setLatLng(latlng)
.setContent('SailBoat: ' + latlng)
.openOn(map);
});
marker1.on("mouseout", function() {
map.closePopup();
});
boatSteps = [
[
[42.035648, 11.882662],
[42.035926, 11.883140],
[42.036205, 11.883618],
[42.036483, 11.884096],
[42.036761, 11.884573],
[42.037039, 11.885050],
[42.037317, 11.885526],
[42.037595, 11.886002],
[42.037873, 11.886477],
[42.038150, 11.886952],
[42.038428, 11.887426],
[42.038705, 11.887900],
[42.038982, 11.888374],
[42.039259, 11.888847],
[42.039536, 11.889320],
[42.039813, 11.889792],
[42.040090, 11.890263],
[42.040367, 11.890734],
[42.040644, 11.891204],
[42.035648, 11.882662] // Torna al punto di partenza
]
]
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function moveMarker(marker, newLat, newLong) {
marker.setLatLng([newLat, newLong]);
}
async function animation(marker, position) {
for (let i = 0; i < position.length; i++) {
for (let j = 0; j < position[i].length; j++) {
let currentCoordinate = position[i][j];
console.log(currentCoordinate);
let currentLat = currentCoordinate[0];
let currentLong = currentCoordinate[1];
moveMarker(marker, currentLat, currentLong);
await sleep(2000); // Pausa di 2 secondi tra i movimenti
}
}
}
animation(marker1,boatSteps)
</script>
</body>
</html>