| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- var infoWindow = false;
- var exportIds = [];
- var markerMap = {};
- function initialiseLocations() {
- if(!infoWindow) {
- infoWindow = new google.maps.InfoWindow();
- }
- $.get("/api/customers/" + customerId + "/get-locations", {
- id: $("#id").val(),
- internal_id: $("#internal-id").val(),
- name: $("#name").val()
- }, function(response) {
- if(!response.success) return false;
- if(!response.locations) return false;
- let map = maps["map"];
- let bounds = new google.maps.LatLngBounds;
- for(let i in response.locations) {
- let location = response.locations[i];
- let position = {
- lat: location.latitude,
- lng: location.longitude
- };
- let options = {
- map: map,
- position: position,
- title: location.name
- }
- if(location.icon) {
- options.icon = "/img/markers/building-red.png";
- }
- bounds.extend(position);
- let key = "marker-" + location.id;
- let marker = new google.maps.Marker(options);
- marker.location = location;
- marker.addListener("click", function() {
- displayInfoWindow(this);
- });
- markerMap[key] = marker;
- }
- map.fitBounds(bounds);
- });
- $(document).on("click", "a[data-export-location-id]", function(event) {
- let locationId = parseInt($(this).attr("data-export-location-id"));
- let index = exportIds.indexOf(locationId);
- let key = "marker-" + locationId;
- let marker = markerMap[key];
- if(index == -1) {
- exportIds.push(locationId);
- marker.setOptions({
- icon: "/img/markers/building-green.png"
- });
- }
- else {
- exportIds.splice(index, 1);
- marker.setOptions({
- icon: "/img/markers/building-red.png"
- });
- }
- displayInfoWindow(marker);
- });
- $("#export-csv-button, #export-kml-button").click(function(event) {
- if(exportIds.length > 0) {
- event.preventDefault();
- let action = $(this).attr("data-action");
- $("#locations-export-form input[name='ids[]']").remove();
- $("#locations-export-form input[name='action']").val(action);
- for(let i in exportIds) {
- let locationId = exportIds[i];
- $("#locations-export-form").append("<input type=\"hidden\" name=\"ids[]\" value=\"" + locationId + "\" />");
- }
- $("#locations-export-form").submit();
- }
- });
- }
- function displayInfoWindow(marker) {
- let locationId = parseInt(marker.location.id);
- let index = exportIds.indexOf(locationId);
- let exportText = "Select for Export";
- let exportClass = "btn-primary";
- if(index > -1) {
- exportText = "Deselect for Export";
- exportClass = "btn-success";
- }
- let content = "<div class=\"container-fluid\" style=\"font-size: 1rem; font-weight: normal;\">";
- content += "<p>" + marker.location.name + "</p>\n";
- content += "<div class=\"row\">";
- content += "<div class=\"col\"><a class=\"btn btn-block " + exportClass + "\" href=\"#\" data-export-location-id=\"" + marker.location.id + "\">" + exportText + "</a></div>";
- content += "<div class=\"col\"><a class=\"btn btn-block btn-primary\" href=\"/account/locations/" + marker.location.id + "\" target=\"_blank\">View Details</a></div>";
- content += "</div>";
- content += "</div>";
- infoWindow.setContent(content);
- infoWindow.open(map, marker);
- }
|