-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps.html
More file actions
223 lines (183 loc) · 6.84 KB
/
maps.html
File metadata and controls
223 lines (183 loc) · 6.84 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
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
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0;
padding: 0
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?language=en&region=IT&key=AIzaSyDgUNMSglhkTLRC4jsxmOURa_3lNisIoPg"></script>
<script>
function Client(id, name) {
this.id = id;
this.name = name;
this.marker = undefined;
}
var DEFAULT_POSITION = new google.maps.LatLng(39.44510959999999, 9.540954499999998);
var map = undefined;
var clients = {};
var infoWindow = new google.maps.InfoWindow({
content: ""
});
var markerHab = undefined;
var markerLocal = undefined;
var forceBounds = false;
var mapOptions = {
zoom: 13,
maxZoom: 19,
center: DEFAULT_POSITION,
panControl: true,
zoomControl: true,
scaleControl: true,
rotateControl: true,
mapTypeControl: true,
streetViewControl: false,
overviewMapControl: true,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
function setAutoBounds(status) {
forceBounds = status;
if (status) {
updateBounds();
}
}
function updateBounds() {
if (!forceBounds) {
console.log("Auto Bounds disabled");
return;
}
var bounds = new google.maps.LatLngBounds();
var useDefault = true;
if (markerHab != undefined) {
console.log("HAB Marker");
bounds.extend(markerHab.getPosition());
useDefault = false;
}
if (markerLocal != undefined) {
console.log("Local marker");
bounds.extend(markerLocal.getPosition());
useDefault = false;
}
for (var key in clients) {
if (clients.hasOwnProperty(key)) {
var client = clients[key];
console.log(client);
if (client == undefined || client.marker == undefined) {
continue;
}
bounds.extend(client.marker.position);
useDefault = false;
console.log("Remote client " + client.id);
}
}
if (useDefault) {
console.log("Using default");
bounds.extend(DEFAULT_POSITION);
}
map.fitBounds(bounds);
}
function updateHab(lat, lon) {
var position = new google.maps.LatLng(lat, lon);
if (markerHab == undefined) {
markerHab = new google.maps.Marker({
position: position,
map: map,
icon: "https://maps.google.com/mapfiles/kml/paddle/red-circle.png",
title: "HAB"
});
google.maps.event.addListener(markerHab, "click", function () {
infoWindow.setContent(markerHab.title);
infoWindow.open(map, markerHab);
});
}
markerHab.setPosition(position);
updateBounds();
}
function updateLocal(lat, lon) {
var position = new google.maps.LatLng(lat, lon);
if (markerLocal == undefined) {
markerLocal = new google.maps.Marker({
position: position,
map: map,
icon: "https://maps.google.com/mapfiles/kml/paddle/grn-stars.png",
title: "LOCAL"
});
google.maps.event.addListener(markerLocal, "click", function () {
infoWindow.setContent(markerLocal.title);
infoWindow.open(map, markerLocal);
});
} else {
markerLocal.setPosition(position);
}
updateBounds();
}
function removeHab() {
markerHab.setMap(null);
markerHab = undefined;
updateBounds();
}
function removeLocal() {
markerLocal.setMap(null);
markerLocal = undefined;
updateBounds();
}
function addRemoteClient(id, name) {
console.log("addRemoteClient");
clients[id] = new Client(id, name);
}
function updateRemoteClient(id, latitude, longitude) {
console.log("updateRemoteClient");
if (clients[id] == undefined) {
return;
}
var position = new google.maps.LatLng(latitude, longitude);
if (clients[id].marker == undefined) {
clients[id].marker = new google.maps.Marker({
position: position,
map: map,
icon: "https://maps.google.com/mapfiles/kml/paddle/ylw-stars.png",
title: clients[id].name
});
google.maps.event.addListener(clients[id].marker, "click", function () {
infoWindow.setContent(clients[id].marker.title);
infoWindow.open(map, clients[id].marker);
});
} else {
clients[id].marker.setPosition(position);
}
updateBounds();
}
function removeRemoteClient(id) {
console.log("removeRemoteClient");
clients[id].marker.setMap(null);
clients[id].marker = undefined;
clients[id] = undefined;
}
function removeAllRemoteClients() {
for (var key in clients) {
if (clients.hasOwnProperty(key)) {
if (clients[key] == undefined || clients[key].marker == undefined) {
continue;
}
clients[key].marker.setMap(null);
clients[key].marker = undefined;
clients[key] = undefined;
}
}
}
function initialize() {
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
infoWindow = new google.maps.InfoWindow();
}
google.maps.event.addDomListener(window, "load", initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>