-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.html
173 lines (150 loc) · 7 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#infoWindow {
width: 150px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=drawing"></script>
<script>
var map;
var marker;
var markersArray = {};
var count = 0;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(37.5, -122.2),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
google.maps.event.addListener(map, 'dragend', function() {
self.print_center(map.getCenter().lat(), map.getCenter().lng());
var lat_lng_bounds_ne = map.getBounds().getNorthEast();
var lat_lng_bounds_sw = map.getBounds().getSouthWest();
lat_lng_bounds_ne_lat = lat_lng_bounds_ne.lat();
lat_lng_bounds_ne_lon = lat_lng_bounds_ne.lng();
lat_lng_bounds_sw_lat = lat_lng_bounds_sw.lat();
lat_lng_bounds_sw_lon = lat_lng_bounds_sw.lng();
self.print_bounds(lat_lng_bounds_ne_lat, lat_lng_bounds_ne_lon, lat_lng_bounds_sw_lat, lat_lng_bounds_sw_lon);
self.load_aircrafts_by_bounds(lat_lng_bounds_ne_lat, lat_lng_bounds_ne_lon, lat_lng_bounds_sw_lat, lat_lng_bounds_sw_lon);
});
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
// do something only the first time the map is loaded
var lat_lng_bounds_ne = map.getBounds().getNorthEast();
var lat_lng_bounds_sw = map.getBounds().getSouthWest();
lat_lng_bounds_ne_lat = lat_lng_bounds_ne.lat();
lat_lng_bounds_ne_lon = lat_lng_bounds_ne.lng();
lat_lng_bounds_sw_lat = lat_lng_bounds_sw.lat();
lat_lng_bounds_sw_lon = lat_lng_bounds_sw.lng();
self.load_aircrafts_by_bounds(lat_lng_bounds_ne_lat, lat_lng_bounds_ne_lon, lat_lng_bounds_sw_lat, lat_lng_bounds_sw_lon);
self.loaded_complete();
});
}
function repaint_by_hand(){
google.maps.event.trigger(map, "dragend");
}
function clearOverlays() {
// alert("clearOverlays started");
// alert(Object.keys(markersArray).length);
for (var prop in markersArray) {
if (markersArray.hasOwnProperty(prop)) {
markersArray[prop].setMap(null);
google.maps.event.clearListeners(markersArray[prop], 'click');
delete markersArray[prop];
}
}
google.maps.event.clearListeners(map, 'click');
// alert("clearOverlays finish");
// alert(Object.keys(markersArray).length);
}
function changeMarkerPos(flight_id, lat, lng, track) {
var latlng = new google.maps.LatLng(lat, lng);
markersArray[flight_id].setPosition(latlng);
var my_icon = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 3,
//url: 'plane1.svg',
rotation: track //this is how to rotate the pointer
};
markersArray[flight_id].setIcon(my_icon);
}
function removeMarker(flight_id) {
markersArray[flight_id].setMap(null);
}
function setInfoWindowContent(flight_id, data_label) {
infowindow = markersArray[flight_id]["infowindow"];
data_label = JSON.parse(data_label);
data = '<div id="infoWindow">';
data += "<b>" + "Flight id: " + "</b>" + flight_id + "<br>";
data += "<b>" + "Flight: " + "</b>" + data_label["flight"] + "<br>";
data += "<b>" + "To: " + "</b>" + data_label["to_iata"] + "<br>";
data += data_label["to_city"] + "<br>";
data += "<b>" + "From: " + "</b>" + data_label["from_iata"] + "<br>";
data += data_label["from_city"] + "<br>";
data += "<b>" + "Airline: " + "</b>" + data_label["airline"] + "<br>";
data += "<b>" + "Aircraft: " + "</b>" + data_label["aircraft"] + "<br>";
data += '</div>';
// data = data_label + "<br>" + flight_id;
infowindow.setContentHTML(data);
}
function addMarker(lat, lng, track, data_label, flight_id) {
count ++;
var myLatLng = new google.maps.LatLng(lat, lng);
var my_icon = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 3,
//url: 'plane1.svg',
//scale: 0.1
rotation: track //this is how to rotate the pointer
};
var marker = new google.maps.Marker({
position: myLatLng,
icon: my_icon,
draggable: false,
map: map
});
// Setting InfoWindow for marker
data_label = JSON.parse(data_label);
data = '<div id="infoWindow">';
data += "<b>" + "Flight id: " + "</b>" + flight_id + "<br>";
data += "<b>" + "Flight: " + "</b>" + data_label["flight"] + "<br>";
data += "<b>" + "To: " + "</b>" + data_label["to_iata"] + "<br>";
data += data_label["to_city"] + "<br>";
data += "<b>" + "From: " + "</b>" + data_label["from_iata"] + "<br>";
data += data_label["from_city"] + "<br>";
data += "<b>" + "Airline: " + "</b>" + data_label["airline"] + "<br>";
data += "<b>" + "Aircraft: " + "</b>" + data_label["aircraft"] + "<br>";
data += '</div>';
var infowindow = new google.maps.InfoWindow({
content: data
});
// marker["infowindow"] = infowindow;
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
markersArray[flight_id] = marker;
}
function show_marker_by_flight_id(flight_id){
// We have to wait until mult. thread downloader of the planes done his work. Otherwise we have got nothing in markersArray
// Of course it might be done more wisely. We have to triger it after all downdloading comleted
// But for now just wait one second and hope that it is downloaded
setTimeout (function() {google.maps.event.trigger(markersArray[flight_id], "click")}, 1000);
}
google.maps.event.addDomListener(window, 'load', initialize);
//google.maps.event.addDomListener(window, 'idle', hey());
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>