Advertisement
Guest User

acarsmap.js

a guest
Jun 12th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. /**
  2. * phpVMS - Virtual Airline Administration Software
  3. * Copyright (c) 2008 Nabeel Shahzad
  4. * For more information, visit www.phpvms.net
  5. * Forums: http://www.phpvms.net/forum
  6. * Documentation: http://www.phpvms.net/docs
  7. *
  8. * phpVMS is licenced under the following license:
  9. * Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
  10. * View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
  11. *
  12. * @author Nabeel Shahzad
  13. * @copyright Copyright (c) 2008, Nabeel Shahzad
  14. * @link http://www.phpvms.net
  15. * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
  16. *
  17. * Rewritten for Google Maps v3
  18. */
  19.  
  20. var flightMarkers = [];
  21. var routeMarkers = [];
  22. var flightPath = null;
  23. var depMarker = null, arrMarker = null;
  24. var info_window= null;
  25. var run_once = false;
  26.  
  27. var defaultOptions = {
  28. autozoom: true,
  29. zoom: 4,
  30. center: new google.maps.LatLng(-25.363882,131.044922),
  31. mapTypeId: google.maps.MapTypeId.TERRAIN,
  32. refreshTime: 12000,
  33. autorefresh: true
  34. };
  35.  
  36. var options = $.extend({}, defaultOptions, acars_map_defaults);
  37. var map = new google.maps.Map(document.getElementById("acarsmap"), options);
  38.  
  39. // They clicked the map
  40. google.maps.event.addListener(map, 'click', function()
  41. {
  42. //clearPreviousMarkers();
  43. });
  44.  
  45. liveRefresh();
  46. if(options.autorefresh == true)
  47. {
  48. setInterval(function () { liveRefresh(); }, options.refreshTime);
  49. }
  50.  
  51. function liveRefresh()
  52. {
  53. $.ajax({
  54. type: "GET",
  55. url: url + "/action.php/acars/data",
  56. dataType: "json",
  57. cache: false,
  58. success: function(data)
  59. {
  60. populateMap(data);
  61. }
  62. });
  63. };
  64.  
  65. function populateMap(data)
  66. {
  67. clearMap();
  68. $("#pilotlist").html("");
  69.  
  70. if (data.length == 0) {
  71. return false;
  72. }
  73.  
  74. var lat, lng;
  75. var details, row, pilotlink;
  76. var bounds = new google.maps.LatLngBounds();
  77.  
  78. for (var i = 0; i < data.length; i++)
  79. {
  80. if(data[i] == null || data[i].lat == null || data[i].lng == null
  81. || data[i].lat == "" || data[i].lng == "")
  82. {
  83. continue;
  84. }
  85.  
  86. lat = data[i].lat;
  87. lng = data[i].lng;
  88.  
  89. if(i%2 == 0)
  90. data[i].trclass = "even";
  91. else
  92. data[i].trclass = "odd";
  93.  
  94. // Pull ze templates!
  95. var map_row = tmpl("acars_map_row", {flight: data[i]});
  96. var detailed_bubble = tmpl("acars_map_bubble", {flight: data[i]});
  97.  
  98. $('#pilotlist').append(map_row);
  99.  
  100. var pos = new google.maps.LatLng(lat, lng);
  101. flightMarkers[flightMarkers.length] = new google.maps.Marker({
  102. position: pos,
  103. map: map,
  104. icon: url+"/lib/images/inair/"+data[i].heading+".png",
  105. flightdetails: data[i],
  106. infowindow_content: detailed_bubble
  107. });
  108.  
  109. bounds.extend(pos);
  110.  
  111. google.maps.event.addListener(flightMarkers[flightMarkers.length - 1], 'click', function()
  112. {
  113. clearPreviousMarkers();
  114.  
  115. var focus_bounds = new google.maps.LatLngBounds();
  116. // Flight details info window
  117. info_window = new google.maps.InfoWindow({
  118. content: this.infowindow_content,
  119. position: this.position
  120. });
  121.  
  122. info_window.open(map, this);
  123.  
  124. // Add polyline, and start/end points
  125. var dep_location = new google.maps.LatLng(this.flightdetails.deplat, this.flightdetails.deplng);
  126. var arr_location = new google.maps.LatLng(this.flightdetails.arrlat, this.flightdetails.arrlng);
  127.  
  128. depMarker = new google.maps.Marker({
  129. position: dep_location,
  130. map: map,
  131. icon: depicon,
  132. title: this.flightdetails.depname,
  133. zIndex: 100
  134. });
  135.  
  136. arrMarker = new google.maps.Marker({
  137. position: arr_location,
  138. map: map,
  139. icon: arricon,
  140. title: this.flightdetails.arrname,
  141. zIndex: 100
  142. });
  143.  
  144. // Now the flight path, if it exists
  145. var path = new Array();
  146. path[path.length] = dep_location;
  147. focus_bounds.extend(dep_location);
  148. if(this.flightdetails.route_details.length > 0)
  149. {
  150. $.each(this.flightdetails.route_details, function(i, nav)
  151. {
  152. var loc = new google.maps.LatLng(nav.lat, nav.lng);
  153.  
  154. if(nav.type == 3)
  155. icon = "icon_vor.png";
  156. else
  157. icon = "icon_fix.png";
  158.  
  159. var navpoint_info = tmpl("navpoint_bubble", {nav: nav});
  160. routeMarkers[routeMarkers.length] = new google.maps.Marker({
  161. position: loc,
  162. map: map,
  163. icon: url + "/lib/images/"+icon,
  164. title: nav.title,
  165. zIndex: 100,
  166. infowindow_content: navpoint_info
  167. });
  168.  
  169. google.maps.event.addListener(routeMarkers[routeMarkers.length - 1], 'click', function()
  170. {
  171. info_window = new google.maps.InfoWindow({
  172. content: this.infowindow_content,
  173. position: this.position
  174. });
  175.  
  176. info_window.open(map, this);
  177. });
  178.  
  179. path[path.length] = loc;
  180. focus_bounds.extend(loc);
  181. });
  182. }
  183.  
  184. path[path.length] = arr_location;
  185. focus_bounds.extend(this.position);
  186. focus_bounds.extend(arr_location);
  187.  
  188. flightPath = new google.maps.Polyline({
  189. path: path,
  190. strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2
  191. });
  192.  
  193. map.fitBounds(focus_bounds);
  194. flightPath.setMap(map);
  195. });
  196. }
  197.  
  198. // If they selected autozoom, only do the zoom first time
  199. if(options.autozoom == true && run_once == false)
  200. {
  201. map.fitBounds(bounds);
  202. run_once = true;
  203. }
  204. }
  205.  
  206. function clearPreviousMarkers()
  207. {
  208. if(info_window)
  209. {
  210. info_window.close();
  211. info_window = null;
  212. }
  213.  
  214. if(depMarker != null)
  215. {
  216. depMarker.setMap(null);
  217. depMarker = null;
  218. }
  219.  
  220. if(arrMarker != null)
  221. {
  222. arrMarker.setMap(null);
  223. arrMarker = null;
  224. }
  225.  
  226. if(routeMarkers.length > 0)
  227. {
  228. for(var i = 0; i < routeMarkers.length; i++) {
  229. routeMarkers[i].setMap(null);
  230. }
  231. }
  232.  
  233. routeMarkers.length = 0;
  234.  
  235. if(flightPath != null)
  236. {
  237. flightPath.setMap(null);
  238. flightPath = null;
  239. }
  240. }
  241.  
  242. function clearMap()
  243. {
  244. if(flightMarkers.length > 0)
  245. {
  246. for(var i = 0; i < flightMarkers.length; i++) {
  247. flightMarkers[i].setMap(null);
  248. }
  249. }
  250.  
  251. flightMarkers.length = 0;
  252.  
  253. if(routeMarkers.length > 0)
  254. {
  255. for(var i = 0; i < routeMarkers.length; i++) {
  256. routeMarkers[i].setMap(null);
  257. }
  258. }
  259.  
  260. routeMarkers.length = 0;
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement