diff --git a/apps/openstmap/ChangeLog b/apps/openstmap/ChangeLog index a991d92fd1..c1b8e5f21d 100644 --- a/apps/openstmap/ChangeLog +++ b/apps/openstmap/ChangeLog @@ -20,3 +20,4 @@ 0.17: With new Recorder app allow track to be drawn in the background Switch tile layer URL for faster/more reliable map tiles 0.18: Prefer map with highest resolution +0.19: Remember latitude, longitude & scale diff --git a/apps/openstmap/app.js b/apps/openstmap/app.js index c69ccece3a..88883b6d6a 100644 --- a/apps/openstmap/app.js +++ b/apps/openstmap/app.js @@ -6,11 +6,27 @@ var mapVisible = false; var hasScrolled = false; var settings = require("Storage").readJSON("openstmap.json",1)||{}; var plotTrack; +let checkMapPos = false; // Do we need to check the if the coordinates we have are valid + +if (settings.lat !== undefined && settings.lon !== undefined && settings.scale !== undefined) { + // restore last view + m.lat = settings.lat; + m.lon = settings.lon; + m.scale = settings.scale; + checkMapPos = true; +} // Redraw the whole page function redraw() { g.setClipRect(R.x,R.y,R.x2,R.y2); - m.draw(); + const count = m.draw(); + if (checkMapPos && count === 0) { + // no map at these coordinates, lets try again with first map + m.lat = m.map.lat; + m.lon = m.map.lon; + m.scale = m.map.scale; + m.draw(); + } drawPOI(); drawMarker(); // if track drawing is enabled... @@ -45,7 +61,7 @@ function drawPOI() { g.fillRect(p.x-sz, p.y-sz, p.x+sz, p.y+sz); g.setColor(0,0,0); g.drawString(wp.name, p.x, p.y); - print(wp.name); + //print(wp.name); }) } @@ -59,24 +75,33 @@ function drawMarker() { Bangle.on('GPS',function(f) { fix=f; - if (HASWIDGETS) WIDGETS["sats"].draw(WIDGETS["sats"]); + if (HASWIDGETS && WIDGETS["sats"]) WIDGETS["sats"].draw(WIDGETS["sats"]); if (mapVisible) drawMarker(); }); Bangle.setGPSPower(1, "app"); if (HASWIDGETS) { Bangle.loadWidgets(); - WIDGETS["sats"] = { area:"tl", width:48, draw:w=>{ - var txt = (0|fix.satellites)+" Sats"; - if (!fix.fix) txt += "\nNO FIX"; - g.reset().setFont("6x8").setFontAlign(0,0) - .drawString(txt,w.x+24,w.y+12); - } - }; + if (!WIDGETS["gps"]) { // one GPS Widget is enough + WIDGETS["sats"] = { area:"tl", width:48, draw:w=>{ + var txt = (0|fix.satellites)+" Sats"; + if (!fix.fix) txt += "\nNO FIX"; + g.reset().setFont("6x8").setFontAlign(0,0) + .drawString(txt,w.x+24,w.y+12); + } + }; + } Bangle.drawWidgets(); } R = Bangle.appRect; +function writeSettings() { + settings.lat = m.lat; + settings.lon = m.lon; + settings.scale = m.scale; + require("Storage").writeJSON("openstmap.json",settings); +} + function showMap() { mapVisible = true; g.reset().clearRect(R); @@ -108,7 +133,7 @@ function showMap() { }, /*LANG*/"Draw Track": { value : !!settings.drawTrack, - onchange : v => { settings.drawTrack=v; require("Storage").writeJSON("openstmap.json",settings); } + onchange : v => { settings.drawTrack=v; writeSettings(); } }, /*LANG*/"Center Map": () =>{ m.lat = m.map.lat; @@ -126,3 +151,6 @@ function showMap() { } showMap(); + +// Write settings on exit via button +setWatch(() => writeSettings(), BTN, { repeat: true, edge: "rising" }); diff --git a/apps/openstmap/metadata.json b/apps/openstmap/metadata.json index f4e0f27291..14c789798b 100644 --- a/apps/openstmap/metadata.json +++ b/apps/openstmap/metadata.json @@ -2,7 +2,7 @@ "id": "openstmap", "name": "OpenStreetMap", "shortName": "OpenStMap", - "version": "0.18", + "version": "0.19", "description": "Loads map tiles from OpenStreetMap onto your Bangle.js and displays a map of where you are. Once installed this also adds map functionality to `GPS Recorder` and `Recorder` apps", "readme": "README.md", "icon": "app.png", diff --git a/apps/openstmap/openstmap.js b/apps/openstmap/openstmap.js index 37f82a1275..0a8f35f667 100644 --- a/apps/openstmap/openstmap.js +++ b/apps/openstmap/openstmap.js @@ -37,10 +37,12 @@ m.scale = m.map.scale; // current scale (based on first map) m.lat = m.map.lat; // position of middle of screen m.lon = m.map.lon; // position of middle of screen +// return number of tiles drawn exports.draw = function() { var cx = g.getWidth()/2; var cy = g.getHeight()/2; var p = Bangle.project({lat:m.lat,lon:m.lon}); + let count = 0; m.maps.forEach((map,idx) => { var d = map.scale/m.scale; var ix = (p.x-map.center.x)/m.scale + (map.imgx*d/2) - cx; @@ -68,12 +70,15 @@ exports.draw = function() { } var mx = g.getWidth(); var my = g.getHeight(); - for (var x=ox,ttx=tx; x