gipy openstmap: drag, zoom

master
Erik Andresen 2024-08-06 05:45:14 +02:00
parent af61e6eff5
commit 01edc827f3
1 changed files with 58 additions and 27 deletions

View File

@ -1481,10 +1481,11 @@ function start_gipy(path, maps, interests, heights) {
E.showMenu(); // remove menu E.showMenu(); // remove menu
// compute min/max coordinates // compute min/max coordinates
let minLat = 90; const fix = Bangle.getGPSFix();
let maxLat = -90; let minLat = fix.lat ? fix.lat : 90;
let minLong = 180; let maxLat = fix.lat ? fix.lat : -90;
let maxLong = -180; let minLong = fix.lon ? fix.lon : 180;
let maxLong = fix.lon ? fix.lon : -180;
for(let i=0; i<path.len; i++) { for(let i=0; i<path.len; i++) {
const point = path.point(i); const point = path.point(i);
if(point.lat>maxLat) maxLat=point.lat; if(point.lat<minLat) minLat=point.lat; if(point.lat>maxLat) maxLat=point.lat; if(point.lat<minLat) minLat=point.lat;
@ -1499,32 +1500,62 @@ function start_gipy(path, maps, interests, heights) {
osm.scale = Math.ceil((scaleX > scaleY ? scaleX : scaleY)*1.1); // add 10% margin osm.scale = Math.ceil((scaleX > scaleY ? scaleX : scaleY)*1.1); // add 10% margin
osm.lat = (minLat+maxLat)/2.0; osm.lat = (minLat+maxLat)/2.0;
osm.lon = (minLong+maxLong)/2.0; osm.lon = (minLong+maxLong)/2.0;
osm.draw();
// draw track const drawOpenStmap = () => {
g.setColor("#f09"); osm.draw();
for(let i=0; i<path.len; i++) {
const point = path.point(i);
const mp = osm.latLonToXY(point.lat, point.lon);
g.lineTo(mp.x,mp.y);
g.fillCircle(mp.x,mp.y,2); // make the track more visible
}
// draw current position // draw track
g.setColor("#000"); g.setColor("#f09");
if (Bangle.getGPSFix().lat && Bangle.getGPSFix().lon) { for(let i=0; i<path.len; i++) {
const icon = require("heatshrink").decompress(atob("jEYwYPMyVJkgHEkgICyAHCgIIDyQIChIIEoAIDC4IIEBwOAgEEyVIBAY4DBD4sGHxBQIMRAIIPpAyCHAYILUJEAiVJkAIFgVJXo5fCABQA==")); // 24x24px const point = path.point(i);
const mp = osm.latLonToXY(Bangle.getGPSFix().lat, Bangle.getGPSFix().lon); const mp = osm.latLonToXY(point.lat, point.lon);
g.drawImage(icon, mp.x, mp.y); g.lineTo(mp.x,mp.y);
} g.fillCircle(mp.x,mp.y,2); // make the track more visible
}
// back handling // draw current position
g.setFont("6x8",2); g.setColor("#000");
g.setFontAlign(0,0,3); if (fix.lat && fix.lon) {
g.drawString(/*LANG*/"Back", g.getWidth() - 10, g.getHeight()/2); const icon = require("heatshrink").decompress(atob("jEYwYPMyVJkgHEkgICyAHCgIIDyQIChIIEoAIDC4IIEBwOAgEEyVIBAY4DBD4sGHxBQIMRAIIPpAyCHAYILUJEAiVJkAIFgVJXo5fCABQA==")); // 24x24px
setWatch(function() { const mp = osm.latLonToXY(fix.lat, fix.lon);
E.showMenu(menu); g.drawImage(icon, mp.x, mp.y);
}, BTN1, {edge:"falling"}); }
// labels
g.setFont("6x8",2);
g.setFontAlign(0,0,3);
g.drawString(/*LANG*/"Back", g.getWidth() - 10, g.getHeight()/2);
g.drawString("+", g.getWidth() - 10, g.getHeight()/4);
g.drawString("-", g.getWidth() - 10, g.getHeight()/4*3);
};
drawOpenStmap();
let startDrag = 0;
Bangle.setUI({
mode: "custom",
btn: (n) => { // back handling
E.showMenu(menu);
},
drag: (ev) => { // zoom, move
if (ev.b) {
osm.scroll(ev.dx, ev.dy);
if (!startDrag) {
startDrag = getTime();
}
} else {
if (getTime() - startDrag < 0.2) {
// tap
if (ev.y > g.getHeight() / 2) {
osm.scale *= 2;
} else {
osm.scale /= 2;
}
}
startDrag = 0;
drawOpenStmap();
}
},
});
}; };
} catch (ex) { } catch (ex) {
// openstmap not available. // openstmap not available.