Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gipy: new release with bugfixes #2852

Merged
merged 7 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/gipy/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@
0.18:
* Major rewrite of display : now tile based
* We have a map. Never get lost again.

0.19:
* Several fixes for osm requests and map computations
* Display path in leaflet
* Reduce framerate if locked
* Stroke to move around in the map
* Fix for missing paths in display
72 changes: 42 additions & 30 deletions apps/gipy/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class Map {
let local_y = displayed_y - this.start_coordinates[1];
let tile_x = Math.floor(local_x / this.side);
let tile_y = Math.floor(local_y / this.side);

let limit = 1;
if (!zoomed) {
limit = 2;
Expand All @@ -266,6 +267,18 @@ class Map {
sin_direction
)
) {
// let colors = [
// [0, 0, 0],
// [0, 0, 1],
// [0, 1, 0],
// [0, 1, 1],
// [1, 0, 0],
// [1, 0, 1],
// [1, 1, 0],
// [1, 1, 0.5],
// [0.5, 0, 0.5],
// [0, 0.5, 0.5],
// ];
if (this.color[0] == 1 && this.color[1] == 0 && this.color[2] == 0) {
this.display_thick_tile(
x,
Expand Down Expand Up @@ -301,33 +314,32 @@ class Map {
cos_direction,
sin_direction
) {
let center_x = g.getWidth() / 2;
let center_y = g.getHeight() / 2 + Y_OFFSET;
let width = g.getWidth();
let height = g.getHeight();
let center_x = width / 2;
let center_y = height / 2 + Y_OFFSET;
let side = this.side;
let x1 = tile_x * side;
let y1 = tile_y * side;
let x2 = x1 + side;
let y2 = y1 + side;
let scaled_x1 = (x1 - current_x) * scale_factor;
let scaled_y1 = (y1 - current_y) * scale_factor;
let rotated_x1 = scaled_x1 * cos_direction - scaled_y1 * sin_direction;
let rotated_y1 = scaled_x1 * sin_direction + scaled_y1 * cos_direction;
let scaled_x2 = (x2 - current_x) * scale_factor;
let scaled_y2 = (y2 - current_y) * scale_factor;
let rotated_x2 = scaled_x2 * cos_direction - scaled_y2 * sin_direction;
let rotated_y2 = scaled_x2 * sin_direction + scaled_y2 * cos_direction;

if (center_x < rotated_x1 && center_x < rotated_x2) {
let tile_center_x = (tile_x + 0.5) * side;
let tile_center_y = (tile_y + 0.5) * side;
let scaled_center_x = (tile_center_x - current_x) * scale_factor;
let scaled_center_y = (tile_center_y - current_y) * scale_factor;
let rotated_center_x = scaled_center_x * cos_direction - scaled_center_y * sin_direction;
let rotated_center_y = scaled_center_x * sin_direction + scaled_center_y * cos_direction;
let on_screen_center_x = center_x - rotated_center_x;
let on_screen_center_y = center_y + rotated_center_y;

let scaled_side = side * scale_factor * Math.sqrt(1/2);

if (on_screen_center_x + scaled_side <= 0) {
return false;
}
if (-center_x > rotated_x1 && -center_x > rotated_x2) {
if (on_screen_center_x - scaled_side >= width) {
return false;
}

if (center_y < rotated_y1 && center_y < rotated_y2) {
if (on_screen_center_y + scaled_side <= 0) {
return false;
}
if (-center_y > rotated_y1 && -center_y > rotated_y2) {
if (on_screen_center_y - scaled_side >= height) {
return false;
}
return true;
Expand Down Expand Up @@ -652,8 +664,8 @@ class Status {
} else {
let previous_point = this.old_points[this.old_points.length - 1];
let distance_to_previous = previous_point.distance(position);
// gps signal is noisy but rarely above 4 meters
if (distance_to_previous < 4) {
// gps signal is noisy but rarely above 5 meters
if (distance_to_previous < 5) {
return null;
}
}
Expand Down Expand Up @@ -725,12 +737,6 @@ class Status {
// console.log("we are not late");
// }

// // abort most frames if locked
// if (Bangle.isLocked() && this.gps_coordinates_counter % 5 != 0) {
// console.log("we are filtered");
// return;
// }

if (this.path !== null) {
// detect segment we are on now
let res = this.path.nearest_segment(
Expand Down Expand Up @@ -803,6 +809,12 @@ class Status {
}
}
}

// abort most frames if locked
if (Bangle.isLocked() && this.gps_coordinates_counter % 5 != 0) {
return;
}

// re-display
this.display();
}
Expand Down Expand Up @@ -1391,8 +1403,8 @@ function start_gipy(path, maps, interests) {
let s = status.adjusted_sin_direction;
let rotated_x = xdiff * c - ydiff * s;
let rotated_y = xdiff * s + ydiff * c;
status.displayed_x += rotated_x / ((status.scale_factor * 4) / 3);
status.displayed_y -= rotated_y / ((status.scale_factor * 4) / 3);
status.displayed_position.lon += 1.3 * rotated_x / status.scale_factor;
status.displayed_position.lat -= 1.3 * rotated_y / status.scale_factor;
status.display();
});

Expand Down
17 changes: 15 additions & 2 deletions apps/gipy/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
document.getElementById('upload').disabled = true;
if (displayed_polygon !== null) {
displayed_polygon.remove();
}
if (displayed_path !== null) {
displayed_path.remove();
}
let polygon = get_polygon(gps_data);
let min_lat = polygon[0];
Expand All @@ -97,11 +100,21 @@
}
}
displayed_polygon = L.polygon(map_polygon).addTo(map);

let polyline = get_polyline(gps_data);
if (polyline.length > 0) {
let map_polyline = [];
for (let i = 0 ; i < polyline.length ; i+= 2) {
map_polyline.push([polyline[i], polyline[i+1]]);
}
displayed_path = L.polyline(map_polyline, {color: 'red'}).addTo(map);
}

map.fitBounds(L.latLngBounds(L.latLng(min_lat, min_lng), L.latLng(max_lat, max_lng)));
document.getElementById('convert').disabled = false;
}

import init, { load_gps_from_string, get_polygon, request_map, get_gps_content, get_gps_map_svg, gps_from_area } from "./pkg/gps.js";
import init, { load_gps_from_string, get_polygon, get_polyline, request_map, get_gps_content, get_gps_map_svg, gps_from_area } from "./pkg/gps.js";
console.log("imported wasm");

// start map
Expand Down Expand Up @@ -138,6 +151,7 @@
let gps_filename = null;
let gps_content = null;
let displayed_polygon = null;
let displayed_path = null;

init().then(() => {

Expand Down Expand Up @@ -200,7 +214,6 @@
status.innerHTML = "file converted";
gps_content = get_gps_content(gps_data);
let svg_string = get_gps_map_svg(gps_data);
console.log("svg string is", svg_string);
let img = document.getElementById("svgmap");
img.innerHTML = svg_string;
if (gps_filename !== null) {
Expand Down
2 changes: 1 addition & 1 deletion apps/gipy/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "gipy",
"name": "Gipy",
"shortName": "Gipy",
"version": "0.18",
"version": "0.19",
"description": "Follow gpx files using the gps. Don't get lost in your bike trips and hikes.",
"allow_emulator":false,
"icon": "gipy.png",
Expand Down
20 changes: 13 additions & 7 deletions apps/gipy/pkg/gps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
/* eslint-disable */
/**
* @param {Gps} gps
* @returns {string}
*/
export function get_gps_map_svg(gps: Gps): string;
/**
* @param {Gps} gps
* @returns {Float64Array}
*/
export function get_polygon(gps: Gps): Float64Array;
/**
* @param {Gps} gps
* @returns {Uint8Array}
* @returns {Float64Array}
*/
export function get_gps_content(gps: Gps): Uint8Array;
export function get_polyline(gps: Gps): Float64Array;
/**
* @param {Gps} gps
* @returns {string}
* @returns {Uint8Array}
*/
export function get_gps_map_svg(gps: Gps): string;
export function get_gps_content(gps: Gps): Uint8Array;
/**
* @param {Gps} gps
* @param {string} key1
Expand Down Expand Up @@ -52,20 +57,21 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_gps_free: (a: number) => void;
readonly get_gps_map_svg: (a: number, b: number) => void;
readonly get_polygon: (a: number, b: number) => void;
readonly get_polyline: (a: number, b: number) => void;
readonly get_gps_content: (a: number, b: number) => void;
readonly get_gps_map_svg: (a: number, b: number) => void;
readonly request_map: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number) => number;
readonly load_gps_from_string: (a: number, b: number) => number;
readonly gps_from_area: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h6bb6801698d941c0: (a: number, b: number, c: number) => void;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hab13c10d53cd1c5a: (a: number, b: number, c: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
readonly __wbindgen_exn_store: (a: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h33169a25550cd50b: (a: number, b: number, c: number, d: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__h26ce002f44a5439b: (a: number, b: number, c: number, d: number) => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
Expand Down
Loading