// How often to query the server? const REFRESH_INTERVAL_SEC = 60; // Storage for the spot data that the server gives us. var spots = [] // Marker layer var markersLayer; // Load spots and populate the table. function loadSpots() { $.getJSON('/api/v1/spots' + buildQueryString(), function(jsonData) { // Store data spots = jsonData; // Update map updateMap(); }); } // Build a query string for the API, based on the filters that the user has selected. function buildQueryString() { var str = "?"; ["dx_continent", "de_continent", "mode_type", "source", "band"].forEach(fn => { if (!allFilterOptionsSelected(fn)) { str = str + getQueryStringFor(fn) + "&"; } }); str = str + "max_age=" + $("#max-spot-age option:selected").val(); return str; } // Update the spots map function updateMap() { // Clear existing content markersLayer.clearLayers(); // Make new markers for all spots with a good location spots.forEach(function (s) { if (s["dx_location_good"]) { let m = L.marker([s["dx_latitude"], s["dx_longitude"]], {icon: getIcon(s)}); markersLayer.addLayer(m); } }); } // Get an icon for a spot, based on its band, using PSK Reporter colours, its program etc. function getIcon(s) { return L.ExtraMarkers.icon({ icon: "fa-" + s["icon"], iconColor: "white", // todo markerColor: "black", // todo shape: 'circle', prefix: 'fa', svg: true }); } // Load server options. Once a successful callback is made from this, we then query spots and set up the timer to query // spots repeatedly. function loadOptions() { $.getJSON('/api/v1/options', function(jsonData) { // Store options options = jsonData; // Add CSS for band bullets and band toggle buttons addBandColourCSS(options["bands"]); // Populate the filters panel generateBandsMultiToggleFilterCard(options["bands"]); generateMultiToggleFilterCard("#dx-continent-options", "dx_continent", options["continents"]); generateMultiToggleFilterCard("#de-continent-options", "de_continent", options["continents"]); generateMultiToggleFilterCard("#mode-options", "mode_type", options["mode_types"]); generateMultiToggleFilterCard("#source-options", "source", options["spot_sources"]); // Load settings from settings storage now all the controls are available loadSettings(); // Load spots and set up the timer loadSpots(); setInterval(loadSpots, REFRESH_INTERVAL_SEC * 1000); }); } // Dynamically add CSS code for the band bullets and band toggle buttons to be in the appropriate colour. // Some band names contain decimal points which are not allowed in CSS classes, so we text-replace them to "p". function addBandColourCSS(band_options) { var $style = $('