24 lines
721 B
JavaScript
24 lines
721 B
JavaScript
(function (ns, $) {
|
|
'use strict';
|
|
|
|
function request(path) {
|
|
return $.ajax({ url: ns.Config.apiBase + path, method: 'GET', dataType: 'json', cache: false });
|
|
}
|
|
|
|
function routeQuery(position) {
|
|
const params = new URLSearchParams({ activatedOnly: 'true' });
|
|
if (position) {
|
|
params.set('lat', String(position.lat));
|
|
params.set('lon', String(position.lon));
|
|
params.set('radiusKm', String(ns.Config.routeRadiusKm));
|
|
}
|
|
return `/routes?${params.toString()}`;
|
|
}
|
|
|
|
ns.Api = {
|
|
health: () => request('/health'),
|
|
routes: position => request(routeQuery(position)),
|
|
route: id => request(`/routes/${encodeURIComponent(id)}`)
|
|
};
|
|
}(globalThis.Wegwichtel, globalThis.jQuery));
|