display locations parsed from ysf on map
This commit is contained in:
@ -12,6 +12,33 @@
|
||||
ws.send("SERVER DE CLIENT client=map.js type=map");
|
||||
};
|
||||
|
||||
var map;
|
||||
var markers = {};
|
||||
var updateQueue = [];
|
||||
|
||||
var processUpdates = function(updates) {
|
||||
if (!map) {
|
||||
updateQueue = updateQueue.concat(updates);
|
||||
return;
|
||||
}
|
||||
updates.forEach(function(update){
|
||||
// TODO maidenhead locator implementation
|
||||
if (update.location.type != 'latlon') return;
|
||||
var pos = new google.maps.LatLng(update.location.lat, update.location.lon)
|
||||
if (markers[update.callsign]) {
|
||||
console.info("updating");
|
||||
markers[update.callsign].setPosition(pos);
|
||||
} else {
|
||||
console.info("initializing");
|
||||
markers[update.callsign] = new google.maps.Marker({
|
||||
position: pos,
|
||||
map: map,
|
||||
title: update.callsign
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ws.onmessage = function(e){
|
||||
if (typeof e.data != 'string') {
|
||||
console.error("unsupported binary data on websocket; ignoring");
|
||||
@ -27,15 +54,19 @@
|
||||
case "config":
|
||||
var config = json.value;
|
||||
$.getScript("https://maps.googleapis.com/maps/api/js?key=" + config.google_maps_api_key).done(function(){
|
||||
var map = new google.maps.Map($('body')[0], {
|
||||
map = new google.maps.Map($('body')[0], {
|
||||
center: {
|
||||
lat: config.receiver_gps[0],
|
||||
lng: config.receiver_gps[1]
|
||||
},
|
||||
zoom: 8
|
||||
});
|
||||
processUpdates(updateQueue);
|
||||
})
|
||||
break
|
||||
case "update":
|
||||
processUpdates(json.value);
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
// don't lose exception
|
||||
|
Reference in New Issue
Block a user