gipy openstmap: drag, zoom
parent
af61e6eff5
commit
01edc827f3
|
|
@ -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,6 +1500,8 @@ 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;
|
||||||
|
|
||||||
|
const drawOpenStmap = () => {
|
||||||
osm.draw();
|
osm.draw();
|
||||||
|
|
||||||
// draw track
|
// draw track
|
||||||
|
|
@ -1512,19 +1515,47 @@ function start_gipy(path, maps, interests, heights) {
|
||||||
|
|
||||||
// draw current position
|
// draw current position
|
||||||
g.setColor("#000");
|
g.setColor("#000");
|
||||||
if (Bangle.getGPSFix().lat && Bangle.getGPSFix().lon) {
|
if (fix.lat && fix.lon) {
|
||||||
const icon = require("heatshrink").decompress(atob("jEYwYPMyVJkgHEkgICyAHCgIIDyQIChIIEoAIDC4IIEBwOAgEEyVIBAY4DBD4sGHxBQIMRAIIPpAyCHAYILUJEAiVJkAIFgVJXo5fCABQA==")); // 24x24px
|
const icon = require("heatshrink").decompress(atob("jEYwYPMyVJkgHEkgICyAHCgIIDyQIChIIEoAIDC4IIEBwOAgEEyVIBAY4DBD4sGHxBQIMRAIIPpAyCHAYILUJEAiVJkAIFgVJXo5fCABQA==")); // 24x24px
|
||||||
const mp = osm.latLonToXY(Bangle.getGPSFix().lat, Bangle.getGPSFix().lon);
|
const mp = osm.latLonToXY(fix.lat, fix.lon);
|
||||||
g.drawImage(icon, mp.x, mp.y);
|
g.drawImage(icon, mp.x, mp.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// back handling
|
// labels
|
||||||
g.setFont("6x8",2);
|
g.setFont("6x8",2);
|
||||||
g.setFontAlign(0,0,3);
|
g.setFontAlign(0,0,3);
|
||||||
g.drawString(/*LANG*/"Back", g.getWidth() - 10, g.getHeight()/2);
|
g.drawString(/*LANG*/"Back", g.getWidth() - 10, g.getHeight()/2);
|
||||||
setWatch(function() {
|
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);
|
E.showMenu(menu);
|
||||||
}, BTN1, {edge:"falling"});
|
},
|
||||||
|
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.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue