Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.21 KB | None | 0 0
  1. <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
  2. <script>
  3.  
  4. var locations = []; //Array contains all locations of current date of all busses
  5. var buses = []; // array contains all buses details
  6. var iconlink = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|"; // this link generate random color giving color code at end
  7. var bouncingMarkers = []; // this array set the markers which should bounce (ie the last position of bus)
  8. var dateLastUpdate; // This value set date which map last updated
  9. var icons = []; // contains all icons color .
  10. var busRoutesArray = [];
  11. var busSelected = '';
  12. var previousStop = '';
  13. var nextStop = '';
  14. var busLatitude = '';
  15. var busLongitude = '';
  16.  
  17. var markers = [];
  18. var polyLines = [];
  19.  
  20. var map;
  21. var myLatLng;
  22.  
  23.  
  24. for(var i=0;i<100;i++){
  25. icons.push(iconlink+getRandomColor()); //creating random icon list
  26. }
  27.  
  28. // this function generate random colors using above url
  29. function getRandomColor() {
  30. var letters = '0123456789ABCDEF';
  31. var color = '';
  32. for (var i = 0; i < 6; i++ ) {
  33. color += letters[Math.floor(Math.random() * 16)];
  34. }
  35. return color;
  36. }
  37.  
  38. $(document).ready(function() {
  39.  
  40. <%for (int i = 0; i < gpsData.size(); i++) {%>
  41. var gpsDataObject = {};
  42. gpsDataObject["busId"]= '<%=gpsData.get(i).getBusId()%>';
  43. gpsDataObject["lat"]= '<%=gpsData.get(i).getLatitude()%>';
  44. gpsDataObject["lng"]= '<%=gpsData.get(i).getLongitude()%>';
  45. gpsDataObject["date"]= '<%=gpsData.get(i).getDate()%>';
  46. locations.push(gpsDataObject);
  47. <%}%>
  48.  
  49. <%for (int i = 0; i < busRoutes.size(); i++) {%>
  50. var busRoutesObject = {};
  51. busRoutesObject["busId"]= '<%=busRoutes.get(i).getBusId()%>';
  52.  
  53. <%-- busRoutesObject["busName"]= '<%=busRoutes.get(i).getBus().getBusName()%>';
  54.  
  55. busRoutesObject["schoolName"]= '<%=busRoutes.get(i).getBus().getSchoolName()%>'; --%>
  56. busRoutesObject["id"]= '<%=busRoutes.get(i).getId()%>';
  57. busRoutesObject["placeId"]= '<%=busRoutes.get(i).getPlaceId()%>';
  58. busRoutesObject["lat"]= '<%=busRoutes.get(i).getLatitude()%>';
  59. busRoutesObject["lng"]= '<%=busRoutes.get(i).getLongitude()%>';
  60. busRoutesObject["date"]= '<%=busRoutes.get(i).getDate()%>';
  61. busRoutesObject["bustop"]= '<%=busRoutes.get(i).getPlaceWeight()%>';
  62.  
  63. busRoutesArray.push(busRoutesObject);
  64. <%}%>
  65.  
  66. dateLastUpdate = <%=date%>;
  67.  
  68. busRoutesArray.sort(function(a, b) {
  69. if(parseFloat(a.busId) == parseFloat(b.busId)){
  70. return parseFloat(a.bustop) - parseFloat(b.bustop);
  71. }else{
  72. return parseFloat(a.busId) - parseFloat(b.busId);
  73. }
  74.  
  75. });
  76.  
  77. <%for (int i = 0; i < busList.size(); i++) {%>
  78. var busesObject = {};
  79. busesObject["bus"]= '<%=busList.get(i).getBusName()%>';
  80. busesObject["school"]= '<%=busList.get(i).getSchoolName()%>';
  81. busesObject["id"]= '<%=busList.get(i).getId()%>';
  82. busesObject["previousStop"]= '<%=busList.get(i).getPreviousStop()%>';
  83. busesObject["nextStop"]= '<%=busList.get(i).getNextStop()%>';
  84. busesObject["latitude"]= '<%=busList.get(i).getLatitude()%>';
  85. busesObject["longitude"]= '<%=busList.get(i).getLongitude()%>';
  86. buses.push(busesObject);
  87. <%}%>
  88.  
  89. for (var i = 0; i < buses.length; i++) {
  90. $("#info").append(
  91. '<div id="bodyContent">'
  92. + '<p><img src="'
  93. + icons[i % 100]
  94. + '"></img><b>Bus:</b>'
  95. + buses[i].bus + '</p>' +
  96. /* '<p><img src="'+icons[i%5]+'"></img><b>Bus:</b>'+buses[i].bus+', <b>School:</b>'+buses[i].school+'</p>'+
  97. */'</div>' + '</div>');
  98. }
  99.  
  100.  
  101. if(buses.length>0){
  102. busSelected = buses[0].id;
  103. previousStop = buses[0].previousStop;
  104. nextStop = buses[0].previousStop;
  105. busLatitude = buses[0].latitude;
  106. busLongitude = buses[0].longitude;
  107. if(previousStop == "" && buses.length>0){
  108. for(var j=0;j<busRoutesArray.length;j++){
  109. if(busRoutesArray[j].busId.trim() == buses[0].id.trim() ) {
  110. previousStop = busRoutesArray[j].id;
  111. nextStop = busRoutesArray[j].id;
  112. busLatitude = busRoutesArray[j].lat;
  113. busLongitude = busRoutesArray[j].lng;
  114. break;
  115. }
  116. }
  117. }
  118.  
  119. $( "#busId" ).val(busSelected);
  120. }
  121.  
  122. $( "#busId" ).change(function() {
  123. busSelected = $(this).val();
  124. for(var i=0;i<buses.length;i++){
  125. if(buses[i].id.trim() == busSelected.trim()){
  126. previousStop = buses[i].previousStop;
  127. nextStop = buses[i].previousStop;
  128. busLatitude = buses[i].latitude;
  129. busLongitude = buses[i].longitude;
  130. if(previousStop == "" && buses.length>0){
  131. for(var j=0;j<busRoutesArray.length;j++){
  132. if(busRoutesArray[j].busId.trim() == buses[i].id.trim() ) {
  133. previousStop = busRoutesArray[j].id;
  134. nextStop = busRoutesArray[j].id;
  135. busLatitude = busRoutesArray[j].lat;
  136. busLongitude = busRoutesArray[j].lng;
  137. break;
  138. }
  139. }
  140.  
  141. }
  142. }
  143. }
  144.  
  145. initMap();
  146. });
  147.  
  148. });
  149.  
  150.  
  151. // Sets the map on all markers in the array.
  152. function setMapOnAll(map) {
  153. for (var i = 0; i < markers.length; i++) {
  154. markers[i].setMap(map);
  155. }
  156. for (var i = 0; i < polyLines.length; i++) {
  157. polyLines[i].setMap(map);
  158. }
  159. }
  160.  
  161.  
  162.  
  163. //set icons based on each bus
  164. function getIcon(busId) {
  165. for (var i = 0; i < buses.length; i++) {
  166. if (buses[i].id.trim() == busId.trim()) {
  167. return icons[i % 100];
  168. }
  169. }
  170. }
  171.  
  172. /* function getMarkerInfo(busId) {
  173. for (var i = 0; i < buses.length; i++) {
  174. if (buses[i].id.trim() == busId.trim()) {
  175. return '<div id="content">' + '<div id="siteNotice">'
  176. + '</div>'
  177. + '<h1 id="firstHeading" class="firstHeading">'
  178. + buses[i].bus + '</h1>' +
  179.  
  180. '</div>';
  181. ;
  182. }
  183. }
  184. } */
  185.  
  186. function getMarkerInfo(message) {
  187. return '<div id="content">' + '<div id="siteNotice">'
  188. + '</div>'
  189. + '<h4 id="firstHeading" class="firstHeading">'
  190. + message+ '</h4>' +
  191. /* '<div id="bodyContent">'+
  192. '<p><b>School:'+buses[i].school+'</b></p>'+
  193. '</div>'+ */
  194. '</div>';
  195. ;
  196. }
  197.  
  198.  
  199. //initiallizea and set all markers and info on map
  200. function reLoadMarekers() {
  201.  
  202. setMapOnAll(null);
  203.  
  204. var infowindow = new google.maps.InfoWindow();
  205.  
  206. var marker, i;
  207.  
  208. var bounds = new google.maps.LatLngBounds();
  209.  
  210. var isPreviousLocationPassed = false;
  211. var isNextLocationPassed = false;
  212. var isFirst = true;
  213.  
  214. for (i = 0; i < busRoutesArray.length; i++) {
  215. if (busRoutesArray[i].busId.trim() == busSelected.trim()) {
  216. marker = new google.maps.Marker({
  217. position : new google.maps.LatLng(parseFloat(busRoutesArray[i].lat),
  218. parseFloat(busRoutesArray[i].lng)),
  219. map : map,
  220. });
  221. markers.push(marker);
  222.  
  223. if(isFirst){
  224. marker.setLabel("Start");
  225. isFirst = false;
  226. }
  227. markers.push(marker);
  228.  
  229. bounds.extend(marker.getPosition());
  230.  
  231. google.maps.event
  232. .addListener(
  233. marker,
  234. 'click',
  235. (function(marker, i) {
  236. return function() {
  237. infowindow
  238. .setContent(getMarkerInfo(busRoutesArray[i].placeId));
  239. infowindow.open(map, marker);
  240. }
  241. })(marker, i));
  242.  
  243.  
  244. var polyLineCoordinates = [];
  245.  
  246.  
  247. if (previousStop.trim() == busRoutesArray[i].id.trim()) {
  248.  
  249. var markerImage = new google.maps.MarkerImage(
  250. "/img/greendot.png",
  251. null, /* size is determined at runtime */
  252. null, /* origin is 0,0 */
  253. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  254. new google.maps.Size(25, 25)
  255. );
  256.  
  257. marker.setIcon(markerImage);
  258.  
  259. if((i < (busRoutesArray.length-1)) && (busRoutesArray[i].busId.trim() == busRoutesArray[i+1].busId.trim() )){
  260.  
  261. var polyLineCoordinatesOBject ={};
  262. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i].lat);
  263. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i].lng);
  264. polyLineCoordinates.push(polyLineCoordinatesOBject);
  265. polyLineCoordinatesOBject ={};
  266. polyLineCoordinatesOBject['lat'] = parseFloat(busLatitude);
  267. polyLineCoordinatesOBject['lng'] = parseFloat(busLongitude);
  268. polyLineCoordinates.push(polyLineCoordinatesOBject);
  269.  
  270.  
  271. var ployLine = new google.maps.Polyline({
  272. path : polyLineCoordinates,
  273. geodesic : true,
  274. strokeColor : '#11891A',
  275. strokeOpacity : 1.0,
  276. strokeWeight : 2,
  277. map: map
  278. });
  279. polyLines.push(ployLine);
  280.  
  281. marker = new google.maps.Marker({
  282. position : new google.maps.LatLng(parseFloat(busLatitude),
  283. parseFloat(busLongitude)),
  284. map : map,
  285. });
  286. markers.push(marker);
  287.  
  288.  
  289. google.maps.event
  290. .addListener(
  291. marker,
  292. 'click',
  293. (function(marker, i) {
  294. return function() {
  295. infowindow
  296. .setContent(getMarkerInfo(busRoutesArray[i].placeId));
  297. infowindow.open(map, marker);
  298. }
  299. })(marker, i));
  300.  
  301. var markerImage = new google.maps.MarkerImage(
  302. "/img/bluedot.png",
  303. null, /* size is determined at runtime */
  304. null, /* origin is 0,0 */
  305. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  306. new google.maps.Size(25, 25)
  307. );
  308.  
  309. marker.setIcon(markerImage);
  310.  
  311. var polyLineCoordinates = [];
  312.  
  313. var polyLineCoordinatesOBject ={};
  314. polyLineCoordinatesOBject['lat'] = parseFloat(busLatitude);
  315. polyLineCoordinatesOBject['lng'] = parseFloat(busLongitude);
  316. polyLineCoordinates.push(polyLineCoordinatesOBject);
  317. polyLineCoordinatesOBject ={};
  318. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i+1].lat);
  319. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i+1].lng);
  320. polyLineCoordinates.push(polyLineCoordinatesOBject);
  321.  
  322.  
  323. var ployLine2 = new google.maps.Polyline({
  324. path : polyLineCoordinates,
  325. geodesic : true,
  326. strokeColor : '#C56E00',
  327. strokeOpacity : 1.0,
  328. strokeWeight : 2,
  329. map: map
  330. });
  331.  
  332. }
  333. polyLines.push(ployLine2);
  334.  
  335. isNextLocationPassed = true;
  336.  
  337. } else if(isNextLocationPassed && isNextLocationPassed){
  338.  
  339. var markerImage = new google.maps.MarkerImage(
  340. "/img/orangedot.png",
  341. null, /* size is determined at runtime */
  342. null, /* origin is 0,0 */
  343. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  344. new google.maps.Size(25, 25)
  345. );
  346.  
  347. marker.setIcon(markerImage);
  348.  
  349. if((i < (busRoutesArray.length-1)) && (busRoutesArray[i].busId.trim() == busRoutesArray[i+1].busId.trim() )){
  350.  
  351. var polyLineCoordinatesOBject ={};
  352. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i].lat);
  353. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i].lng);
  354. polyLineCoordinates.push(polyLineCoordinatesOBject);
  355. polyLineCoordinatesOBject ={};
  356. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i+1].lat);
  357. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i+1].lng);
  358. polyLineCoordinates.push(polyLineCoordinatesOBject);
  359.  
  360.  
  361. var ployLine = new google.maps.Polyline({
  362. path : polyLineCoordinates,
  363. geodesic : true,
  364. strokeColor : '#C56E00',
  365. strokeOpacity : 1.0,
  366. strokeWeight : 2,
  367. map: map
  368. });
  369. polyLines.push(ployLine);
  370.  
  371. }
  372.  
  373. }else {
  374.  
  375. var markerImage = new google.maps.MarkerImage(
  376. "/img/greendot.png",
  377. null, /* size is determined at runtime */
  378. null, /* origin is 0,0 */
  379. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  380. new google.maps.Size(25, 25)
  381. );
  382.  
  383. marker.setIcon(markerImage);
  384.  
  385. if((i < (busRoutesArray.length-1)) && (busRoutesArray[i].busId.trim() == busRoutesArray[i+1].busId.trim() )){
  386.  
  387. var polyLineCoordinatesOBject ={};
  388. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i].lat);
  389. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i].lng);
  390. polyLineCoordinates.push(polyLineCoordinatesOBject);
  391. polyLineCoordinatesOBject ={};
  392. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i+1].lat);
  393. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i+1].lng);
  394. polyLineCoordinates.push(polyLineCoordinatesOBject);
  395.  
  396.  
  397.  
  398. var ployLine = new google.maps.Polyline({
  399. path : polyLineCoordinates,
  400. geodesic : true,
  401. strokeColor : '#11891A',
  402. strokeOpacity : 1.0,
  403. strokeWeight : 2,
  404. map: map
  405. });
  406. polyLines.push(ployLine);
  407. }
  408. }
  409.  
  410. }
  411. }
  412.  
  413. if(marker != null){
  414. marker.setLabel("Stop");
  415. }
  416. }
  417.  
  418.  
  419.  
  420.  
  421. //initiallizea and set all markers and info on map
  422. function initMap() {
  423.  
  424. myLatLng = {
  425. lat : parseFloat(9.9),
  426. lng : parseFloat(76)
  427. };
  428.  
  429. if (busRoutesArray != null && busRoutesArray.length > 0) {
  430. var myLatLng = {
  431. lat : parseFloat(busRoutesArray[0].lat),
  432. lng : parseFloat(busRoutesArray[0].lng)
  433. };
  434. } else {
  435. alert("None of buses started from location");
  436. }
  437. map = new google.maps.Map(document.getElementById("map"), {
  438. zoom : 15,
  439. center : myLatLng
  440. });
  441.  
  442. var infowindow = new google.maps.InfoWindow();
  443.  
  444. var marker, i;
  445.  
  446. var bounds = new google.maps.LatLngBounds();
  447.  
  448. var isPreviousLocationPassed = false;
  449. var isNextLocationPassed = false;
  450.  
  451. var isFirst = true;
  452.  
  453. for (i = 0; i < busRoutesArray.length; i++) {
  454. if (busRoutesArray[i].busId.trim() == busSelected.trim()) {
  455. marker = new google.maps.Marker({
  456. position : new google.maps.LatLng(parseFloat(busRoutesArray[i].lat),
  457. parseFloat(busRoutesArray[i].lng)),
  458. map : map,
  459. });
  460. if(isFirst){
  461. marker.setLabel("Start");
  462. isFirst = false;
  463. }
  464. markers.push(marker);
  465.  
  466.  
  467. bounds.extend(marker.getPosition());
  468.  
  469. google.maps.event
  470. .addListener(
  471. marker,
  472. 'click',
  473. (function(marker, i) {
  474. return function() {
  475. infowindow
  476. .setContent(getMarkerInfo(busRoutesArray[i].placeId));
  477. infowindow.open(map, marker);
  478. }
  479. })(marker, i));
  480.  
  481. var polyLineCoordinates = [];
  482.  
  483. if (previousStop.trim() == busRoutesArray[i].id.trim()) {
  484.  
  485. var markerImage = new google.maps.MarkerImage(
  486. "/img/greendot.png",
  487. null, /* size is determined at runtime */
  488. null, /* origin is 0,0 */
  489. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  490. new google.maps.Size(25, 25)
  491. );
  492.  
  493. marker.setIcon(markerImage);
  494.  
  495. if((i < (busRoutesArray.length-1)) && (busRoutesArray[i].busId.trim() == busRoutesArray[i+1].busId.trim() )){
  496.  
  497. var polyLineCoordinatesOBject ={};
  498. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i].lat);
  499. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i].lng);
  500. polyLineCoordinates.push(polyLineCoordinatesOBject);
  501. polyLineCoordinatesOBject ={};
  502. polyLineCoordinatesOBject['lat'] = parseFloat(busLatitude);
  503. polyLineCoordinatesOBject['lng'] = parseFloat(busLongitude);
  504. polyLineCoordinates.push(polyLineCoordinatesOBject);
  505.  
  506.  
  507. var ployLine = new google.maps.Polyline({
  508. path : polyLineCoordinates,
  509. geodesic : true,
  510. strokeColor : '#11891A',
  511. strokeOpacity : 1.0,
  512. strokeWeight : 2,
  513. map: map
  514. });
  515. polyLines.push(ployLine);
  516.  
  517. marker = new google.maps.Marker({
  518. position : new google.maps.LatLng(parseFloat(busLatitude),
  519. parseFloat(busLongitude)),
  520. map : map,
  521. });
  522. markers.push(marker);
  523.  
  524.  
  525. google.maps.event
  526. .addListener(
  527. marker,
  528. 'click',
  529. (function(marker, i) {
  530. return function() {
  531. infowindow
  532. .setContent(getMarkerInfo(busRoutesArray[i].placeId));
  533. infowindow.open(map, marker);
  534. }
  535. })(marker, i));
  536.  
  537. var markerImage = new google.maps.MarkerImage(
  538. "/img/bluedot.png",
  539. null, /* size is determined at runtime */
  540. null, /* origin is 0,0 */
  541. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  542. new google.maps.Size(25, 25)
  543. );
  544.  
  545. marker.setIcon(markerImage);
  546.  
  547. var polyLineCoordinates = [];
  548.  
  549. var polyLineCoordinatesOBject ={};
  550. polyLineCoordinatesOBject['lat'] = parseFloat(busLatitude);
  551. polyLineCoordinatesOBject['lng'] = parseFloat(busLongitude);
  552. polyLineCoordinates.push(polyLineCoordinatesOBject);
  553. polyLineCoordinatesOBject ={};
  554. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i+1].lat);
  555. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i+1].lng);
  556. polyLineCoordinates.push(polyLineCoordinatesOBject);
  557.  
  558.  
  559. var ployLine2 = new google.maps.Polyline({
  560. path : polyLineCoordinates,
  561. geodesic : true,
  562. strokeColor : '#C56E00',
  563. strokeOpacity : 1.0,
  564. strokeWeight : 2,
  565. map: map
  566. });
  567. polyLines.push(ployLine2);
  568.  
  569. }
  570. isNextLocationPassed = true;
  571.  
  572. } else if(isNextLocationPassed && isNextLocationPassed){
  573.  
  574. var markerImage = new google.maps.MarkerImage(
  575. "/img/orangedot.png",
  576. null, /* size is determined at runtime */
  577. null, /* origin is 0,0 */
  578. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  579. new google.maps.Size(25, 25)
  580. );
  581.  
  582. marker.setIcon(markerImage);
  583.  
  584. if((i < (busRoutesArray.length-1)) && (busRoutesArray[i].busId.trim() == busRoutesArray[i+1].busId.trim() )){
  585.  
  586. var polyLineCoordinatesOBject ={};
  587. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i].lat);
  588. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i].lng);
  589. polyLineCoordinates.push(polyLineCoordinatesOBject);
  590. polyLineCoordinatesOBject ={};
  591. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i+1].lat);
  592. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i+1].lng);
  593. polyLineCoordinates.push(polyLineCoordinatesOBject);
  594.  
  595.  
  596. var ployLine = new google.maps.Polyline({
  597. path : polyLineCoordinates,
  598. geodesic : true,
  599. strokeColor : '#C56E00',
  600. strokeOpacity : 1.0,
  601. strokeWeight : 2,
  602. map: map
  603. });
  604. polyLines.push(ployLine);
  605.  
  606. }
  607.  
  608. }else {
  609.  
  610. var markerImage = new google.maps.MarkerImage(
  611. "/img/greendot.png",
  612. null, /* size is determined at runtime */
  613. null, /* origin is 0,0 */
  614. new google.maps.Point(12, 12), /* anchor is bottom center of the scaled image */
  615. new google.maps.Size(25, 25)
  616. );
  617.  
  618. marker.setIcon(markerImage);
  619.  
  620. if((i < (busRoutesArray.length-1)) && (busRoutesArray[i].busId.trim() == busRoutesArray[i+1].busId.trim() )){
  621.  
  622. var polyLineCoordinatesOBject ={};
  623. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i].lat);
  624. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i].lng);
  625. polyLineCoordinates.push(polyLineCoordinatesOBject);
  626. polyLineCoordinatesOBject ={};
  627. polyLineCoordinatesOBject['lat'] = parseFloat(busRoutesArray[i+1].lat);
  628. polyLineCoordinatesOBject['lng'] = parseFloat(busRoutesArray[i+1].lng);
  629. polyLineCoordinates.push(polyLineCoordinatesOBject);
  630.  
  631.  
  632.  
  633. var ployLine = new google.maps.Polyline({
  634. path : polyLineCoordinates,
  635. geodesic : true,
  636. strokeColor : '#11891A',
  637. strokeOpacity : 1.0,
  638. strokeWeight : 2,
  639. map: map
  640. });
  641. polyLines.push(ployLine);
  642.  
  643. }
  644. }
  645. }
  646. }
  647. if(marker != null){
  648. marker.setLabel("Stop");
  649. }
  650.  
  651.  
  652. map.fitBounds(bounds);
  653.  
  654. }
  655.  
  656.  
  657.  
  658. // function used to recheck data base every minute to get current location of bus
  659. setInterval(function() {
  660.  
  661. //used to access data base from remote thread
  662. var client = new XMLHttpRequest();
  663. client.onload = handler;
  664. client.open("GET", "getBusPosition.jsp?date=" + dateLastUpdate+"&busId="+busSelected);
  665. client.send();
  666.  
  667.  
  668.  
  669. /* busLatitude = parseFloat(busLatitude) + 1;
  670. busLongitude = parseFloat(busLongitude) + 1;
  671.  
  672. var data = [];
  673. var dataObject = {};
  674. dataObject['previousStop']=previousStop;
  675. dataObject['nextStop']=nextStop;
  676. dataObject['latitude']=busLatitude;
  677. dataObject['longitude']=busLongitude;
  678. data.push(dataObject);*/
  679.  
  680. processData(data)
  681.  
  682. }, 5000);
  683.  
  684. //Some simple code to do something with data from an XML document fetched over the network:
  685.  
  686. function processData(data) {
  687.  
  688. if(data != null && data.length>0 && data[0].previousStop != "" && data[0].nextStop != "" && data[0].latitude != "" && data[0].longitude != ""){
  689.  
  690. previousStop = data[0].previousStop;
  691. nextStop = data[0].nextStop;
  692. busLatitude = data[0].latitude;
  693. busLongitude = data[0].longitude;
  694.  
  695. dateLastUpdate = new Date().getTime();
  696. reLoadMarekers();
  697. }
  698. }
  699.  
  700. // XMLHttpRequest request return the responce to this function
  701. function handler() {
  702. if (this.status == 200 && this.response != null
  703. && this.response != '') {
  704.  
  705. var newJson = this.response.replace(/'/g, '"');
  706.  
  707. newJson = newJson.replace(/([^"]+)|("[^"]+")/g, function($0, $1, $2) {
  708. if ($1) {
  709. return $1.replace(/([a-zA-Z0-9]+?):/g, '"$1":');
  710. } else {
  711. return $2;
  712. }
  713. });
  714.  
  715. var data = JSON.parse(newJson);
  716.  
  717. // success!
  718.  
  719. processData(data);
  720.  
  721. } else {
  722. // something went wrong
  723. }
  724. }
  725. </script>
  726. <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC0ub2MijKbqO9wlDlGWFTb61r9m7zQ8dQ&callback=initMap">
  727.  
  728. </script>
  729. </body>
  730. <!-- /. FOOTER -->
  731. <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
  732. <!-- JQUERY SCRIPTS -->
  733. <script src="js/jquery-1.10.2.js"></script>
  734. <!-- BOOTSTRAP SCRIPTS -->
  735. <script src="js/bootstrap.js"></script>
  736. <!-- METISMENU SCRIPTS -->
  737. <script src="js/jquery.metisMenu.js"></script>
  738. <!-- CUSTOM SCRIPTS -->
  739. <script src="js/custom.js"></script>
  740. <%}else{
  741. response.sendRedirect("index.jsp");
  742.  
  743. }%>
  744. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement