add a quick infowindow to show who's in a grid square

This commit is contained in:
Jakob Ketterl 2019-07-07 21:24:56 +02:00
parent 30b56c553e
commit 83273636f6
2 changed files with 35 additions and 0 deletions

View File

@ -2,3 +2,13 @@ html, body {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
h3 {
margin: 10px 0;
}
ul {
margin-block-start: 5px;
margin-block-end: 5px;
padding-inline-start: 25px;
}

View File

@ -73,6 +73,8 @@
rectangle = rectangles[update.callsign]; rectangle = rectangles[update.callsign];
} else { } else {
rectangle = new google.maps.Rectangle(); rectangle = new google.maps.Rectangle();
var center = new google.maps.LatLng({lat: lat + .5, lng: lon + 1});
rectangle.addListener('click', buildRectangleClick(update.location.locator, center));
rectangles[update.callsign] = rectangle; rectangles[update.callsign] = rectangle;
} }
rectangle.setOptions($.extend({ rectangle.setOptions($.extend({
@ -88,6 +90,7 @@
} }
}, getRectangleOpacityOptions(update.lastseen) )); }, getRectangleOpacityOptions(update.lastseen) ));
rectangle.lastseen = update.lastseen; rectangle.lastseen = update.lastseen;
rectangle.locator = update.location.locator;
break; break;
} }
}); });
@ -144,6 +147,28 @@
console.info("onerror"); console.info("onerror");
}; };
var infowindow;
var buildRectangleClick = function(locator, pos) {
if (!infowindow) infowindow = new google.maps.InfoWindow();
return function() {
var inLocator = $.map(rectangles, function(r, callsign) {
return {callsign: callsign, locator: r.locator}
}).filter(function(d) {
return d.locator == locator;
});
infowindow.setContent(
'<h3>Locator: ' + locator + '</h3>' +
'<div>Active Callsigns:</div>' +
'<ul>' +
inLocator.map(function(i){ return '<li>' + i.callsign + '</li>' }).join("") +
'</ul>'
);
infowindow.setPosition(pos);
infowindow.open(map);
};
}
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;