var markerGroups = []; $(function() { $("a[data-customer-id]").click(function(event) { let customerId = $(this).data("customer-id"); let key = "customer-" + customerId; if(typeof markerGroups[key] !== "undefined") { for(let i in markerGroups[key]) { let m = markerGroups[key][i]; m.setMap(null); } } let selected = $(this).data("selected"); if(selected) { $(this).data("selected", false); $(this).find(".badge").removeClass("badge-success").text(""); } else { loadCustomerLocations(customerId); } return false; }); $("a[data-project-id]").click(function(event) { let projectId = $(this).data("project-id"); let key = "project-" + projectId; if(typeof markerGroups[key] !== "undefined") { for(let i in markerGroups[key]) { let m = markerGroups[key][i]; m.setMap(null); } } let selected = $(this).data("selected"); if(selected) { $(this).data("selected", false); $(this).find(".badge").removeClass("badge-success").text(""); } else { loadProjectLocations(projectId); } return false; }); }); function loadCustomerLocations(customerId) { $.get("/account/map-overview/get-customer-locations", { customer_id: customerId, submit: $("#submit").val() }, function(response) { if(!response.success) return false; let map = maps["map"]; let key = "customer-" + customerId; markerGroups[key] = []; for(let i in response.locations) { let l = response.locations[i]; let position = { lat: l.latitude, lng: l.longitude }; var options = { position: position, title: l.name, map: map }; if(l.icon) options.icon = l.icon; let marker = new google.maps.Marker(options); markerGroups[key].push(marker); } $("a[data-customer-id=" + customerId + "]").data("selected", true); $("a[data-customer-id=" + customerId + "]").find(".badge").addClass("badge-danger").text(response.locations.length); }); } function loadProjectLocations(projectId) { $.get("/account/map-overview/get-project-locations", { project_id: projectId, submit: $("#submit").val() }, function(response) { if(!response.success) return false; let map = maps["map"]; let key = "project-" + projectId; markerGroups[key] = []; for(let i in response.locations) { let l = response.locations[i]; let position = { lat: l.latitude, lng: l.longitude }; var options = { position: position, title: l.name, map: map }; if(l.icon) options.icon = l.icon; let marker = new google.maps.Marker(options); markerGroups[key].push(marker); } $("a[data-project-id=" + projectId + "]").data("selected", true); $("a[data-project-id=" + projectId + "]").find(".badge").addClass("badge-danger").text(response.locations.length); }); }