Guest User

Untitled

a guest
Nov 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. var map;
  2. var infowindow = new google.maps.InfoWindow();
  3.  
  4. function initialization() {
  5. showAllReports();
  6. }
  7.  
  8. function showAllReports() {
  9. $.ajax({
  10. url: 'HttpServlet',
  11. type: 'POST',
  12. data: { "tab_id": "1"},
  13. success: function(reports) {
  14. mapInitialization(reports);
  15. },
  16. error: function(xhr, status, error) {
  17. alert("An AJAX error occured: " + status + "nError: " + error);
  18. }
  19. });
  20. }
  21.  
  22. function mapInitialization(reports) {
  23. var mapOptions = {
  24. mapTypeId : google.maps.MapTypeId.ROADMAP, // Set the type of Map
  25. };
  26.  
  27. // Render the map within the empty div
  28. map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
  29.  
  30. var bounds = new google.maps.LatLngBounds ();
  31.  
  32. $.each(reports, function(i, e) {
  33. var long = Number(e['longitude']);
  34. var lat = Number(e['latitude']);
  35. var latlng = new google.maps.LatLng(lat, long);
  36.  
  37. bounds.extend(latlng);
  38.  
  39. // Create the infoWindow content
  40. var contentStr = '<h4>Report Details</h4><hr>';
  41. contentStr += '<p><b>' + 'Disaster' + ':</b>&nbsp' + e['disaster'] + '</p>';
  42. contentStr += '<p><b>' + 'Report Type' + ':</b>&nbsp' + e['report_type'] +
  43. '</p>';
  44. if (e['report_type'] == 'request' || e['report_type'] == 'donation') {
  45. contentStr += '<p><b>' + 'Resource Type' + ':</b>&nbsp' +
  46. e['resource_type'] + '</p>';
  47. }
  48. else if (e['report_type'] == 'damage') {
  49. contentStr += '<p><b>' + 'Damage Type' + ':</b>&nbsp' + e['damage_type']
  50. + '</p>';
  51. }
  52. contentStr += '<p><b>' + 'Reporter' + ':</b>&nbsp' +
  53. e['reporter_id'] + '</p>';
  54.  
  55. contentStr += '<p><b>' + 'Timestamp' + ':</b>&nbsp' +
  56. e['time_stamp'].substring(0,19) + '</p>';
  57. if ('message' in e){
  58. contentStr += '<p><b>' + 'Message' + ':</b>&nbsp' + e['message'] + '</p>';
  59. }
  60.  
  61. var icon = {
  62. url: 'https://1adn3cp4l2-flywheel.netdna-ssl.com/wp-content/uploads/2013/10/Donation-plugins-for-WordPress1.jpg', // url
  63. scaledSize: new google.maps.Size(40, 30), // scaled size
  64. origin: new google.maps.Point(0, 0), // origin
  65. anchor: new google.maps.Point(0, 0) // anchor
  66. };
  67.  
  68. var marker = new google.maps.Marker({
  69. position: latlng,
  70. map: map,
  71. icon: icon,
  72. customInfo: contentStr,
  73.  
  74. });
  75.  
  76.  
  77. // Add a Click Listener to the marker
  78. google.maps.event.addListener(marker, 'click', function() {
  79. // use 'customInfo' to customize infoWindow
  80. infowindow.setContent(marker['customInfo']);
  81. infowindow.open(map, marker); // Open InfoWindow
  82. });
  83.  
  84. });
  85.  
  86. map.fitBounds (bounds);
  87.  
  88. }
  89.  
  90.  
  91. //Execute our 'initialization' function once the page has loaded.
  92. google.maps.event.addDomListener(window, 'load', initialization);
Add Comment
Please, Sign In to add comment