mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-03-13 16:22:59 +00:00
Compare commits
4 Commits
c91baf7c83
...
graphhoppe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01a7ec916e | ||
|
|
dd94a7d613 | ||
|
|
089b88c62d | ||
|
|
a01ca79a82 |
@@ -731,17 +731,7 @@ export class RoutingControls {
|
||||
try {
|
||||
response = await route(targetCoordinates);
|
||||
} catch (e: any) {
|
||||
if (e.message.includes('from-position not mapped in existing datafile')) {
|
||||
toast.error(i18n._('toolbar.routing.error.from'));
|
||||
} else if (e.message.includes('via1-position not mapped in existing datafile')) {
|
||||
toast.error(i18n._('toolbar.routing.error.via'));
|
||||
} else if (e.message.includes('to-position not mapped in existing datafile')) {
|
||||
toast.error(i18n._('toolbar.routing.error.to'));
|
||||
} else if (e.message.includes('Time-out')) {
|
||||
toast.error(i18n._('toolbar.routing.error.timeout'));
|
||||
} else {
|
||||
toast.error(e.message);
|
||||
}
|
||||
toast.error(i18n._(e.message, e.message));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,12 +53,63 @@ const mtbRatingToScale: { [key: string]: string } = {
|
||||
'6': '5',
|
||||
'7': '6',
|
||||
};
|
||||
|
||||
const graphhopperBlockPrivateCustomModels: { [key: string]: any } = {
|
||||
bike: {
|
||||
priority: [
|
||||
{
|
||||
if: 'bike_road_access == PRIVATE',
|
||||
multiply_by: '0.0',
|
||||
},
|
||||
],
|
||||
},
|
||||
racingbike: {
|
||||
priority: [
|
||||
{
|
||||
if: 'bike_road_access == PRIVATE',
|
||||
multiply_by: '0.0',
|
||||
},
|
||||
],
|
||||
},
|
||||
gravelbike: {
|
||||
priority: [
|
||||
{
|
||||
if: 'bike_road_access == PRIVATE',
|
||||
multiply_by: '0.0',
|
||||
},
|
||||
],
|
||||
},
|
||||
mtb: {
|
||||
priority: [
|
||||
{
|
||||
if: 'bike_road_access == PRIVATE',
|
||||
multiply_by: '0.0',
|
||||
},
|
||||
],
|
||||
},
|
||||
foot: {
|
||||
priority: [
|
||||
{
|
||||
if: 'foot_road_access == PRIVATE',
|
||||
multiply_by: '0.0',
|
||||
},
|
||||
],
|
||||
},
|
||||
motorcycle: {
|
||||
priority: [
|
||||
{
|
||||
if: 'road_access == PRIVATE',
|
||||
multiply_by: '0.0',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
async function getGraphHopperRoute(
|
||||
points: Coordinates[],
|
||||
graphHopperProfile: string,
|
||||
privateRoads: boolean
|
||||
): Promise<TrackPoint[]> {
|
||||
let response = await fetch('https://graphhopper-a.gpx.studio/route', {
|
||||
let response = await fetch('https://graphhopper.gpx.studio/route', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -71,19 +122,27 @@ async function getGraphHopperRoute(
|
||||
details: graphhopperDetails,
|
||||
custom_model: privateRoads
|
||||
? {}
|
||||
: {
|
||||
priority: [
|
||||
{
|
||||
if: 'road_access == PRIVATE',
|
||||
multiply_by: '0.0',
|
||||
},
|
||||
],
|
||||
},
|
||||
: graphhopperBlockPrivateCustomModels[graphHopperProfile] || {},
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`${await response.text()}`);
|
||||
const error = await response.json();
|
||||
if (error.message.includes('Cannot find point 0')) {
|
||||
throw new Error('toolbar.routing.error.from');
|
||||
} else if (error.message.includes('Cannot find point 1')) {
|
||||
if (points.length == 3) {
|
||||
throw new Error('toolbar.routing.error.via');
|
||||
} else {
|
||||
throw new Error('toolbar.routing.error.to');
|
||||
}
|
||||
} else if (error.hints[0].details.includes('PointDistanceExceededException')) {
|
||||
throw new Error('toolbar.routing.error.distance');
|
||||
} else if (error.hints[0].details.includes('ConnectionNotFoundException')) {
|
||||
throw new Error('toolbar.routing.error.connection');
|
||||
} else {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
let json = await response.json();
|
||||
@@ -142,7 +201,18 @@ async function getBRouterRoute(
|
||||
let response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`${await response.text()}`);
|
||||
const error = await response.text();
|
||||
if (error.includes('from-position not mapped in existing datafile')) {
|
||||
throw new Error('toolbar.routing.error.from');
|
||||
} else if (error.includes('via1-position not mapped in existing datafile')) {
|
||||
throw new Error('toolbar.routing.error.via');
|
||||
} else if (error.includes('to-position not mapped in existing datafile')) {
|
||||
throw new Error('toolbar.routing.error.to');
|
||||
} else if (error.includes('Time-out')) {
|
||||
throw new Error('toolbar.routing.error.timeout');
|
||||
} else {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
let geojson = await response.json();
|
||||
|
||||
@@ -190,6 +190,8 @@
|
||||
"from": "The start point is too far from the nearest road",
|
||||
"via": "The via point is too far from the nearest road",
|
||||
"to": "The end point is too far from the nearest road",
|
||||
"distance": "The end point is to far from the start point",
|
||||
"connection": "No connection found between the points",
|
||||
"timeout": "Route calculation took too long, try adding points closer together"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user