diff --git a/apps.json b/apps.json index db8e2d92f..b8dcda7fd 100644 --- a/apps.json +++ b/apps.json @@ -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"} + ] } ] diff --git a/apps/whereworld/ChangeLog b/apps/whereworld/ChangeLog new file mode 100644 index 000000000..863a2e9a2 --- /dev/null +++ b/apps/whereworld/ChangeLog @@ -0,0 +1 @@ +0.01: Created app \ No newline at end of file diff --git a/apps/whereworld/app-icon.js b/apps/whereworld/app-icon.js new file mode 100644 index 000000000..00ff3a14b --- /dev/null +++ b/apps/whereworld/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwxH+oIA/AANAFNFjtIrBoFoxmMGMopDtFpAgQvBGEgpDAYYwDHwYECG4tjHyonCsYuFtAkDxlpF49osiMSshbDLwwfDsdoKpCoBMCASBOgIsBAgIvFsaOGRYwcCCAYvMJwIrCCQRfIAAouDIgYGCtFpGJRbCAAIWBDgruEOwwQBOYqSBsZFEDQJZBsh7BCgQXDDwLGBF49AAwZfBUIoAFE4IoBCBBeCBYI6BJQYuFIQVpFpYAEtLiGc4oBBEwIuBLIg+CACZHEMA1AtJaCtLsFCwJILKJKiCWgIzFaQTxDf4qaCFRx3DeIp8IAwRACLq7sCJoyUJGIJfGRaRYDAA9pT5I/EZIL+ECw4aEF5Z+GCQ69CsbXBUAi9IRhCAJT5gwERhNpJZAhHZ4NoZx4ABSI6MKGA1otJRBIgwvHFgNpoNkNAJnBXYK8LG49osloSIpfIOAQLBAYJJBAoYAReoZIEoFkGQo+DCAILBAIRgSoKqLdgb/HsdkVQQNBBw5fMF45gDQwKqHAALCCAYIwUTZS/CGAzMEGQQvQtASGEIQKBDxDNGYh6kBRozAEDpQMBDQSOQIwVkCaCSIPIagIF4xCRVhQCCSBqzBUB4TCBjBfDcJIA/aq4utaBw+EAYIBEJKdAsYNMf4OMtFAsgEBAAoKBJSFoxgpHsYKBAIIADFxAxDJxBtCDINjEgQNFEZQANDwpJDJopAFsYuXZwhNKUIhdZLwhMLF4TVBFzJfGRQoPENgRvLAB1pVqFkoABBLzLdSRra/FF5oAdsi9BMYJSdeBzzDGFY=")) \ No newline at end of file diff --git a/apps/whereworld/app.js b/apps/whereworld/app.js new file mode 100644 index 000000000..48d0f7b0c --- /dev/null +++ b/apps/whereworld/app.js @@ -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(); + } +}); \ No newline at end of file diff --git a/apps/whereworld/app.png b/apps/whereworld/app.png new file mode 100644 index 000000000..1e12db39d Binary files /dev/null and b/apps/whereworld/app.png differ diff --git a/apps/whereworld/worldmap b/apps/whereworld/worldmap new file mode 100644 index 000000000..d7e30424f Binary files /dev/null and b/apps/whereworld/worldmap differ