|
|
@@ -1,17 +1,20 @@
|
|
|
+
|
|
|
var markerGroups = [];
|
|
|
var infoWindow = false;
|
|
|
|
|
|
$(function() {
|
|
|
|
|
|
// On customer select
|
|
|
- $("a[data-customer-id]").click(function(event) {
|
|
|
+ $("a[data-customer-id]").click(function() {
|
|
|
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);
|
|
|
+ if(markerGroups[key].hasOwnProperty(i)) {
|
|
|
+ let m = markerGroups[key][i];
|
|
|
+ m.setMap(null);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -28,14 +31,16 @@ $(function() {
|
|
|
});
|
|
|
|
|
|
// On project select
|
|
|
- $("a[data-project-id]").click(function(event) {
|
|
|
+ $("a[data-project-id]").click(function() {
|
|
|
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);
|
|
|
+ if(markerGroups[key].hasOwnProperty(i)) {
|
|
|
+ let m = markerGroups[key][i];
|
|
|
+ m.setMap(null);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -52,13 +57,15 @@ $(function() {
|
|
|
});
|
|
|
|
|
|
// On all addresses select
|
|
|
- $("a[data-all-addresses]").click(function(event) {
|
|
|
+ $("a[data-all-addresses]").click(function() {
|
|
|
|
|
|
let key = "all-addresses";
|
|
|
if(typeof markerGroups[key] !== "undefined") {
|
|
|
for(let i in markerGroups[key]) {
|
|
|
- let m = markerGroups[key][i];
|
|
|
- m.setMap(null);
|
|
|
+ if(markerGroups[key].hasOwnProperty(i)) {
|
|
|
+ let m = markerGroups[key][i];
|
|
|
+ m.setMap(null);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -101,7 +108,6 @@ function loadCustomerLocations(customerId) {
|
|
|
}, function(response) {
|
|
|
if(!response.success) return false;
|
|
|
|
|
|
- let map = maps["map"];
|
|
|
let key = "customer-" + customerId;
|
|
|
|
|
|
markerGroups[key] = [];
|
|
|
@@ -109,28 +115,7 @@ function loadCustomerLocations(customerId) {
|
|
|
let count = response.locations.length;
|
|
|
|
|
|
for(let i = 0; i < count; ++i) {
|
|
|
- let location = response.locations[i];
|
|
|
-
|
|
|
- let position = {
|
|
|
- lat: location.latitude,
|
|
|
- lng: location.longitude
|
|
|
- };
|
|
|
-
|
|
|
- var options = {
|
|
|
- position: position,
|
|
|
- title: location.name,
|
|
|
- map: map
|
|
|
- };
|
|
|
-
|
|
|
- if(location.icon) options.icon = "/img/markers/" + location.icon;
|
|
|
- if(location.doNotTest) options.icon = "/img/markers/do_not_test.png";
|
|
|
- if(location.closed) options.icon = "/img/markers/closed.png";
|
|
|
-
|
|
|
- infoWindow.setContent("");
|
|
|
-
|
|
|
- let marker = new google.maps.Marker(options);
|
|
|
- addMarkerClickListenerForLocation(marker, location);
|
|
|
-
|
|
|
+ let marker = addLocationMarker(response.locations[i]);
|
|
|
markerGroups[key].push(marker);
|
|
|
}
|
|
|
|
|
|
@@ -166,7 +151,6 @@ function loadProjectLocations(projectId) {
|
|
|
}, function(response) {
|
|
|
if(!response.success) return false;
|
|
|
|
|
|
- let map = maps["map"];
|
|
|
let key = "project-" + projectId;
|
|
|
|
|
|
markerGroups[key] = [];
|
|
|
@@ -174,36 +158,40 @@ function loadProjectLocations(projectId) {
|
|
|
let count = response.locations.length;
|
|
|
|
|
|
for(let i = 0; i < count; ++i) {
|
|
|
+ let marker = addLocationMarker(response.locations[i]);
|
|
|
+ markerGroups[key].push(marker);
|
|
|
+ }
|
|
|
|
|
|
- let location = response.locations[i];
|
|
|
-
|
|
|
- let position = {
|
|
|
- lat: location.latitude,
|
|
|
- lng: location.longitude
|
|
|
- };
|
|
|
+ $projectItem.data("selected", true);
|
|
|
+ $projectItem.find(".badge").addClass("badge-danger").text(response.locations.length);
|
|
|
|
|
|
- var options = {
|
|
|
- position: position,
|
|
|
- title: location.name,
|
|
|
- map: map
|
|
|
- };
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
- if(location.icon) options.icon = "/img/markers/" + location.icon;
|
|
|
- if(location.doNotTest) options.icon = "/img/markers/do_not_test.png";
|
|
|
- if(location.closed) options.icon = "/img/markers/closed.png";
|
|
|
+function addLocationMarker(location) {
|
|
|
|
|
|
+ let map = maps["map"];
|
|
|
|
|
|
- let marker = new google.maps.Marker(options);
|
|
|
- addMarkerClickListenerForLocation(marker, location);
|
|
|
+ let position = {
|
|
|
+ lat: location.latitude,
|
|
|
+ lng: location.longitude
|
|
|
+ };
|
|
|
|
|
|
- markerGroups[key].push(marker);
|
|
|
+ var options = {
|
|
|
+ position: position,
|
|
|
+ title: location.name,
|
|
|
+ map: map
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
+ if(location.icon) options.icon = "/img/markers/" + location.icon;
|
|
|
+ if(location.doNotTest) options.icon = "/img/markers/do_not_test.png";
|
|
|
+ if(location.closed) options.icon = "/img/markers/closed.png";
|
|
|
|
|
|
- $projectItem.data("selected", true);
|
|
|
- $projectItem.find(".badge").addClass("badge-danger").text(response.locations.length);
|
|
|
+ infoWindow.setContent("");
|
|
|
|
|
|
- });
|
|
|
+ let marker = new google.maps.Marker(options);
|
|
|
+ addMarkerClickListenerForLocation(marker, location);
|
|
|
+ return marker;
|
|
|
}
|
|
|
|
|
|
function loadAllAddresses() {
|