openstmap: Fix rounding errors

pull/3169/head
Erik Andresen 2024-01-27 10:15:31 +01:00
parent e5c9286e77
commit 56b39fead9
5 changed files with 17 additions and 8 deletions

View File

@ -32,3 +32,4 @@
0.25: Enable scaled image filtering on 2v19+ firmware
0.26: Ensure that when redrawing, we always cancel any in-progress track draw
0.27: Display message if no map is installed
0.28: Fix rounding errors

View File

@ -65,14 +65,16 @@ function redraw() {
// Draw the POIs
function drawPOI() {
let waypoints;
try {
var waypoints = require("waypoints").load();
waypoints = require("waypoints").load();
} catch (ex) {
// Waypoints module not available.
return;
}
g.setFont("Vector", 18);
waypoints.forEach((wp, idx) => {
if (wp.lat === undefined || wp.lon === undefined) return;
var p = m.latLonToXY(wp.lat, wp.lon);
var sz = 2;
g.setColor(0,0,0);
@ -80,7 +82,7 @@ function drawPOI() {
g.setColor(0,0,0);
g.drawString(wp.name, p.x, p.y);
//print(wp.name);
})
});
}
function isInside(rect, e, w, h) {

View File

@ -45,7 +45,11 @@
<div id="map">
</div>
<div id="controls">
<div style="display:inline-block;text-align:center;vertical-align: top;" id="3bitdiv"> <input type="checkbox" id="3bit"></input><br/><span>3 bit</span></div>
<div style="display:inline-block;text-align:left;vertical-align: top;" id="3bitdiv">
<input type="checkbox" id="3bit"></input><span>3 bit</span>
<br>
<input type="checkbox" id="preview"><span>Preview</span>
</div>
<div class="form-group" style="display:inline-block;">
<select class="form-select" id="mapSize">
<option value="4">Small (4x4)</option>
@ -275,7 +279,9 @@ TODO:
options.width = TILESIZE;
options.height = TILESIZE;
var imgstr = imageconverter.RGBAtoString(rgba, options);
//ctx.putImageData(imageData,x*TILESIZE, y*TILESIZE); // write preview
if (document.getElementById("preview").checked) {
ctx.putImageData(imageData,x*TILESIZE, y*TILESIZE); // write preview
}
/*var compress = 'require("heatshrink").decompress('
if (!imgstr.startsWith(compress)) throw "Data in wrong format";
imgstr = imgstr.slice(compress.length,-1);*/

View File

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

View File

@ -76,7 +76,7 @@ exports.draw = function() {
for (var x=ox,ttx=tx; x<mx && ttx<map.w; x+=s,ttx++) {
for (var y=oy,tty=ty;y<my && tty<map.h;y+=s,tty++) {
o.frame = ttx+(tty*map.w);
g.drawImage(img,x,y,o);
g.drawImage(img,Math.round(x),Math.round(y),o);
count++;
}
}
@ -91,8 +91,8 @@ exports.latLonToXY = function(lat, lon) {
var cx = g.getWidth()/2;
var cy = g.getHeight()/2;
return {
x : (q.x-p.x)/m.scale + cx,
y : cy - (q.y-p.y)/m.scale
x : Math.round((q.x-p.x)/m.scale + cx),
y : Math.round(cy - (q.y-p.y)/m.scale)
};
};