|
|
@@ -27,41 +27,54 @@ class Map {
|
|
|
}
|
|
|
|
|
|
if($item.prop("checked")) {
|
|
|
- // Add markers
|
|
|
- $.post("/api/get-markers", {
|
|
|
- customer_id: customerId
|
|
|
- }).then(response => {
|
|
|
- if(typeof this.markers[customerId] === "undefined") {
|
|
|
- this.markers[customerId] = [];
|
|
|
- }
|
|
|
-
|
|
|
- response.markers.forEach(markerData => {
|
|
|
- const marker = new google.maps.Marker({
|
|
|
- map: this.map,
|
|
|
- position: markerData.latLng,
|
|
|
- });
|
|
|
- marker.addListener("click", () => {
|
|
|
- window.location = markerData.url;
|
|
|
- });
|
|
|
-
|
|
|
- this.markers[customerId].push(marker);
|
|
|
- });
|
|
|
-
|
|
|
+ this.plotForCustomerId(customerId).then(() => {
|
|
|
$item.find("i").attr("class", "fa fa-fw fa-check text-success");
|
|
|
$item.attr("data-selected", "true");
|
|
|
});
|
|
|
}
|
|
|
else {
|
|
|
- // Remove markers
|
|
|
- this.markers[customerId].forEach(marker => {
|
|
|
- marker.setMap(null);
|
|
|
- });
|
|
|
- this.markers[customerId] = [];
|
|
|
+ this.removeForCustomerId(customerId);
|
|
|
|
|
|
$item.find("i").attr("class", "fa fa-fw");
|
|
|
$item.attr("data-selected", "false");
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ const $map = $("#map");
|
|
|
+ const data = $map.data();
|
|
|
+ const { customerId } = data;
|
|
|
+ if(customerId) {
|
|
|
+ this.plotForCustomerId(customerId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ plotForCustomerId(customerId) {
|
|
|
+ return $.post("/api/get-markers", {
|
|
|
+ customer_id: customerId
|
|
|
+ }).then(response => {
|
|
|
+ if(typeof this.markers[customerId] === "undefined") {
|
|
|
+ this.markers[customerId] = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ response.markers.forEach(markerData => {
|
|
|
+ const marker = new google.maps.Marker({
|
|
|
+ map: this.map,
|
|
|
+ position: markerData.latLng,
|
|
|
+ });
|
|
|
+ marker.addListener("click", () => {
|
|
|
+ window.location = markerData.url;
|
|
|
+ });
|
|
|
+
|
|
|
+ this.markers[customerId].push(marker);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ removeForCustomerId(customerId) {
|
|
|
+ this.markers[customerId].forEach(marker => {
|
|
|
+ marker.setMap(null);
|
|
|
+ });
|
|
|
+ this.markers[customerId] = [];
|
|
|
}
|
|
|
|
|
|
get latLng() {
|