|
|
@@ -2,15 +2,34 @@ class Map {
|
|
|
constructor() {
|
|
|
this.element = document.getElementById("map");
|
|
|
this.markers = [];
|
|
|
+ this.infoWindow = new google.maps.InfoWindow();
|
|
|
|
|
|
this.map = new google.maps.Map(this.element, {
|
|
|
center: this.latLng,
|
|
|
zoom: 5
|
|
|
});
|
|
|
|
|
|
+ this.map.addListener("click", () => {
|
|
|
+ this.infoWindow.close();
|
|
|
+ });
|
|
|
+
|
|
|
this.$table = $("#customers-table");
|
|
|
|
|
|
const $checkboxes = this.$table.find("tbody input[type=checkbox]");
|
|
|
+ const $rows = this.$table.find("tbody tr");
|
|
|
+ $rows.on("click", event => {
|
|
|
+ const $row = $(event.currentTarget);
|
|
|
+ const customerId = $row.data("id");
|
|
|
+ const $checkbox = $row.find("input[type=checkbox]");
|
|
|
+ const checked = $checkbox.prop("checked");
|
|
|
+ if(checked) {
|
|
|
+ this.removeForCustomerId(customerId)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.plotForCustomerId(customerId);
|
|
|
+ }
|
|
|
+ $checkbox.prop("checked", !checked);
|
|
|
+ });
|
|
|
|
|
|
const $allCheckbox = $("#all-items-checkbox");
|
|
|
$allCheckbox.on("change", () => {
|
|
|
@@ -83,12 +102,26 @@ class Map {
|
|
|
}
|
|
|
|
|
|
response.markers.forEach(markerData => {
|
|
|
+ const { latLng, name, addressLinesHtml, url, customer } = markerData;
|
|
|
+
|
|
|
const marker = new google.maps.Marker({
|
|
|
map: this.map,
|
|
|
- position: markerData.latLng,
|
|
|
+ position: latLng,
|
|
|
});
|
|
|
+
|
|
|
marker.addListener("click", () => {
|
|
|
- window.location = markerData.url;
|
|
|
+ const $header = $("<h6>").text(name);
|
|
|
+ const $address = $("<address>").html(addressLinesHtml);
|
|
|
+ const $button = $("<a>").attr("class", "btn btn-sm btn-primary").attr("href", url).text("View");
|
|
|
+ const $customerLink = $(`<a class="d-block my-3">`).attr("href", customer.url).text(customer.name);
|
|
|
+
|
|
|
+ const $div = $("<div>").append([$header, $address, $customerLink, $button]);
|
|
|
+
|
|
|
+ this.infoWindow.setContent($div.html());
|
|
|
+ this.infoWindow.open({
|
|
|
+ anchor: marker,
|
|
|
+ map: this.map,
|
|
|
+ })
|
|
|
});
|
|
|
|
|
|
this.markers[customerId].push(marker);
|