Skip to content

Commit a1fc70e

Browse files
committed
move helper/utils out of QueryStore into utils.ts
1 parent 09438a5 commit a1fc70e

File tree

15 files changed

+99
-115
lines changed

15 files changed

+99
-115
lines changed

config.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ const config = {
6363
// { profile: 'racingbike' },
6464
// { profile: 'ecargobike' }
6565
// ]
66-
// },
67-
// truck: {
68-
// options: [
69-
// { profile: 'small_truck' },
70-
// { profile: 'truck' }
71-
// ]
72-
// },
73-
// foot: {
74-
// options: [
75-
// { profile: 'foot' },
76-
// { profile: 'hike' }
77-
// ]
7866
// }
7967
// }
8068
}

src/Converters.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { GeocodingHit } from '@/api/graphhopper'
2-
3-
import { Coordinate } from '@/stores/QueryStore'
2+
import { Coordinate } from '@/utils'
43

54
export function milliSecondsToText(ms: number) {
65
const hours = Math.floor(ms / 3600000)

src/NavBar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import Dispatcher from '@/stores/Dispatcher'
33
import { ClearPoints, SelectMapLayer, SetBBox, SetQueryPoints, SetVehicleProfile } from '@/actions/Actions'
44
// import the window like this so that it can be mocked during testing
55
import { window } from '@/Window'
6-
import QueryStore, { getBBoxFromCoord, QueryPoint, QueryPointType, QueryStoreState } from '@/stores/QueryStore'
6+
import QueryStore, { QueryPoint, QueryPointType, QueryStoreState } from '@/stores/QueryStore'
77
import MapOptionsStore, { MapOptionsStoreState } from './stores/MapOptionsStore'
8-
import { ApiImpl, getApi } from '@/api/Api'
8+
import { getApi } from '@/api/Api'
99
import { AddressParseResult } from '@/pois/AddressParseResult'
10-
import { getQueryStore } from '@/stores/Stores'
10+
import { getBBoxFromCoord, getBBoxPoints } from '@/utils'
1111

1212
export default class NavBar {
1313
private readonly queryStore: QueryStore
@@ -159,7 +159,7 @@ export default class NavBar {
159159
const bbox =
160160
initializedPoints.length == 1
161161
? getBBoxFromCoord(initializedPoints[0].coordinate)
162-
: ApiImpl.getBBoxPoints(initializedPoints.map(p => p.coordinate))
162+
: getBBoxPoints(initializedPoints.map(p => p.coordinate))
163163
if (bbox) Dispatcher.dispatch(new SetBBox(bbox))
164164
return Dispatcher.dispatch(new SetQueryPoints(points))
165165
}

src/actions/Actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Action } from '@/stores/Dispatcher'
2-
import { Coordinate, QueryPoint } from '@/stores/QueryStore'
2+
import { QueryPoint } from '@/stores/QueryStore'
33
import { ApiInfo, Bbox, Path, RoutingArgs, RoutingProfile, RoutingResult } from '@/api/graphhopper'
44
import { PathDetailsPoint } from '@/stores/PathDetailsStore'
55
import { POI } from '@/stores/POIsStore'
66
import { Settings } from '@/stores/SettingsStore'
7+
import { Coordinate } from '@/utils'
78

89
export class InfoReceived implements Action {
910
readonly result: ApiInfo

src/api/Api.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
import { LineString } from 'geojson'
1818
import { getTranslation, tr } from '@/translation/Translation'
1919
import * as config from 'config'
20-
import { Coordinate } from '@/stores/QueryStore'
2120
import { POIQuery } from '@/pois/AddressParseResult'
2221

2322
interface ApiProfile {
@@ -445,7 +444,7 @@ export class ApiImpl implements Api {
445444

446445
public static isMotorVehicle(profile: string) {
447446
return (
448-
profile.includes('car') && !profile.includes('cargobike') ||
447+
(profile.includes('car') && !profile.includes('cargobike')) ||
449448
profile.includes('truck') ||
450449
profile.includes('scooter') ||
451450
profile.includes('bus') ||
@@ -456,25 +455,4 @@ export class ApiImpl implements Api {
456455
public static isTruck(profile: string) {
457456
return profile.includes('truck')
458457
}
459-
460-
public static getBBoxPoints(points: Coordinate[]): Bbox | null {
461-
const bbox: Bbox = points.reduce(
462-
(res: Bbox, c) => [
463-
Math.min(res[0], c.lng),
464-
Math.min(res[1], c.lat),
465-
Math.max(res[2], c.lng),
466-
Math.max(res[3], c.lat),
467-
],
468-
[180, 90, -180, -90] as Bbox
469-
)
470-
if (points.length == 1) {
471-
bbox[0] = bbox[0] - 0.001
472-
bbox[1] = bbox[1] - 0.001
473-
bbox[2] = bbox[2] + 0.001
474-
bbox[3] = bbox[3] + 0.001
475-
}
476-
477-
// return null if the bbox is not valid, e.g. if no url points were given at all
478-
return bbox[0] < bbox[2] && bbox[1] < bbox[3] ? bbox : null
479-
}
480458
}

src/custom.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ declare module 'heightgraph/src/heightgraph'
55
declare module 'custom-model-editor/src/index'
66

77
declare module 'config' {
8-
import ol from 'ol/dist/ol'
9-
import array = ol.array
10-
import { ProfileGroup, ProfileGroupMap } from '@/stores/QueryStore'
8+
interface ProfileGroup {
9+
readonly options: { profile: string }[]
10+
}
11+
1112
const routingApi: string
1213
const geocodingApi: string
1314
const defaultTiles: string

src/distUtils.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/map/findNextWayPoint.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Coordinate } from '@/stores/QueryStore'
2-
import { calcDist } from '@/distUtils'
1+
import { calcDist, Coordinate } from '@/utils'
32

43
/**
54
* Finds the way-point that follows the part of a route that is closest to a given location

src/pathDetails/PathDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Dispatcher from '@/stores/Dispatcher'
77
import { PathDetailsElevationSelected, PathDetailsHover, PathDetailsRangeSelected } from '@/actions/Actions'
88
import QueryStore, { Coordinate, QueryPointType } from '@/stores/QueryStore'
99
import { Position } from 'geojson'
10-
import { calcDist } from '@/distUtils'
10+
import { calcDist } from '@/utils'
1111
import { tr } from '@/translation/Translation'
1212
import { SettingsContext } from '@/contexts/SettingsContext'
1313

src/pois/AddressParseResult.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ApiImpl } from '@/api/Api'
21
import Dispatcher from '@/stores/Dispatcher'
32
import { SetBBox, SetPOIs } from '@/actions/Actions'
43
import { hitToItem } from '@/Converters'
54
import { GeocodingHit, ReverseGeocodingHit } from '@/api/graphhopper'
65
import { tr, Translation } from '@/translation/Translation'
76
import { POI } from '@/stores/POIsStore'
7+
import { getBBoxPoints } from '@/utils'
88

99
export class AddressParseResult {
1010
location: string
@@ -144,7 +144,7 @@ export class AddressParseResult {
144144
address: res.secondText,
145145
} as POI
146146
})
147-
const bbox = ApiImpl.getBBoxPoints(pois.map(p => p.coordinate))
147+
const bbox = getBBoxPoints(pois.map(p => p.coordinate))
148148
if (bbox) {
149149
if (parseResult.location) Dispatcher.dispatch(new SetBBox(bbox))
150150
Dispatcher.dispatch(new SetPOIs(pois))

0 commit comments

Comments
 (0)