1
0
Fork 0

Added my "Where in the world?" application

master
seb 2021-04-15 17:34:14 +01:00
parent 3093d5123f
commit 82f839bd3f
6 changed files with 84 additions and 0 deletions

View File

@ -3132,5 +3132,18 @@
{"name":"hourstrike.boot.js","url":"boot.js"},
{"name":"hourstrike.img","url":"app-icon.js","evaluate":true}
]
},
{ "id": "whereworld",
"name": "Where in the World?",
"shortName" : "Where World",
"icon": "app.png",
"version": "0.01",
"description": "Shows your current location on the world map",
"tags": "gps",
"storage": [
{"name":"whereworld.app.js","url":"app.js"},
{"name":"whereworld.img","url":"app-icon.js","evaluate":true},
{"name":"whereworld.worldmap","url":"worldmap"}
]
}
]

View File

@ -0,0 +1 @@
0.01: Created app

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+oIA/AANAFNFjtIrBoFoxmMGMopDtFpAgQvBGEgpDAYYwDHwYECG4tjHyonCsYuFtAkDxlpF49osiMSshbDLwwfDsdoKpCoBMCASBOgIsBAgIvFsaOGRYwcCCAYvMJwIrCCQRfIAAouDIgYGCtFpGJRbCAAIWBDgruEOwwQBOYqSBsZFEDQJZBsh7BCgQXDDwLGBF49AAwZfBUIoAFE4IoBCBBeCBYI6BJQYuFIQVpFpYAEtLiGc4oBBEwIuBLIg+CACZHEMA1AtJaCtLsFCwJILKJKiCWgIzFaQTxDf4qaCFRx3DeIp8IAwRACLq7sCJoyUJGIJfGRaRYDAA9pT5I/EZIL+ECw4aEF5Z+GCQ69CsbXBUAi9IRhCAJT5gwERhNpJZAhHZ4NoZx4ABSI6MKGA1otJRBIgwvHFgNpoNkNAJnBXYK8LG49osloSIpfIOAQLBAYJJBAoYAReoZIEoFkGQo+DCAILBAIRgSoKqLdgb/HsdkVQQNBBw5fMF45gDQwKqHAALCCAYIwUTZS/CGAzMEGQQvQtASGEIQKBDxDNGYh6kBRozAEDpQMBDQSOQIwVkCaCSIPIagIF4xCRVhQCCSBqzBUB4TCBjBfDcJIA/aq4utaBw+EAYIBEJKdAsYNMf4OMtFAsgEBAAoKBJSFoxgpHsYKBAIIADFxAxDJxBtCDINjEgQNFEZQANDwpJDJopAFsYuXZwhNKUIhdZLwhMLF4TVBFzJfGRQoPENgRvLAB1pVqFkoABBLzLdSRra/FF5oAdsi9BMYJSdeBzzDGFY="))

69
apps/whereworld/app.js Normal file
View File

@ -0,0 +1,69 @@
const landColor = 0x8FAB, seaColor= 0x365D, markerColor = 0xF800;
let lastSuccess = true;
const mapImg = {
width : 240,
height : 240,
palette: new Uint16Array([landColor, seaColor]),
buffer: require("Storage").read("whereworld.worldmap")
};
function getMarkerImg(x, y) {
const b = Graphics.createArrayBuffer(240, 240, 2, {msb:true});
b.setColor(1);
b.drawLine(x, 0, x, b.getHeight());
b.drawLine(0, y, b.getWidth(), y);
const pal = new Uint16Array([0, markerColor]);
return {width: 240, height: 240, bpp: 2, palette: pal, buffer: b.buffer, transparent: 0};
}
function degreesToRadians(deg) {
return (deg / 180) * Math.PI;
}
function coordsToScreenLocation(lat, lon) {
const maxMapHeight = g.getHeight() - 1, maxMapWidth = g.getWidth() - 1;
const maxLong = 180;
const x = ((lon + maxLong) / (maxLong * 2)) * maxMapWidth;
const mercN = Math.log(Math.tan((Math.PI / 4) + (degreesToRadians(lat) / 2)));
const y = (maxMapHeight / 2) - (maxMapWidth * mercN / (2 * Math.PI));
return {x: x, y: y};
}
function drawLocation(lat, lon) {
const location = coordsToScreenLocation(lat, lon);
g.drawImages([
{image: mapImg},
{image: getMarkerImg(location.x, location.y)}
]);
}
function drawNoFixMessage() {
const b = Graphics.createArrayBuffer(240, 216, 1, {msb:true});
const throbber = ".".repeat(new Date().getSeconds() % 4);
b.setColor(1);
b.setFont("6x8", 2);
b.drawString("Finding GPS Fix" + throbber, 15, 94);
g.drawImage({
width: b.getWidth(),
height: b.getHeight(),
palette: new Uint16Array([0, 0xF800]),
buffer: b.buffer
}, 0, 24);
}
Bangle.setGPSPower(1);
Bangle.loadWidgets();
Bangle.on('GPS', function(gps) {
if (gps.fix) {
drawLocation(gps.lat, gps.lon);
lastSuccess = true;
}
else {
if (lastSuccess) {
Bangle.drawWidgets();
lastSuccess = false;
}
drawNoFixMessage();
}
});

BIN
apps/whereworld/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
apps/whereworld/worldmap Normal file

Binary file not shown.