app-locations.js 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function initialiseLocations() {
  2. $.get("/api/customers/" + customerId + "/get-locations", {
  3. id: $("#id").val(),
  4. internal_id: $("#internal-id").val(),
  5. name: $("#name").val()
  6. }, function(response) {
  7. if(!response.success) return false;
  8. if(!response.locations) return false;
  9. let map = maps["map"];
  10. let bounds = new google.maps.LatLngBounds;
  11. for(let i in response.locations) {
  12. let location = response.locations[i];
  13. let position = {
  14. lat: location.latitude,
  15. lng: location.longitude
  16. };
  17. let options = {
  18. map: map,
  19. position: position,
  20. title: location.name
  21. }
  22. if(location.icon) {
  23. options.icon = "/img/markers/" + location.icon;
  24. }
  25. bounds.extend(position);
  26. let marker = new google.maps.Marker(options);
  27. marker.locationId = location.id;
  28. marker.addListener("click", function() {
  29. window.open("/account/locations/" + this.locationId, "_blank");
  30. });
  31. }
  32. map.fitBounds(bounds);
  33. });
  34. }