Kaynağa Gözat

Added info window to project map.

Alan Lam 8 yıl önce
ebeveyn
işleme
8f247a0090
1 değiştirilmiş dosya ile 30 ekleme ve 0 silme
  1. 30 0
      public/js/app-project.js

+ 30 - 0
public/js/app-project.js

@@ -9,6 +9,7 @@ var locationLatLngBounds;
 var assignLatLngBounds;
 
 var map = null;
+var infoWindow = false;
 
 var locations = [];
 var testers = [];
@@ -59,6 +60,10 @@ $(function() {
 
 function initialiseLocations() {
 
+	if(!infoWindow) {
+		infoWindow = new google.maps.InfoWindow();
+	}
+
 	map = maps["map"];
 
 	for(let i in locationMarkers) {
@@ -218,13 +223,26 @@ function handleFindTestersButtonClick() {
 
 function handleLocationClick() {
 
+	// Info Window
+	let content = "<strong><a href=\"/account/locations/" + this.location.id + "\" target=\"_blank\">" + this.location.name + "</a></strong><br />";
+	if(this.location.internalId) {
+		content += "Internal ID: " + this.location.internalId + "<br />";
+	}
+	content += "ID: " + this.location.id;
+
+	infoWindow.setContent(content);
+	infoWindow.open(map, this);
+
+	// Set selected location
 	selectedLocation = {
 		id: this.location.id,
 		testerId: this.location.testerId
 	};
 
+	// Pan map
 	map.panTo(this.getPosition());
 
+	// Update list groups
 	clearTesters();
 	initialiseTesters();
 
@@ -289,6 +307,8 @@ function initialiseTesters() {
 			let marker = new google.maps.Marker(options);
 			marker.addressId = tester.id;
 			marker.userId = tester.id;
+			marker.tester = tester;
+			marker.addListener("click", handleTesterClick);
 
 			testerMarkers.push(marker);
 
@@ -340,6 +360,16 @@ function initialiseTesters() {
 	});
 }
 
+
+function handleTesterClick() {
+	// Info Window
+	let content = "<strong><a href=\"/account/users/" + this.tester.id + "\" target=\"_blank\">" + this.tester.name + "</a></strong><br />";
+	content += "ID: " + this.tester.id;
+
+	infoWindow.setContent(content);
+	infoWindow.open(map, this);
+}
+
 function handleAssignButtonClick(event) {
 	let container = $(this).closest("[data-address-id]");