-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadMap.js
129 lines (105 loc) · 2.96 KB
/
loadMap.js
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
var infowindow;
var map;
jQuery(document).ready(loadSelectBox);
function loadSelectBox(){
var element = document.getElementById('TripSelectBox');
if (typeof(element) == 'undefined' || element == null)
{
// does not exist. get the id from the URL and send it to load map.
var urlTripId = getUrlVars()["id"];
if(urlTripId == 'undefined' || urlTripId == 'null'){
urlTripId = -1;
}
loadMap(urlTripId);
return;
}
jQuery.ajax("http://pleskac.org:8080/api/trip/list").done(
function(data){
tripList = JSON.parse(data);
jQuery.each(tripList, function(){
var id = this.TripId;
var name = this.TripName;
var current = this.IsCurrent;
if(current == 0){
jQuery("#TripSelectBox").append("<option value='" + id + "'>" + name + "</option>");
}else{
jQuery("#TripSelectBox").append("<option value='" + id + "'>(Current) " + name + "</option>");
}
});
jQuery("#TripSelectBox").ready(changeMap);
}
);
jQuery("#TripSelectBox").change(changeMap);
}
function changeMap(){
var id = jQuery("#TripSelectBox").val();
loadMap(id);
}
function loadMap(loadId){
infowindow = new google.maps.InfoWindow();
var apiUrl = ""
if(loadId == -1){
apiUrl = "http://pleskac.org:8080/api/trip/currentTrip";
}else{
apiUrl = "http://pleskac.org:8080/api/trip/id/" + loadId;
}
jQuery.ajax(apiUrl).done(
function(data){
trips = JSON.parse(data);
var flightPlanCoordinates = [];
if(trips.Coordinates != null){
jQuery.each(trips.Coordinates, function(){
flightPlanCoordinates.push(new google.maps.LatLng(this.Latitude, this.Longitude));
});
}
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(0, 0),
mapTypeId: google.maps.MapTypeId.TERRAIN,
streetViewControl: false,
scrollwheel: false
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var bounds = new google.maps.LatLngBounds();
if(trips.Coordinates != null){
jQuery.each(trips.Coordinates, function(){
var position = new google.maps.LatLng(this.Latitude, this.Longitude);
createMarker(position, this.Details, this.Color);
bounds.extend(position);
});
}
map.fitBounds(bounds);
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "Black",
strokeOpacity: 1.0,
strokeWeight: 1.2
});
flightPath.setMap(map);
}
);
}
function createMarker(_position, name, color) {
var marker = new google.maps.Marker({
icon: { path: google.maps.SymbolPath.CIRCLE,
scale: 5,
fillColor: color,
fillOpacity: 1,
strokeWeight: 1
},
position: _position,
map: map,
title: this.Title
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(name);
infowindow.open(map, this);
});
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}