app-map-overview.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var markerGroups = [];
  2. $(function() {
  3. $("a[data-customer-id]").click(function(event) {
  4. let customerId = $(this).data("customer-id");
  5. let key = "customer-" + customerId;
  6. if(typeof markerGroups[key] !== "undefined") {
  7. for(let i in markerGroups[key]) {
  8. let m = markerGroups[key][i];
  9. m.setMap(null);
  10. }
  11. }
  12. let selected = $(this).data("selected");
  13. if(selected) {
  14. $(this).data("selected", false);
  15. $(this).find(".badge").removeClass("badge-success").text("");
  16. }
  17. else {
  18. loadCustomerLocations(customerId);
  19. }
  20. return false;
  21. });
  22. $("a[data-project-id]").click(function(event) {
  23. let projectId = $(this).data("project-id");
  24. let key = "project-" + projectId;
  25. if(typeof markerGroups[key] !== "undefined") {
  26. for(let i in markerGroups[key]) {
  27. let m = markerGroups[key][i];
  28. m.setMap(null);
  29. }
  30. }
  31. let selected = $(this).data("selected");
  32. if(selected) {
  33. $(this).data("selected", false);
  34. $(this).find(".badge").removeClass("badge-success").text("");
  35. }
  36. else {
  37. loadProjectLocations(projectId);
  38. }
  39. return false;
  40. });
  41. });
  42. function loadCustomerLocations(customerId) {
  43. $.get("/account/map-overview/get-customer-locations", {
  44. customer_id: customerId,
  45. submit: $("#submit").val()
  46. }, function(response) {
  47. if(!response.success) return false;
  48. let map = maps["map"];
  49. let key = "customer-" + customerId;
  50. markerGroups[key] = [];
  51. for(let i in response.locations) {
  52. let l = response.locations[i];
  53. let position = {
  54. lat: l.latitude,
  55. lng: l.longitude
  56. };
  57. var options = {
  58. position: position,
  59. title: l.name,
  60. map: map
  61. };
  62. if(l.icon) options.icon = l.icon;
  63. let marker = new google.maps.Marker(options);
  64. markerGroups[key].push(marker);
  65. }
  66. $("a[data-customer-id=" + customerId + "]").data("selected", true);
  67. $("a[data-customer-id=" + customerId + "]").find(".badge").addClass("badge-danger").text(response.locations.length);
  68. });
  69. }
  70. function loadProjectLocations(projectId) {
  71. $.get("/account/map-overview/get-project-locations", {
  72. project_id: projectId,
  73. submit: $("#submit").val()
  74. }, function(response) {
  75. if(!response.success) return false;
  76. let map = maps["map"];
  77. let key = "project-" + projectId;
  78. markerGroups[key] = [];
  79. for(let i in response.locations) {
  80. let l = response.locations[i];
  81. let position = {
  82. lat: l.latitude,
  83. lng: l.longitude
  84. };
  85. var options = {
  86. position: position,
  87. title: l.name,
  88. map: map
  89. };
  90. if(l.icon) options.icon = l.icon;
  91. let marker = new google.maps.Marker(options);
  92. markerGroups[key].push(marker);
  93. }
  94. $("a[data-project-id=" + projectId + "]").data("selected", true);
  95. $("a[data-project-id=" + projectId + "]").find(".badge").addClass("badge-danger").text(response.locations.length);
  96. });
  97. }