0.03: Show widgets (mainly so we can use the GPS recorder widget)

master
Gordon Williams 2020-05-08 22:06:36 +01:00
parent 4416df1363
commit e57e03d35d
3 changed files with 18 additions and 5 deletions

View File

@ -1193,7 +1193,7 @@
"name": "OpenStreetMap", "name": "OpenStreetMap",
"shortName":"OpenStMap", "shortName":"OpenStMap",
"icon": "app.png", "icon": "app.png",
"version":"0.02", "version":"0.03",
"description": "[BETA] Loads map tiles from OpenStreetMap onto your Bangle.js and displays a map of where you are", "description": "[BETA] Loads map tiles from OpenStreetMap onto your Bangle.js and displays a map of where you are",
"tags": "outdoors,gps", "tags": "outdoors,gps",
"custom": "custom.html", "custom": "custom.html",

View File

@ -1,2 +1,3 @@
0.01: New App! 0.01: New App!
0.02: Fix marker position, color, and map scaling 0.02: Fix marker position, color, and map scaling
0.03: Show widgets (mainly so we can use the GPS recorder widget)

View File

@ -1,11 +1,12 @@
var s = require("Storage"); var s = require("Storage");
var map = s.readJSON("openstmap.json"); var map = s.readJSON("openstmap.json");
var HASWIDGETS = true;
var y1,y2;
map.center = Bangle.project({lat:map.lat,lon:map.lon}); map.center = Bangle.project({lat:map.lat,lon:map.lon});
var lat = map.lat, lon = map.lon; var lat = map.lat, lon = map.lon;
var fix = {}; var fix = {};
function redraw() { function redraw() {
var cx = g.getWidth()/2; var cx = g.getWidth()/2;
var cy = g.getHeight()/2; var cy = g.getHeight()/2;
@ -17,6 +18,7 @@ function redraw() {
var ty = 0|(iy/map.tilesize); var ty = 0|(iy/map.tilesize);
var ox = (tx*map.tilesize)-ix; var ox = (tx*map.tilesize)-ix;
var oy = (ty*map.tilesize)-iy; var oy = (ty*map.tilesize)-iy;
g.setClipRect(0,y1,g.getWidth()-1,y2);
for (var x=ox,ttx=tx;x<g.getWidth();x+=map.tilesize,ttx++) { for (var x=ox,ttx=tx;x<g.getWidth();x+=map.tilesize,ttx++) {
for (var y=oy,tty=ty;y<g.getHeight();y+=map.tilesize,tty++) { for (var y=oy,tty=ty;y<g.getHeight();y+=map.tilesize,tty++) {
var img = s.read("openstmap-"+ttx+"-"+tty+".img"); var img = s.read("openstmap-"+ttx+"-"+tty+".img");
@ -29,6 +31,7 @@ function redraw() {
} }
} }
drawMarker(); drawMarker();
g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1);
} }
function drawMarker() { function drawMarker() {
@ -43,9 +46,6 @@ function drawMarker() {
g.fillRect(ix-2,iy-2,ix+2,iy+2); g.fillRect(ix-2,iy-2,ix+2,iy+2);
} }
redraw();
var fix; var fix;
Bangle.on('GPS',function(f) { Bangle.on('GPS',function(f) {
fix=f; fix=f;
@ -60,6 +60,18 @@ Bangle.on('GPS',function(f) {
drawMarker(); drawMarker();
}); });
Bangle.setGPSPower(1); Bangle.setGPSPower(1);
if (HASWIDGETS) {
Bangle.loadWidgets();
Bangle.drawWidgets();
y1 = 24;
var hasBottomRow = Object.keys(WIDGETS).some(w=>WIDGETS[w].area[0]=="b");
y2 = g.getHeight() - (hasBottomRow ? 24 : 1);
} else {
y1=0;
y2=g.getHeight()-1;
}
redraw(); redraw();
setWatch(function() { setWatch(function() {