gpstrek - Simplify code for detecting next/last
parent
95d9fd3195
commit
a43840f5ba
|
|
@ -411,11 +411,12 @@ let getMapSlice = function(){
|
||||||
if (currentPosFromGPS) {
|
if (currentPosFromGPS) {
|
||||||
let pos = graphics.transformVertices([ startingPoint.x - current.x, (startingPoint.y - current.y)*-1 ], mapTrans);
|
let pos = graphics.transformVertices([ startingPoint.x - current.x, (startingPoint.y - current.y)*-1 ], mapTrans);
|
||||||
|
|
||||||
|
if (!isMapOverview){
|
||||||
if (pos[0] < x) { pos[0] = x + errorMarkerSize + 5; graphics.setColor(1,0,0).fillRect(x,y,x+errorMarkerSize,y+height);}
|
if (pos[0] < x) { pos[0] = x + errorMarkerSize + 5; graphics.setColor(1,0,0).fillRect(x,y,x+errorMarkerSize,y+height);}
|
||||||
if (pos[0] > x + width) {pos[0] = x + width - errorMarkerSize - 5; graphics.setColor(1,0,0).fillRect(x + width - errorMarkerSize,y,x + width ,y+height);}
|
if (pos[0] > x + width) {pos[0] = x + width - errorMarkerSize - 5; graphics.setColor(1,0,0).fillRect(x + width - errorMarkerSize,y,x + width ,y+height);}
|
||||||
if (pos[1] < y) {pos[1] = y + errorMarkerSize + 5; graphics.setColor(1,0,0).fillRect(x,y,x + width,y+errorMarkerSize);}
|
if (pos[1] < y) {pos[1] = y + errorMarkerSize + 5; graphics.setColor(1,0,0).fillRect(x,y,x + width,y+errorMarkerSize);}
|
||||||
if (pos[1] > y + height - interfaceHeight -1) { pos[1] = y + height - errorMarkerSize - 5-interfaceHeight-1; graphics.setColor(1,0,0).fillRect(x,y + height - errorMarkerSize-interfaceHeight-1,x + width ,y+height-interfaceHeight-1);}
|
if (pos[1] > y + height - interfaceHeight -1) { pos[1] = y + height - errorMarkerSize - 5-interfaceHeight-1; graphics.setColor(1,0,0).fillRect(x,y + height - errorMarkerSize-interfaceHeight-1,x + width ,y+height-interfaceHeight-1);}
|
||||||
|
}
|
||||||
|
|
||||||
if (isMapOverview) {
|
if (isMapOverview) {
|
||||||
graphics.drawImage(arrow, pos[0],pos[1], {rotate: require("graphics_utils").degreesToRadians(course)});
|
graphics.drawImage(arrow, pos[0],pos[1], {rotate: require("graphics_utils").degreesToRadians(course)});
|
||||||
|
|
@ -483,12 +484,14 @@ let getMapSlice = function(){
|
||||||
let toDraw;
|
let toDraw;
|
||||||
let named = [];
|
let named = [];
|
||||||
for (let j = 0; j < SETTINGS.mapChunkSize; j++){
|
for (let j = 0; j < SETTINGS.mapChunkSize; j++){
|
||||||
|
data.i = data.i + (reverse?-1:1);
|
||||||
let p = get(route, data.i);
|
let p = get(route, data.i);
|
||||||
if (!p || !p.lat) {
|
if (!p || !p.lat) {
|
||||||
|
data.i = data.i + (reverse?1:-1);
|
||||||
data.breakLoop = true;
|
data.breakLoop = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (data.maxWaypoints && Math.abs(data.i) > data.maxWaypoints) {
|
if (data.maxWaypoints && Math.abs(startingIndex - data.i) > data.maxWaypoints) {
|
||||||
data.breakLoop = true;
|
data.breakLoop = true;
|
||||||
last = true;
|
last = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -497,9 +500,8 @@ let getMapSlice = function(){
|
||||||
if (p.name) named.push({i:data.poly.length,n:p.name});
|
if (p.name) named.push({i:data.poly.length,n:p.name});
|
||||||
data.poly.push(startingPoint.x-toDraw.x);
|
data.poly.push(startingPoint.x-toDraw.x);
|
||||||
data.poly.push((startingPoint.y-toDraw.y)*-1);
|
data.poly.push((startingPoint.y-toDraw.y)*-1);
|
||||||
if (j < SETTINGS.mapChunkSize - 1) data.i = data.i + (reverse?-1:1);
|
|
||||||
}
|
}
|
||||||
finish = isLast(route, data.i - 1);
|
finish = isLast(route, getWaypointIndex(route, data.i));
|
||||||
|
|
||||||
data.poly = graphics.transformVertices(data.poly, mapTrans);
|
data.poly = graphics.transformVertices(data.poly, mapTrans);
|
||||||
graphics.drawPoly(data.poly, false);
|
graphics.drawPoly(data.poly, false);
|
||||||
|
|
@ -536,8 +538,8 @@ let getMapSlice = function(){
|
||||||
addToTaskQueue(drawChunk, data);
|
addToTaskQueue(drawChunk, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
drawPath(true, currentRouteIndex);
|
drawPath(true, currentRouteIndex+1);
|
||||||
drawPath(false, currentRouteIndex);
|
drawPath(false, currentRouteIndex-1);
|
||||||
|
|
||||||
addToTaskQueue(drawInterface);
|
addToTaskQueue(drawInterface);
|
||||||
|
|
||||||
|
|
@ -997,14 +999,14 @@ let hasPrev = function(route, index){
|
||||||
let hasNext = function(route, index, count){
|
let hasNext = function(route, index, count){
|
||||||
if (!count) count = 1;
|
if (!count) count = 1;
|
||||||
if (isNaN(index)) index = route.index;
|
if (isNaN(index)) index = route.index;
|
||||||
return getWaypointIndex(route, index) + count < (getRouteIndex(route).length - 1);
|
return getWaypointIndex(route, index) + count < (getRouteIndex(route).length);
|
||||||
};
|
};
|
||||||
|
|
||||||
let getNext = function(route, index, count){
|
let getNext = function(route, index, count){
|
||||||
if (!count) count = 1;
|
if (!count) count = 1;
|
||||||
if (isNaN(index)) index = getWaypointIndex(route);
|
if (isNaN(index)) index = getWaypointIndex(route);
|
||||||
index += count;
|
index += count;
|
||||||
if (index >= getRouteIndex(route).length) return;
|
if (index >= getRouteIndex(route).length || index < 0) return;
|
||||||
let result = {};
|
let result = {};
|
||||||
getEntry(route.filename, getRouteIndex(route)[getWaypointIndex(route, index)], result);
|
getEntry(route.filename, getRouteIndex(route)[getWaypointIndex(route, index)], result);
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -1031,13 +1033,7 @@ let setWaypointIndex = function(route, waypointIndex){
|
||||||
};
|
};
|
||||||
|
|
||||||
let getPrev = function(route, index){
|
let getPrev = function(route, index){
|
||||||
if (isNaN(index)) index = getWaypointIndex(route);
|
return getNext(route, index, -1);
|
||||||
if (!hasPrev(route, index)) return;
|
|
||||||
if (route.mirror) ++index;
|
|
||||||
if (!route.mirror) --index;
|
|
||||||
let result = {};
|
|
||||||
getEntry(route.filename, getIndex(route)[index], result);
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let next = function(route){
|
let next = function(route){
|
||||||
|
|
@ -1052,8 +1048,7 @@ let set = function(route, index){
|
||||||
|
|
||||||
let prev = function(route){
|
let prev = function(route){
|
||||||
if (!hasPrev(route)) return;
|
if (!hasPrev(route)) return;
|
||||||
if (route.mirror) set(route, ++route.index);
|
set(route, getWaypointIndex(route)-1);
|
||||||
if (!route.mirror) set(route, --route.index);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let getLast = function(route){
|
let getLast = function(route){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue