infowindow for ysf markers

This commit is contained in:
Jakob Ketterl 2019-07-11 21:21:01 +02:00
parent 8edc7c1374
commit acbf2939c9
2 changed files with 19 additions and 3 deletions

View File

@ -21,6 +21,7 @@ body {
h3 { h3 {
margin: 10px 0; margin: 10px 0;
text-align: center;
} }
ul { ul {

View File

@ -46,6 +46,9 @@
marker = markers[update.callsign]; marker = markers[update.callsign];
} else { } else {
marker = new google.maps.Marker(); marker = new google.maps.Marker();
marker.addListener('click', function(){
showMarkerInfoWindow(update.callsign, pos);
});
markers[update.callsign] = marker; markers[update.callsign] = marker;
} }
marker.setOptions($.extend({ marker.setOptions($.extend({
@ -58,6 +61,7 @@
// TODO the trim should happen on the server side // TODO the trim should happen on the server side
if (expectedCallsign && expectedCallsign == update.callsign.trim()) { if (expectedCallsign && expectedCallsign == update.callsign.trim()) {
map.panTo(pos); map.panTo(pos);
showMarkerInfoWindow(update.callsign, pos);
delete(expectedCallsign); delete(expectedCallsign);
} }
break; break;
@ -72,7 +76,7 @@
} else { } else {
rectangle = new google.maps.Rectangle(); rectangle = new google.maps.Rectangle();
rectangle.addListener('click', function(){ rectangle.addListener('click', function(){
showInfoWindow(update.location.locator, center); showLocatorInfoWindow(update.location.locator, center);
}); });
rectangles[update.callsign] = rectangle; rectangles[update.callsign] = rectangle;
} }
@ -93,7 +97,7 @@
if (expectedLocator && expectedLocator == update.location.locator) { if (expectedLocator && expectedLocator == update.location.locator) {
map.panTo(center); map.panTo(center);
showInfoWindow(expectedLocator, center); showLocatorInfoWindow(expectedLocator, center);
delete(expectedLocator); delete(expectedLocator);
} }
break; break;
@ -175,7 +179,7 @@
connect(); connect();
var infowindow; var infowindow;
var showInfoWindow = function(locator, pos) { var showLocatorInfoWindow = function(locator, pos) {
if (!infowindow) infowindow = new google.maps.InfoWindow(); if (!infowindow) infowindow = new google.maps.InfoWindow();
var inLocator = $.map(rectangles, function(r, callsign) { var inLocator = $.map(rectangles, function(r, callsign) {
return {callsign: callsign, locator: r.locator, lastseen: r.lastseen} return {callsign: callsign, locator: r.locator, lastseen: r.lastseen}
@ -198,6 +202,17 @@
infowindow.open(map); infowindow.open(map);
}; };
var showMarkerInfoWindow = function(callsign, pos) {
if (!infowindow) infowindow = new google.maps.InfoWindow();
var marker = markers[callsign];
var timestring = moment(marker.lastseen).fromNow();
infowindow.setContent(
'<h3>' + callsign + '</h3>' +
'<div>' + timestring + '</div>'
);
infowindow.open(map, marker);
}
var getScale = function(lastseen) { var getScale = function(lastseen) {
var age = new Date().getTime() - lastseen; var age = new Date().getTime() - lastseen;
var scale = 1; var scale = 1;