Procházet zdrojové kódy

Added info windows to show ID and internal ID.

Alan Lam před 8 roky
rodič
revize
f46beae978
1 změnil soubory, kde provedl 28 přidání a 3 odebrání
  1. 28 3
      public/js/app-map-overview.js

+ 28 - 3
public/js/app-map-overview.js

@@ -1,4 +1,5 @@
 var markerGroups = [];
+var infoWindow = false;
 
 $(function() {
 
@@ -52,6 +53,10 @@ $(function() {
 
 function loadCustomerLocations(customerId) {
 
+	if(infoWindow == false) {
+		infoWindow = new google.maps.InfoWindow();
+	}
+
 	$.get("/account/map-overview/get-customer-locations", {
 		customer_id: customerId,
 		submit: $("#submit").val()
@@ -64,7 +69,6 @@ function loadCustomerLocations(customerId) {
 		markerGroups[key] = [];
 
 		for(let i in response.locations) {
-
 			let l = response.locations[i];
 
 			let position = {
@@ -80,10 +84,12 @@ function loadCustomerLocations(customerId) {
 
 			if(l.icon) options.icon = l.icon;
 
+			infoWindow.setContent("");
+
 			let marker = new google.maps.Marker(options);
+			addMarkerClickListener(marker, l);
 
 			markerGroups[key].push(marker);
-
 		}
 
 		$("a[data-customer-id=" + customerId + "]").data("selected", true);
@@ -95,6 +101,10 @@ function loadCustomerLocations(customerId) {
 
 function loadProjectLocations(projectId) {
 
+	if(infoWindow == false) {
+		infoWindow = new google.maps.InfoWindow();
+	}
+
 	$.get("/account/map-overview/get-project-locations", {
 		project_id: projectId,
 		submit: $("#submit").val()
@@ -124,6 +134,7 @@ function loadProjectLocations(projectId) {
 			if(l.icon) options.icon = l.icon;
 
 			let marker = new google.maps.Marker(options);
+			addMarkerClickListener(marker, l);
 
 			markerGroups[key].push(marker);
 
@@ -133,4 +144,18 @@ function loadProjectLocations(projectId) {
 		$("a[data-project-id=" + projectId + "]").find(".badge").addClass("badge-danger").text(response.locations.length);
 
 	});
-}
+}
+
+function addMarkerClickListener(m, l) {
+	let map = maps["map"];
+	m.addListener("click", function() {
+		let content = "<strong><a href=\"/account/locations/" + l.id + "\" target=\"_blank\">" + l.name + "</a></strong><br />";
+		if(l.internalId) {
+			content += "Internal ID: " + l.internalId + "<br />";
+		}
+		content += "ID: " + l.id + "<br />";
+
+		infoWindow.setContent(content);
+		infoWindow.open(map, m);
+	});
+}