Skip to content

Commit

Permalink
improve tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Dec 31, 2023
1 parent e87f44c commit 6d9336b
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 238 deletions.
44 changes: 22 additions & 22 deletions application/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const module = (() => {

var notification = new window.Notification(title, options);

notification.onerror = function (err) {
console.log(err);
};
notification.onerror = function (err) {};
notification.onclick = function (event) {
if (window.navigator.mozApps) {
var request = window.navigator.mozApps.getSelf();
Expand Down Expand Up @@ -525,9 +523,7 @@ const module = (() => {

let update_gpx_info = function () {
document.getElementById("gpx-name").innerText = gpx_selection_info.name;
document.getElementById("gpx-time").innerText = format_ms(
gpx_selection_info.duration
);
document.getElementById("gpx-time").innerText = format_ms(gpx_selection_info.duration);

document.querySelector("#gpx-evo-up span").innerText =
gpx_selection_info.elevation_gain.toFixed(2);
Expand Down Expand Up @@ -736,7 +732,7 @@ const module = (() => {
if (altitudeDifference > 0) {
gain += altitudeDifference;
} else {
loss -= altitudeDifference; // Convert negative difference to positive for loss
loss += Math.abs(altitudeDifference);
}
}
}
Expand Down Expand Up @@ -800,13 +796,13 @@ const module = (() => {
tracking.gain
)
? "-"
: tracking.gain;
: tracking.gain.toFixed(2);

document.querySelector("#tracking-view .loss div").innerText = isNaN(
tracking.loss
)
? "-"
: tracking.loss;
: tracking.loss.toFixed(2);

document.querySelector("#tracking-view .altitude div").innerText = isNaN(
tracking.altitude
Expand All @@ -817,9 +813,9 @@ const module = (() => {
document.querySelector("#tracking-view .average-speed div").innerText =
isNaN(tracking.speed_average) ? "-" : tracking.speed_average;

document.querySelector("#tracking-evo-down span").innerText = tracking.loss;
document.querySelector("#tracking-evo-up span").innerText = tracking.gain;
document.getElementById("tracking-altitude").innerText = tracking.altitude;
document.querySelector("#tracking-evo-down span").innerText = tracking.loss.toFixed(2);
document.querySelector("#tracking-evo-up span").innerText = tracking.gain.toFixed(2);
document.getElementById("tracking-altitude").innerText = tracking.altitude.toFixed(2);

document.querySelector("#tracking-speed-average-time").innerText = isNaN(
tracking.speed_average
Expand Down Expand Up @@ -904,7 +900,7 @@ const module = (() => {
polyline_tracking.addLatLng([
tracking_cache[i].lat,
tracking_cache[i].lng,
tracking_cache[i].timestamp,
tracking_cache[i].alt,
]);

tracking_timestamp.push(tracking_cache[i].timestamp);
Expand All @@ -927,15 +923,12 @@ const module = (() => {
//store time
let ts = new Date();
tracking_timestamp.push(ts.toISOString());
//store altitude
let alt = "";
if (mainmarker.device_alt) {
if (isNaN(mainmarker.device_alt)) {
alt = null;
} else {
alt = mainmarker.device_alt;
tracking_altitude.push(alt);
}
// Store altitude
let alt = null;

if (mainmarker.device_alt && !isNaN(mainmarker.device_alt)) {
alt = mainmarker.device_alt;
// tracking_altitude.push(alt);
}

polyline_tracking.addLatLng([
Expand Down Expand Up @@ -967,6 +960,12 @@ const module = (() => {
console.log(e);
}

// Extract altitudes from the LatLng objects and filter out null values
tracking_altitude = tracking_cache
.map((latlng) => latlng.alt)
.filter((altitude) => altitude !== null);

// Now you can use the filtered tracking_altitude array in the calculateGainAndLoss function
const { gain, loss } = calculateGainAndLoss(tracking_altitude, 50);

//get tracking data to display in view
Expand Down Expand Up @@ -1213,5 +1212,6 @@ const module = (() => {
pushLocalNotification,
uniqueId,
parseGPX,
update_gpx_info,
};
})();
4 changes: 4 additions & 0 deletions application/assets/js/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ const osm = (() => {
};

files.push({ name: m.name, id: m.id, type: "osm_sever" });
files_.push({ name: m.name, id: m.id, type: "osm_sever" });

files.sort((a, b) => {
return b.name.localeCompare(a.name);
});
Expand All @@ -286,6 +288,8 @@ const osm = (() => {
};

files.push({ name: m.name, id: m.id, type: "osm_sever" });
files_.push({ name: m.name, id: m.id, type: "osm_sever" });

files.sort((a, b) => {
return b.name.localeCompare(a.name);
});
Expand Down
40 changes: 31 additions & 9 deletions application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let tracking_group = new L.FeatureGroup();
let gpx_group = new L.FeatureGroup();
let geoJSON_group = new L.FeatureGroup();
var hotline_group = new L.FeatureGroup();

var jsonLayer = L.geoJSON("", { color: "red" });
let map;
let tracking_timestamp = [];
Expand All @@ -24,9 +23,10 @@ let gpx_selection_info = {};
let gpx_string;
let tilesLayer = "";
let n;

let gps_lock;

let files_ = [];

const audio = document.createElement("audio");
audio.mozAudioChannelType = "content";

Expand Down Expand Up @@ -467,6 +467,8 @@ document.addEventListener("DOMContentLoaded", function () {
});

finder_gpx.on("fileFound", function (file, fileinfo, storageName) {
files_.push({ name: fileinfo.name, path: fileinfo.path, type: "gpx" });

files.push({ name: fileinfo.name, path: fileinfo.path, type: "gpx" });
files.sort((a, b) => {
return b.name.localeCompare(a.name);
Expand All @@ -484,7 +486,7 @@ document.addEventListener("DOMContentLoaded", function () {

let filename = e.split("/");
filename = filename[filename.length - 1];

files_.push({ name: filename, path: e, type: "gpx" });
files.push({ name: filename, path: e, type: "gpx" });
files.sort((a, b) => {
return b.name.localeCompare(a.name);
Expand Down Expand Up @@ -558,6 +560,12 @@ document.addEventListener("DOMContentLoaded", function () {
});
});
finder.on("fileFound", function (file, fileinfo, storageName) {
files_.push({
name: fileinfo.name,
path: fileinfo.path,
type: "geoJSON",
});

files.push({
name: fileinfo.name,
path: fileinfo.path,
Expand All @@ -570,12 +578,12 @@ document.addEventListener("DOMContentLoaded", function () {
} catch (e) {}

//KaiOS 3.x

let list_files_callback = function (e) {
let files = [];

let filename = e.split("/");
filename = filename[filename.length - 1];
files_.push({ name: filename, path: e, type: "geoJSON" });

files.push({ name: filename, path: e, type: "geoJSON" });
files.sort((a, b) => {
Expand Down Expand Up @@ -893,15 +901,22 @@ document.addEventListener("DOMContentLoaded", function () {
};

let open_finder = function () {
console.log(files_);
settings.load_settings();
finder_tabindex();
document.querySelector("div#finder").style.display = "block";
finder_navigation("start");
status.windowOpen = "finder";

activelayer();
mapcenter_position();

if (general.active_item == "") {
finder_navigation("start");
} else {
general.active_item.focus();
tabIndex = document.activeElement.getAttribute("tabindex");
}

//openweather request
if (setting.openweather_api == "") return false;
let c = map.getCenter();
Expand Down Expand Up @@ -1675,6 +1690,9 @@ document.addEventListener("DOMContentLoaded", function () {
}

if (general.active_item.getAttribute("data-map") == "geojson") {
document.querySelectorAll("#files-option div").forEach(function (e) {
e.style.display = "none";
});
document.querySelectorAll("div.only-gpx-local").forEach(function (e) {
e.style.display = "block";
});
Expand Down Expand Up @@ -1867,6 +1885,10 @@ document.addEventListener("DOMContentLoaded", function () {
count--;
if (count == -1) count = finder_panels.length - 1;
}

if (dir == "start") {
console.log("start");
}
document.getElementById(finder_panels[count].id).style.display = "block";
document.getElementById(finder_panels[count].id).focus();

Expand Down Expand Up @@ -1911,7 +1933,6 @@ document.addEventListener("DOMContentLoaded", function () {
}

if (finder_panels[count].id == "routing") {
console.log("hey. " + setting.routing_profil);
document.querySelectorAll(".item")[0].focus();
helper.bottom_bar("", "", "");
document.querySelector("button.routing-profile-status").innerText =
Expand Down Expand Up @@ -1939,6 +1960,7 @@ document.addEventListener("DOMContentLoaded", function () {
document.activeElement.parentNode.focus();
}
status.activeElement = document.activeElement;

//get items from current

let b = document.activeElement.closest("div.menu-box");
Expand Down Expand Up @@ -2212,7 +2234,7 @@ document.addEventListener("DOMContentLoaded", function () {
if (status.windowOpen == "scan") {
qr.stop_scan();
open_finder();
windowOpen = "finder";
//windowOpen = "finder";
}

if (
Expand All @@ -2224,8 +2246,8 @@ document.addEventListener("DOMContentLoaded", function () {
if (status.windowOpen == "files-option") {
document.getElementById("files-option").style.display = "none";
open_finder();
windowOpen = "finder";
general.active_item.focus();
// windowOpen = "finder";

break;
}

Expand Down
4 changes: 2 additions & 2 deletions application/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.9.752",
"version": "1.9.759",
"version_name": "hotline",
"name": "o.map",
"description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.",
"launch_path": "/index.html",
"type": "privileged",
"fullscreen": "true",
"priority": "high",
"userAgentInfo": "o.map / 1.9.751 written by [email protected]",
"userAgentInfo": "o.map / 1.9.755 written by [email protected]",
"icons": {
"56": "/assets/icons/icon-56-56.png",
"112": "/assets/icons/icon-112-112.png"
Expand Down
13 changes: 6 additions & 7 deletions application/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

"lang": "en-US",
"start_url": "/index.html",
"priority": "high",
"userAgentInfo": "o.map written by [email protected]",
"priority": "high",
"userAgentInfo": "o.map written by [email protected]",

"icons": [
{
Expand All @@ -22,7 +22,7 @@
],

"b2g_features": {
"version": "2.0.78",
"version": "2.0.79",
"id": "o.map",
"core": true,
"categories": ["utilities"],
Expand All @@ -34,8 +34,8 @@
"name": "strukturart",
"url": "https://github.com/strukturart/o.map"
},
"messages": [

"messages": [
{ "serviceworker-notification": "index.html" },
"alarm",
"activity"
Expand All @@ -54,8 +54,7 @@
},

"permissions": {

"desktop-notification": {
"desktop-notification": {
"description": "Needed to fire system notifications"
},
"alarms": {
Expand Down
Loading

0 comments on commit 6d9336b

Please sign in to comment.