2022-02-05 15:54:14 +00:00
|
|
|
// GridTracker Copyright © 2022 GridTracker.org
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE for more information.
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
var g_pota = {
|
2022-09-19 02:06:49 +00:00
|
|
|
parks: {},
|
|
|
|
parksTimeout: null,
|
|
|
|
callSchedule: {},
|
|
|
|
parkSchedule: {},
|
2022-09-11 01:05:25 +00:00
|
|
|
scheduleTimeout: null,
|
2022-09-19 02:06:49 +00:00
|
|
|
callSpots: {},
|
|
|
|
spotsTimeout: null,
|
|
|
|
mapParks: {}
|
2022-09-11 01:05:25 +00:00
|
|
|
};
|
2022-02-05 15:54:14 +00:00
|
|
|
|
2022-09-14 01:13:16 +00:00
|
|
|
var g_defaultPark = {
|
|
|
|
scheduled: false,
|
|
|
|
spotted: false,
|
2022-09-19 02:06:49 +00:00
|
|
|
activators: {},
|
|
|
|
feature: null
|
2022-09-14 01:13:16 +00:00
|
|
|
}
|
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
var g_gtParkIconActive = new ol.style.Icon({
|
|
|
|
src: "./img/pota_icon_active.png",
|
|
|
|
anchorYUnits: "pixels",
|
|
|
|
anchorXUnits: "pixels",
|
|
|
|
anchor: [10, 19]
|
|
|
|
});
|
|
|
|
|
|
|
|
var g_gtParkIconInactive = new ol.style.Icon({
|
|
|
|
src: "./img/pota_icon_inactive.png",
|
|
|
|
anchorYUnits: "pixels",
|
|
|
|
anchorXUnits: "pixels",
|
|
|
|
anchor: [10, 19]
|
|
|
|
});
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
function initPota()
|
|
|
|
{
|
|
|
|
potaImg.style.filter = g_potaEnabled == 1 ? "" : "grayscale(1)";
|
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
getPotaParks();
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function togglePota()
|
|
|
|
{
|
|
|
|
g_potaEnabled ^= 1;
|
|
|
|
g_appSettings.potaEnabled = g_potaEnabled;
|
|
|
|
potaImg.style.filter = g_potaEnabled == 1 ? "" : "grayscale(1)";
|
|
|
|
|
|
|
|
saveAppSettings();
|
|
|
|
|
|
|
|
if (g_potaEnabled == 1)
|
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
getPotaParks();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_layerSources.pota.clear();
|
|
|
|
g_pota.mapParks = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function rebuildParks()
|
|
|
|
{
|
|
|
|
g_layerSources.pota.clear();
|
|
|
|
g_pota.mapParks = {};
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeParkFeature(park, active)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (park in g_pota.parks)
|
2022-09-11 01:05:25 +00:00
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
let parkObj = null;
|
|
|
|
if (park in g_pota.mapParks)
|
|
|
|
{
|
|
|
|
parkObj = g_pota.mapParks[park];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parkObj = Object.assign({}, g_defaultPark);
|
|
|
|
g_pota.mapParks[park] = parkObj;
|
|
|
|
}
|
|
|
|
if (parkObj.feature == null)
|
|
|
|
{
|
2022-09-20 00:42:20 +00:00
|
|
|
parkObj.feature = iconFeature(ol.proj.fromLonLat([0, 0]), g_gtParkIconActive, 1);
|
2022-09-19 02:06:49 +00:00
|
|
|
}
|
|
|
|
feature.key = park;
|
|
|
|
feature.size = 1;
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
catch (e)
|
2022-09-14 01:13:16 +00:00
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
console.log("exception: makeParkFeature " + park);
|
|
|
|
console.log(e.message);
|
2022-09-14 01:13:16 +00:00
|
|
|
}
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
function processPotaParks(buffer)
|
2022-02-05 21:55:25 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
let newParks = JSON.parse(buffer);
|
|
|
|
g_pota.parks = newParks;
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
getPotaSchedule();
|
|
|
|
getPotaSpots();
|
2022-02-05 21:55:25 +00:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// can't write, somethings broke
|
2022-09-19 02:06:49 +00:00
|
|
|
console.log("Failed to load parks!");
|
|
|
|
console.log(e.message);
|
2022-02-05 21:55:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
function getPotaParks()
|
2022-02-05 15:54:14 +00:00
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
if (g_pota.parksTimeout)
|
2022-09-11 01:05:25 +00:00
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
clearTimeout(g_pota.parksTimeout);
|
2022-09-11 01:05:25 +00:00
|
|
|
g_pota.spotsTimeout = null;
|
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
if (g_mapSettings.offlineMode == false && g_potaEnabled == 1)
|
2022-02-05 21:55:25 +00:00
|
|
|
{
|
|
|
|
getBuffer(
|
2022-09-20 00:42:20 +00:00
|
|
|
"https://storage.googleapis.com/gt_app/pota.json?cb=" + Date.now(),
|
2022-09-19 02:06:49 +00:00
|
|
|
processPotaParks,
|
2022-02-05 21:55:25 +00:00
|
|
|
null,
|
2022-05-18 01:47:35 +00:00
|
|
|
"https",
|
|
|
|
443
|
2022-02-05 21:55:25 +00:00
|
|
|
);
|
|
|
|
}
|
2022-09-11 01:05:25 +00:00
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
g_pota.parksTimeout = setTimeout(getPotaParks, 86400000)
|
|
|
|
}
|
|
|
|
|
|
|
|
function uniqueArrayFromArray(input)
|
|
|
|
{
|
|
|
|
let unique = [];
|
2022-09-20 00:42:20 +00:00
|
|
|
input.forEach((c) =>
|
|
|
|
{
|
|
|
|
if (!unique.includes(c))
|
|
|
|
{
|
|
|
|
unique.push(c);
|
2022-09-19 02:06:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return unique;
|
2022-02-05 15:54:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
function processPotaSpots(buffer)
|
2022-02-05 17:36:52 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-09-11 01:05:25 +00:00
|
|
|
let spots = JSON.parse(buffer);
|
2022-09-19 02:06:49 +00:00
|
|
|
g_pota.callSpots = {};
|
|
|
|
g_pota.parkSpots = {};
|
|
|
|
for (const spot in spots)
|
|
|
|
{
|
|
|
|
if (spots[spot].reference in g_pota.parks)
|
|
|
|
{
|
|
|
|
(g_pota.callSpots[spots[spot].activator] = g_pota.callSpots[spots[spot].activator] || []).push(spots[spot].reference);
|
|
|
|
(g_pota.parkSpots[spots[spot].reference] = g_pota.parkSpots[spots[spot].reference] || []).push(spots[spot].activator);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log("PotaSpots: unknown park id: " + spots[spot].reference);
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
// Sanity dedupe checks
|
|
|
|
for (const spot in g_pota.callSpots)
|
2022-09-11 01:05:25 +00:00
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
g_pota.callSpots[spot] = uniqueArrayFromArray(g_pota.callSpots[spot]);
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
2022-09-19 02:06:49 +00:00
|
|
|
for (const spot in g_pota.parkSpots)
|
|
|
|
{
|
|
|
|
g_pota.parkSpots[spot] = uniqueArrayFromArray(g_pota.parkSpots[spot]);
|
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
rebuildParks();
|
2022-02-05 17:36:52 +00:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// can't write, somethings broke
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 15:56:25 +00:00
|
|
|
function getPotaSpots()
|
2022-02-05 15:54:14 +00:00
|
|
|
{
|
2022-09-11 01:05:25 +00:00
|
|
|
if (g_pota.spotsTimeout)
|
|
|
|
{
|
|
|
|
clearTimeout(g_pota.spotsTimeout);
|
|
|
|
g_pota.spotsTimeout = null;
|
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
if (g_mapSettings.offlineMode == false && g_potaEnabled == 1)
|
2022-02-05 17:36:52 +00:00
|
|
|
{
|
|
|
|
getBuffer(
|
|
|
|
"https://api.pota.app/spot/activator",
|
2022-09-11 01:05:25 +00:00
|
|
|
processPotaSpots,
|
2022-02-05 17:36:52 +00:00
|
|
|
null,
|
2022-02-05 18:08:25 +00:00
|
|
|
"https",
|
|
|
|
443
|
2022-02-05 17:36:52 +00:00
|
|
|
);
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
g_pota.spotsTimeout = setTimeout(getPotaSpots, 300000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function processPotaSchedule(buffer)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
let schedules = JSON.parse(buffer);
|
2022-09-19 02:06:49 +00:00
|
|
|
g_pota.callSchedule = {};
|
|
|
|
g_pota.parkSchedule = {};
|
|
|
|
for (const i in schedules)
|
2022-09-11 01:05:25 +00:00
|
|
|
{
|
|
|
|
let newObj = {};
|
|
|
|
newObj.id = schedules[i].reference;
|
|
|
|
newObj.start = Date.parse(schedules[i].startDate + "T" + schedules[i].startTime);
|
|
|
|
newObj.end = Date.parse(schedules[i].endDate + "T" + schedules[i].endTime);
|
2022-09-19 02:06:49 +00:00
|
|
|
newObj.frequencies = schedules[i].frequencies;
|
|
|
|
newObj.comments = schedules[i].comments;
|
2022-09-11 01:05:25 +00:00
|
|
|
if (Date.now() < newObj.end)
|
|
|
|
{
|
2022-09-19 02:06:49 +00:00
|
|
|
if (newObj.id in g_pota.parks)
|
|
|
|
{
|
|
|
|
(g_pota.callSchedule[schedules[i].activator] = g_pota.callSchedule[schedules[i].activator] || []).push(newObj);
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
newObj = Object.assign({}, newObj);
|
|
|
|
newObj.id = schedules[i].activator;
|
|
|
|
(g_pota.parkSchedule[schedules[i].reference] = g_pota.parkSchedule[schedules[i].reference] || []).push(newObj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.log("PotaSchedule: unknown park id: " + newObj.id);
|
|
|
|
}
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
|
|
|
// else it is expired and no longer relevant
|
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-19 02:06:49 +00:00
|
|
|
// Sanity dedupe checks
|
|
|
|
for (const key in g_pota.callSchedule)
|
|
|
|
{
|
2022-09-20 00:42:20 +00:00
|
|
|
g_pota.callSchedule[key] = uniqueArrayFromArray(g_pota.callSchedule[key]);
|
2022-09-19 02:06:49 +00:00
|
|
|
}
|
|
|
|
for (const key in g_pota.parkSchedule)
|
|
|
|
{
|
2022-09-20 00:42:20 +00:00
|
|
|
g_pota.parkSchedule[key] = uniqueArrayFromArray(g_pota.parkSchedule[key]);
|
2022-09-19 02:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rebuildParks();
|
2022-09-11 01:05:25 +00:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// can't write, somethings broke
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPotaSchedule()
|
|
|
|
{
|
2022-09-11 20:18:00 +00:00
|
|
|
if (g_pota.scheduleTimeout)
|
2022-09-11 01:05:25 +00:00
|
|
|
{
|
|
|
|
clearTimeout(g_pota.scheduleTimeout);
|
|
|
|
g_pota.scheduleTimeout = null;
|
|
|
|
}
|
2022-09-20 00:42:20 +00:00
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
if (g_mapSettings.offlineMode == false && g_potaEnabled == 1)
|
|
|
|
{
|
|
|
|
getBuffer(
|
|
|
|
"https://api.pota.app/activation",
|
|
|
|
processPotaSchedule,
|
|
|
|
null,
|
|
|
|
"https",
|
|
|
|
443
|
|
|
|
);
|
2022-02-05 17:36:52 +00:00
|
|
|
}
|
2022-09-11 01:05:25 +00:00
|
|
|
g_pota.scheduleTimeout = setTimeout(getPotaSchedule, 900000);
|
2022-02-05 15:54:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 01:05:25 +00:00
|
|
|
function sendPotaSpot()
|
2022-02-05 15:54:14 +00:00
|
|
|
{
|
|
|
|
// if Pota spotting enabled, and we have enough info, send a spot to Pota
|
|
|
|
}
|