Advertisement
Guest User

acarrsmap.js

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