| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- var markerGroups = [];
- var infoWindow = false;
- $(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;
- });
- $("a[data-all-addresses]").click(function(event) {
- let key = "all-addresses";
- 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 {
- loadAllAddresses();
- }
- return false;
- });
- });
- function loadCustomerLocations(customerId) {
- if(infoWindow == false) {
- infoWindow = new google.maps.InfoWindow();
- }
- $.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 = "/img/markers/" + l.icon;
- infoWindow.setContent("");
- let marker = new google.maps.Marker(options);
- addMarkerClickListenerForLocation(marker, l);
- 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) {
- if(infoWindow == false) {
- infoWindow = new google.maps.InfoWindow();
- }
- $.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 = "/img/markers/" + l.icon;
- let marker = new google.maps.Marker(options);
- addMarkerClickListenerForLocation(marker, l);
- 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);
- });
- }
- function loadAllAddresses() {
- if(infoWindow == false) {
- infoWindow = new google.maps.InfoWindow();
- }
- $.get("/api/addresses/get-all", {
- submit: $("#submit").val()
- }, function(response) {
- if(!response.success) return false;
- let map = maps["map"];
- let key = "all-addresses";
- markerGroups[key] = [];
- for(let i in response.addresses) {
- let a = response.addresses[i];
- let position = {
- lat: a.latitude,
- lng: a.longitude
- };
- var options = {
- position: position,
- title: a.name,
- map: map
- };
- let marker = new google.maps.Marker(options);
- addMarkerClickListenerForAddress(marker, a);
- markerGroups[key].push(marker);
- }
- $("a[data-all-addresses]").data("selected", true);
- $("a[data-all-addresses]").find(".badge").addClass("badge-danger").text(response.addresses.length);
- });
- }
- function addMarkerClickListenerForLocation(m, l) {
- let map = maps["map"];
- m.addListener("click", function() {
- let content = "<strong><a href=\"/account/locations/" + l.id + "\" target=\"_blank\">" + l.name + "</a></strong><br />";
- if(l.internalId) {
- content += "Internal ID: " + l.internalId + "<br />";
- }
- content += "ID: " + l.id + "<br />";
- infoWindow.setContent(content);
- infoWindow.open(map, m);
- });
- }
- function addMarkerClickListenerForAddress(m, a) {
- let map = maps["map"];
- m.addListener("click", function() {
- let content = "<strong><a href=\"/account/users/" + a.userId + "\" target=\"_blank\">" + a.name + "</a></strong><br />";
- content += "ID: " + a.userId + "<br />";
- infoWindow.setContent(content);
- infoWindow.open(map, m);
- });
- }
|