Alan Lam před 4 roky
rodič
revize
1d9c9818e0
2 změnil soubory, kde provedl 21 přidání a 2 odebrání
  1. 20 2
      public/js/app-locations.js
  2. 1 0
      views/location_list.php

+ 20 - 2
public/js/app-locations.js

@@ -3,6 +3,10 @@ let exportIds = [];
 let markerMap = {};
 let markerMap = {};
 
 
 // noinspection JSUnusedGlobalSymbols
 // noinspection JSUnusedGlobalSymbols
+function getMarkerKey(locationId) {
+	return `marker-${locationId}`;
+}
+
 function initialiseLocations() {
 function initialiseLocations() {
 
 
 	if(!infoWindow) {
 	if(!infoWindow) {
@@ -46,7 +50,7 @@ function initialiseLocations() {
 
 
 			bounds.extend(position);
 			bounds.extend(position);
 
 
-			let key = "marker-" + location.id;
+			let key = getMarkerKey(location.id);
 
 
 			let marker = new google.maps.Marker(options);
 			let marker = new google.maps.Marker(options);
 			marker.location = location;
 			marker.location = location;
@@ -67,7 +71,7 @@ function initialiseLocations() {
 
 
 		let locationId = parseInt($(event.currentTarget).attr("data-export-location-id"));
 		let locationId = parseInt($(event.currentTarget).attr("data-export-location-id"));
 		let index = exportIds.indexOf(locationId);
 		let index = exportIds.indexOf(locationId);
-		let key = "marker-" + locationId;
+		let key = getMarkerKey(locationId);
 		let marker = markerMap[key];
 		let marker = markerMap[key];
 
 
 		if(index === -1) {
 		if(index === -1) {
@@ -124,6 +128,20 @@ function initialiseLocations() {
 
 
 	new AddLocationsToProjectModal();
 	new AddLocationsToProjectModal();
 
 
+	$(".btn-map").on("click", event => {
+		const locationId = $(event.currentTarget).data("location-id");
+		const key = getMarkerKey(locationId);
+		const marker = markerMap[key];
+
+		const map = maps.map;
+
+		const center = marker.getPosition();
+		map.setCenter(center);
+		map.setZoom(14);
+
+		displayInfoWindow(markerMap[key]);
+	});
+
 }
 }
 
 
 function displayInfoWindow(marker) {
 function displayInfoWindow(marker) {

+ 1 - 0
views/location_list.php

@@ -59,6 +59,7 @@
 				</td>
 				</td>
 				<td class="text-right align-middle">
 				<td class="text-right align-middle">
 					<a class="btn btn-sm btn-outline-primary" href="/account/locations/<?=$location->id?>/edit">Edit</a>
 					<a class="btn btn-sm btn-outline-primary" href="/account/locations/<?=$location->id?>/edit">Edit</a>
+					<button type="button" class="btn btn-sm btn-outline-primary btn-map" data-location-id="<?=$location->id?>">Map</button>
 				</td>
 				</td>
 			</tr>
 			</tr>
 			<?php
 			<?php