show receiver location pin on the map

This commit is contained in:
Jakob Ketterl 2020-12-11 17:47:17 +01:00
parent bdb6d75f83
commit e062412e60
2 changed files with 43 additions and 6 deletions

View File

@ -30,6 +30,7 @@
var map; var map;
var markers = {}; var markers = {};
var rectangles = {}; var rectangles = {};
var receiverMarker;
var updateQueue = []; var updateQueue = [];
// reasonable default; will be overriden by server // reasonable default; will be overriden by server
@ -200,6 +201,7 @@
var reset = function(callsign, item) { item.setMap(); }; var reset = function(callsign, item) { item.setMap(); };
$.each(markers, reset); $.each(markers, reset);
$.each(rectangles, reset); $.each(rectangles, reset);
receiverMarker.setMap();
markers = {}; markers = {};
rectangles = {}; rectangles = {};
}; };
@ -227,12 +229,13 @@
switch (json.type) { switch (json.type) {
case "config": case "config":
var config = json.value; var config = json.value;
var receiverPos = {
lat: config.receiver_gps.lat,
lng: config.receiver_gps.lon
};
if (!map) $.getScript("https://maps.googleapis.com/maps/api/js?key=" + config.google_maps_api_key).done(function(){ if (!map) $.getScript("https://maps.googleapis.com/maps/api/js?key=" + config.google_maps_api_key).done(function(){
map = new google.maps.Map($('.openwebrx-map')[0], { map = new google.maps.Map($('.openwebrx-map')[0], {
center: { center: receiverPos,
lat: config.receiver_gps.lat,
lng: config.receiver_gps.lon
},
zoom: 5, zoom: 5,
}); });
@ -245,7 +248,27 @@
updateQueue = []; updateQueue = [];
}); });
map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push($(".openwebrx-map-legend")[0]); map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push($(".openwebrx-map-legend")[0]);
});
if (!receiverMarker) {
receiverMarker = new google.maps.Marker();
receiverMarker.addListener('click', function() {
showReceiverInfoWindow(receiverMarker);
});
}
receiverMarker.setOptions({
map: map,
position: receiverPos,
title: config['receiver_name'],
config: config
});
}); else {
receiverMarker.setOptions({
map: map,
position: receiverPos,
title: config['receiver_name'],
config: config
});
}
retention_time = config.map_position_retention_time * 1000; retention_time = config.map_position_retention_time * 1000;
break; break;
case "update": case "update":
@ -344,6 +367,15 @@
infowindow.open(map, marker); infowindow.open(map, marker);
} }
var showReceiverInfoWindow = function(marker) {
var infowindow = getInfoWindow()
infowindow.setContent(
'<h3>' + marker.config['receiver_name'] + '</h3>' +
'<div>Receiver location</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;

View File

@ -426,7 +426,12 @@ class MapConnection(OpenWebRxClient):
super().__init__(conn) super().__init__(conn)
pm = Config.get() pm = Config.get()
self.write_config(pm.filter("google_maps_api_key", "receiver_gps", "map_position_retention_time").__dict__()) self.write_config(pm.filter(
"google_maps_api_key",
"receiver_gps",
"map_position_retention_time",
"receiver_name",
).__dict__())
Map.getSharedInstance().addClient(self) Map.getSharedInstance().addClient(self)