|
@@ -70,81 +70,11 @@ class AddressMap {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/* Map Overview */
|
|
|
|
|
-
|
|
|
|
|
-class GoogleMap {
|
|
|
|
|
- constructor(element) {
|
|
|
|
|
- this.element = element;
|
|
|
|
|
- this.markers = [];
|
|
|
|
|
-
|
|
|
|
|
- this.map = new google.maps.Map(this.element, {
|
|
|
|
|
- center: this.latLng,
|
|
|
|
|
- zoom: 5
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- this.$customerList = $("#customer-list");
|
|
|
|
|
- this.$customerList.on("click", ".list-group-item", event => {
|
|
|
|
|
- const $item = $(event.currentTarget);
|
|
|
|
|
- const customerId = $item.attr("data-id");
|
|
|
|
|
- const selected = $item.attr("data-selected");
|
|
|
|
|
-
|
|
|
|
|
- if(selected === "false") {
|
|
|
|
|
- // 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 + "/update";
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- this.markers[customerId].push(marker);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- $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] = [];
|
|
|
|
|
-
|
|
|
|
|
- $item.find("i").attr("class", "fa fa-fw");
|
|
|
|
|
- $item.attr("data-selected", "false");
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- get latLng() {
|
|
|
|
|
- return {
|
|
|
|
|
- lat: 54,
|
|
|
|
|
- lng: -4
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
$(() => {
|
|
$(() => {
|
|
|
const addressMap = document.querySelector("#address-map");
|
|
const addressMap = document.querySelector("#address-map");
|
|
|
if(addressMap) {
|
|
if(addressMap) {
|
|
|
new AddressMap(addressMap);
|
|
new AddressMap(addressMap);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const map = document.getElementById("map");
|
|
|
|
|
- if(map) {
|
|
|
|
|
- new GoogleMap(map);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
toastr.options.positionClass = "toast-bottom-right";
|
|
toastr.options.positionClass = "toast-bottom-right";
|
|
|
});
|
|
});
|