From 555dc0de38e39e63a0f52e94d802e142146259c0 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 20 Sep 2023 22:13:36 +0200 Subject: [PATCH] avoid large gps_accuracy for larger distances --- src/api/Api.ts | 17 ++++++++++++----- src/layers/UsePathsLayer.tsx | 1 - 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/Api.ts b/src/api/Api.ts index d2f1575b..ba8bfaa7 100644 --- a/src/api/Api.ts +++ b/src/api/Api.ts @@ -16,8 +16,7 @@ import { import { LineString } from 'geojson' import { getTranslation, tr } from '@/translation/Translation' import * as config from 'config' -import { request } from 'config' -import { lessThanOrEqualTo } from 'ol/format/filter' +import { calcDist } from '@/distUtils' interface ApiProfile { name: string @@ -119,9 +118,17 @@ export class ApiImpl implements Api { const url = new URL(this.routingApi + 'match') url.searchParams.append('key', this.apiKey) - // TODO NOW avoid large distances and large gps_accuracy -> measure distances? - // another problem is that response times for outdoor vehicles and larger gps_accuracy values are too slow - url.searchParams.append('gps_accuracy', ApiImpl.isMotorVehicle(args.profile) ? '160' : '50') + // avoid large distances and large gps_accuracy + let largeDistanceFactor = 1 + if (args.points.length >= 2) { + const p0 = { lat: args.points[0][1], lng: args.points[0][0] } + const p1 = { lat: args.points[1][1], lng: args.points[1][0] } + if (calcDist(p0, p1) > 1_500) largeDistanceFactor = 2 + } + + // another problem is that response times for outdoor vehicles and larger gps_accuracy values are too slow + const gpsAccuracy = ApiImpl.isMotorVehicle(args.profile) ? 160 : 50 + url.searchParams.append('gps_accuracy', '' + gpsAccuracy / largeDistanceFactor) url.searchParams.append('profile', args.profile) url.searchParams.append('elevation', 'true') diff --git a/src/layers/UsePathsLayer.tsx b/src/layers/UsePathsLayer.tsx index 4fa9f67a..007cfe37 100644 --- a/src/layers/UsePathsLayer.tsx +++ b/src/layers/UsePathsLayer.tsx @@ -122,7 +122,6 @@ function addHandDrawQueryPointLayer(map: Map) { let zoom = map.getView().getZoom() // not sure how to do this with coords.filter for (let idx = 1; idx < coords.length; idx++) { - // TODO NOW find a better way!? // Now skip certain locations depending on the distance (which is zoom-dependent) if (calcDist(prevCoord, coords[idx]) > 6000 / (zoom ? zoom : 10)) {