mirror of https://github.com/espruino/BangleApps
draw the user when gps fixed
parent
0fea3dd850
commit
bbcf98edad
|
@ -19,7 +19,8 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const url = "https://overpass-api.de/api/interpreter";
|
const url = "https://overpass-api.de/api/interpreter";
|
||||||
let query = `[bbox:37.4829,-122.8694,39.7110,-120.6215][out:json][timeout:5];way["name"="El Macero Country Club"];map_to_area ->.golfcourse;way["golf"="hole"](area.golfcourse)->.holes;(relation["golf"="fairway"](area.golfcourse);way["golf"~"^(green|tee|water_hazard|bunker|fairway)"](area.golfcourse);)->.features;.holes out geom;.features out geom;`;
|
//let query = `[bbox:37.4829,-122.8694,39.7110,-120.6215][out:json][timeout:5];way["name"="El Macero Country Club"];map_to_area ->.golfcourse;way["golf"="hole"](area.golfcourse)->.holes;(relation["golf"="fairway"](area.golfcourse);way["golf"~"^(green|tee|water_hazard|bunker|fairway)"](area.golfcourse);)->.features;.holes out geom;.features out geom;`;
|
||||||
|
let query = `[bbox:37.4829,-122.8694,39.7110,-120.6215][out:json][timeout:5];way["name"="Davis Golf Course"];map_to_area ->.golfcourse;way["golf"="hole"](area.golfcourse)->.holes;(relation["golf"="fairway"](area.golfcourse);way["golf"~"^(green|tee|water_hazard|bunker|fairway)"](area.golfcourse);)->.features;.holes out geom;.features out geom;`;
|
||||||
let course_input = null;
|
let course_input = null;
|
||||||
|
|
||||||
function processFeatures(course_verbose) {
|
function processFeatures(course_verbose) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ const EARTHRADIUS = 6371000; //km
|
||||||
function radians(a) {
|
function radians(a) {
|
||||||
return a * Math.PI / 180;
|
return a * Math.PI / 180;
|
||||||
}
|
}
|
||||||
|
position
|
||||||
function degrees(a) {
|
function degrees(a) {
|
||||||
let d = a * 180 / Math.PI;
|
let d = a * 180 / Math.PI;
|
||||||
return (d + 360) % 360;
|
return (d + 360) % 360;
|
||||||
|
@ -64,9 +64,17 @@ let user_position = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
to_hole: 0,
|
to_hole: 0,
|
||||||
last_time: getTime()
|
last_time: getTime(),
|
||||||
|
transform: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function drawUser() {
|
||||||
|
if(!user_position.fix) return;
|
||||||
|
let new_pos = g.transformVertices([user_position.x,user_position.y],user_position.transform);
|
||||||
|
g.setColor(g.theme.fg);
|
||||||
|
g.drawCircle(new_pos[0],new_pos[1],8);
|
||||||
|
}
|
||||||
|
|
||||||
function drawHole(l) {
|
function drawHole(l) {
|
||||||
|
|
||||||
//console.log(l);
|
//console.log(l);
|
||||||
|
@ -84,6 +92,8 @@ function drawHole(l) {
|
||||||
rotate: hole.angle - Math.PI / 2.0, // angle in radians (default 0)
|
rotate: hole.angle - Math.PI / 2.0, // angle in radians (default 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
user_position.transform = transform;
|
||||||
|
|
||||||
// draw the fairways first
|
// draw the fairways first
|
||||||
hole.features.sort((a, b) => {
|
hole.features.sort((a, b) => {
|
||||||
if (a.type === "fairway") {
|
if (a.type === "fairway") {
|
||||||
|
@ -117,6 +127,8 @@ function drawHole(l) {
|
||||||
g.fillPoly(newnodelist, true);
|
g.fillPoly(newnodelist, true);
|
||||||
//console.log(feature.type);
|
//console.log(feature.type);
|
||||||
//console.log(newnodelist);
|
//console.log(newnodelist);
|
||||||
|
|
||||||
|
drawUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
var waynodelist = [];
|
var waynodelist = [];
|
||||||
|
@ -141,12 +153,12 @@ function setHole(current_hole) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDistanceToHole() {
|
function updateDistanceToHole() {
|
||||||
let xy = toXY({ "lat": user_position.lat, "lon": user_position.lon }, hole.way[hole.way.length - 1]);
|
let xy = toXY({ "lat": user_position.lat, "lon": user_position.lon }, hole.way[0]);
|
||||||
user_position.x = xy.x;
|
user_position.x = xy.x;
|
||||||
user_position.y = xy.y;
|
user_position.y = xy.y;
|
||||||
user_position.last_time = getTime();
|
user_position.last_time = getTime();
|
||||||
let new_distance = Math.round(distance(xy, hole.nodesXY[hole.nodesXY.length - 1]) * 1.093613); //TODO meters later
|
let new_distance = Math.round(distance(xy, hole.nodesXY[hole.nodesXY.length - 1]) * 1.093613); //TODO meters later
|
||||||
console.log(new_distance);
|
//console.log(new_distance);
|
||||||
layout.measyardage.label = (new_distance < 999) ? new_distance : "---";
|
layout.measyardage.label = (new_distance < 999) ? new_distance : "---";
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
|
@ -169,11 +181,12 @@ Bangle.on('swipe', function (direction) {
|
||||||
|
|
||||||
Bangle.on('GPS', (fix) => {
|
Bangle.on('GPS', (fix) => {
|
||||||
if (isNaN(fix.lat)) return;
|
if (isNaN(fix.lat)) return;
|
||||||
console.log(fix.hdop * 5); //precision
|
//console.log(fix.hdop * 5); //precision
|
||||||
user_position.fix = true;
|
user_position.fix = true;
|
||||||
user_position.lat = fix.lat;
|
user_position.lat = fix.lat;
|
||||||
user_position.lon = fix.lon;
|
user_position.lon = fix.lon;
|
||||||
updateDistanceToHole();
|
updateDistanceToHole();
|
||||||
|
drawUser();
|
||||||
});
|
});
|
||||||
|
|
||||||
// The layout, referencing the custom renderer
|
// The layout, referencing the custom renderer
|
||||||
|
|
Loading…
Reference in New Issue