openstmap: current position overlay

- Draw a current position marker (Bangle.js 2 only)
- Enable/Disable previous position marker in new setting "Draw cont. position"
pull/2881/head
Erik Andresen 2023-07-14 22:36:38 +02:00
parent e408fb9879
commit 696623c659
3 changed files with 32 additions and 4 deletions

View File

@ -23,4 +23,6 @@
0.19: Remember latitude, longitude & scale
0.20: Make Satellite counter widget 24px wide (was 48)
Move 'Center GPS' to the top of the menu
If 'Recorder' app installed, add a 'Record' menu item
If 'Recorder' app installed, add a 'Record' menu item
0.21: Draw a current position marker (Bangle.js 2 only)
Enable/Disable previous position marker in new setting "Draw cont. position"

View File

@ -25,10 +25,12 @@ function redraw() {
m.lat = m.map.lat;
m.lon = m.map.lon;
m.scale = m.map.scale;
checkMapPos = false;
m.draw();
}
drawPOI();
drawMarker();
drawLocation();
// if track drawing is enabled...
if (settings.drawTrack) {
if (HASWIDGETS && WIDGETS["gpsrec"] && WIDGETS["gpsrec"].plotTrack) {
@ -67,16 +69,35 @@ function drawPOI() {
// Draw the marker for where we are
function drawMarker() {
if (!fix.fix) return;
if (!fix.fix || !settings.drawMarker) return;
var p = m.latLonToXY(fix.lat, fix.lon);
g.setColor(1,0,0);
g.fillRect(p.x-2, p.y-2, p.x+2, p.y+2);
}
// Draw current location with LCD Overlay (Bangle.js 2 only)
function drawLocation() {
if (!Bangle.setLCDOverlay) {
return; // Overlay not supported
}
if (!fix.fix || !mapVisible) {
Bangle.setLCDOverlay(); // clear if map is not visible or no fix
return;
}
const icon = require("heatshrink").decompress(atob("jEYwYPMyVJkgHEkgICyAHCgIIDyQIChIIEoAIDC4IIEBwOAgEEyVIBAY4DBD4sGHxBQIMRAIIPpAyCHAYILUJEAiVJkAIFgVJXo5fCABQA==")); // 24x24px
var p = m.latLonToXY(fix.lat, fix.lon);
Bangle.setLCDOverlay(icon, p.x-24/2, p.y-24);
}
Bangle.on('GPS',function(f) {
fix=f;
if (HASWIDGETS && WIDGETS["sats"]) WIDGETS["sats"].draw(WIDGETS["sats"]);
if (mapVisible) drawMarker();
if (mapVisible) {
drawMarker();
drawLocation();
}
});
Bangle.setGPSPower(1, "app");
@ -105,6 +126,7 @@ function showMenu() {
if (plotTrack && plotTrack.stop)
plotTrack.stop();
mapVisible = false;
drawLocation();
var menu = {
"":{title:/*LANG*/"Map"},
"< Back": ()=> showMap(),
@ -128,6 +150,10 @@ function showMenu() {
value : !!settings.drawTrack,
onchange : v => { settings.drawTrack=v; writeSettings(); }
},
/*LANG*/"Draw cont. position": {
value : !!settings.drawMarker,
onchange : v => { settings.drawMarker=v; writeSettings(); }
},
/*LANG*/"Center Map": () =>{
m.lat = m.map.lat;
m.lon = m.map.lon;

View File

@ -2,7 +2,7 @@
"id": "openstmap",
"name": "OpenStreetMap",
"shortName": "OpenStMap",
"version": "0.20",
"version": "0.21",
"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",