mirror of https://github.com/espruino/BangleApps
0.07: Added @jeffmer's awesome track viewer (fix #273)
parent
f890227b61
commit
40f291730e
|
@ -280,7 +280,7 @@
|
|||
{ "id": "gpsrec",
|
||||
"name": "GPS Recorder",
|
||||
"icon": "app.png",
|
||||
"version":"0.06",
|
||||
"version":"0.07",
|
||||
"interface": "interface.html",
|
||||
"description": "Application that allows you to record a GPS track. Can run in background",
|
||||
"tags": "tool,outdoors,gps,widget",
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
0.04: Properly Fix GPS time display in gpsrec app
|
||||
0.05: Tweaks for variable size widget system
|
||||
0.06: Ensure widget update itself (fix #118) and change to using icons
|
||||
0.07: Added @jeffmer's awesome track viewer
|
||||
|
|
|
@ -70,27 +70,65 @@ function viewTracks() {
|
|||
return E.showMenu(menu);
|
||||
}
|
||||
|
||||
function getTrackInfo(fn) {
|
||||
var filename = getFN(fn);
|
||||
var minLat = 90;
|
||||
var maxLat = -90;
|
||||
var minLong = 180;
|
||||
var maxLong = -180;
|
||||
var starttime, duration=0;
|
||||
var f = require("Storage").open(filename,"r");
|
||||
if (f===undefined) return;
|
||||
var l = f.readLine(f);
|
||||
var nl = 0, c, n;
|
||||
if (l!==undefined) {
|
||||
c = l.split(",");
|
||||
starttime = parseInt(c[0]);
|
||||
}
|
||||
// pushed this loop together to try and bump loading speed a little
|
||||
while(l!==undefined) {
|
||||
++nl;c=l.split(",");
|
||||
n = parseFloat(c[1]);if(n>maxLat)maxLat=n;if(n<minLat)minLat=n;
|
||||
n = parseFloat(c[2]);if(n>maxLong)maxLong=n;if(n<minLong)minLong=n;
|
||||
l = f.readLine(f);
|
||||
}
|
||||
if (c) duration = parseInt(c[0]) - starttime;
|
||||
var lfactor = Math.cos(minLat*Math.PI/180);
|
||||
var ylen = (maxLat-minLat);
|
||||
var xlen = (maxLong-minLong)* lfactor;
|
||||
var scale = xlen>ylen ? 200/xlen : 200/ylen;
|
||||
return {
|
||||
fn : fn,
|
||||
filename : filename,
|
||||
time : new Date(starttime),
|
||||
records : nl,
|
||||
minLat : minLat, maxLat : maxLat,
|
||||
minLong : minLong, maxLong : maxLong,
|
||||
lfactor : lfactor,
|
||||
scale : scale,
|
||||
duration : Math.round(duration/1000)
|
||||
};
|
||||
}
|
||||
|
||||
function asTime(v){
|
||||
var mins = Math.floor(v/60);
|
||||
var secs = v-mins*60;
|
||||
return ""+mins.toString()+"m "+secs.toString()+"s";
|
||||
}
|
||||
|
||||
function viewTrack(n) {
|
||||
E.showMessage("Loading...","GPS Track "+n);
|
||||
var info = getTrackInfo(n);
|
||||
const menu = {
|
||||
'': { 'title': 'GPS Track '+n }
|
||||
};
|
||||
var trackCount = 0;
|
||||
var trackTime;
|
||||
var f = require("Storage").open(getFN(n),"r");
|
||||
var l = f.readLine();
|
||||
if (l!==undefined) {
|
||||
var c = l.split(",");
|
||||
trackTime = new Date(parseInt(c[0]));
|
||||
}
|
||||
while (l!==undefined) {
|
||||
trackCount++;
|
||||
// TODO: min/max/length of track?
|
||||
l = f.readLine();
|
||||
}
|
||||
if (trackTime)
|
||||
menu[" "+trackTime.toISOString().substr(0,16).replace("T"," ")] = function(){};
|
||||
menu[trackCount+" records"] = function(){};
|
||||
// TODO: option to draw it? Just scan through, project using min/max
|
||||
if (info.time)
|
||||
menu[info.time.toISOString().substr(0,16).replace("T"," ")] = function(){};
|
||||
menu["Duration"] = { value : asTime(info.duration)};
|
||||
menu["Records"] = { value : ""+info.records };
|
||||
menu['Plot'] = function() {
|
||||
plotTrack(info);
|
||||
};
|
||||
menu['Erase'] = function() {
|
||||
E.showPrompt("Delete Track?").then(function(v) {
|
||||
if (v) {
|
||||
|
@ -107,4 +145,80 @@ function viewTrack(n) {
|
|||
return E.showMenu(menu);
|
||||
}
|
||||
|
||||
function plotTrack(info) {
|
||||
function xcoord(long){
|
||||
return 30 + Math.round((long-info.minLong)*info.lfactor*info.scale);
|
||||
}
|
||||
|
||||
function ycoord(lat){
|
||||
return 210 - Math.round((lat - info.minLat)*info.scale);
|
||||
}
|
||||
|
||||
function radians(a) {
|
||||
return a*Math.PI/180;
|
||||
}
|
||||
|
||||
function distance(lat1,long1,lat2,long2){
|
||||
var x = radians(long1-long2) * Math.cos(radians((lat1+lat2)/2));
|
||||
var y = radians(lat2-lat1);
|
||||
return Math.sqrt(x*x + y*y) * 6371000;
|
||||
}
|
||||
|
||||
E.showMenu(); // remove menu
|
||||
g.setColor(1,0.5,0.5);
|
||||
g.setFont("Vector",16);
|
||||
g.fillRect(9,80,11,120);
|
||||
g.fillPoly([9,60,19,80,0,80]);
|
||||
g.setColor(1,1,1);
|
||||
g.drawString("N",2,40);
|
||||
g.drawString("Track"+info.fn.toString()+" - Loading",10,220);
|
||||
g.setColor(0,0,0);
|
||||
g.fillRect(0,220,239,239);
|
||||
g.setColor(1,1,1);
|
||||
g.drawString(asTime(info.duration),10,220);
|
||||
var f = require("Storage").open(info.filename,"r");
|
||||
if (f===undefined) return;
|
||||
var l = f.readLine(f);
|
||||
var ox=0;
|
||||
var oy=0;
|
||||
var olat,olong,dist=0;
|
||||
var first = true;
|
||||
var i=0;
|
||||
while(l!==undefined) {
|
||||
var c = l.split(",");
|
||||
var lat = parseFloat(c[1]);
|
||||
var long = parseFloat(c[2]);
|
||||
var x = xcoord(long);
|
||||
var y = ycoord(lat);
|
||||
if (first) {
|
||||
g.moveTo(x,y);
|
||||
g.setColor(0,1,0);
|
||||
g.fillCircle(x,y,5);
|
||||
g.setColor(1,1,1);
|
||||
first = false;
|
||||
} else if (x!=ox || y!=oy) {
|
||||
g.lineTo(x,y);
|
||||
}
|
||||
if (!first) {
|
||||
var d = distance(olat,olong,lat,long);
|
||||
if (!isNaN(d)) dist+=d;
|
||||
}
|
||||
olat = lat;
|
||||
olong = long;
|
||||
ox = x;
|
||||
oy = y;
|
||||
l = f.readLine(f);
|
||||
}
|
||||
g.setColor(1,0,0);
|
||||
g.fillCircle(ox,oy,5);
|
||||
g.setColor(1,1,1);
|
||||
g.drawString(require("locale").distance(dist),120,220);
|
||||
g.setFont("6x8",2);
|
||||
g.setFontAlign(0,0,3);
|
||||
g.drawString("Back",230,200);
|
||||
setWatch(function() {
|
||||
viewTrack(info.fn);
|
||||
}, BTN3);
|
||||
}
|
||||
|
||||
showMainMenu();
|
||||
|
|
Loading…
Reference in New Issue