Skip to content

Commit 7ebf7c8

Browse files
committed
refactoring: move a couple of things into utils
1 parent 87acad8 commit 7ebf7c8

27 files changed

Lines changed: 82 additions & 69 deletions

src/Converters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GeocodingHit } from '@/api/graphhopper'
22

3-
import { Coordinate } from '@/stores/QueryStore'
3+
import { Coordinate } from '@/utils'
44

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

src/NavBar.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ 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'
88
import { ApiImpl, getApi } from '@/api/Api'
99
import { AddressParseResult } from '@/pois/AddressParseResult'
1010
import { getQueryStore } from '@/stores/Stores'
11+
import { getBBoxFromCoord, getBBoxPoints } from '@/utils'
1112

1213
export default class NavBar {
1314
private readonly queryStore: QueryStore
@@ -159,7 +160,7 @@ export default class NavBar {
159160
const bbox =
160161
initializedPoints.length == 1
161162
? getBBoxFromCoord(initializedPoints[0].coordinate)
162-
: ApiImpl.getBBoxPoints(initializedPoints.map(p => p.coordinate))
163+
: getBBoxPoints(initializedPoints.map(p => p.coordinate))
163164
if (bbox) Dispatcher.dispatch(new SetBBox(bbox))
164165
return Dispatcher.dispatch(new SetQueryPoints(points))
165166
}

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 & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ 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'
21+
import { Coordinate } from '@/utils'
2222

2323
interface ApiProfile {
2424
name: string
@@ -456,25 +456,4 @@ export class ApiImpl implements Api {
456456
public static isTruck(profile: string) {
457457
return profile.includes('truck')
458458
}
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-
}
480459
}

src/api/graphhopper.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { LineString } from 'geojson'
2-
import { Coordinate, CustomModel } from '@/stores/QueryStore'
2+
3+
import { Coordinate, CustomModel } from '@/utils'
34

45
// minLon, minLat, maxLon, maxLat
56
export type Bbox = [number, number, number, number]

src/layers/ContextMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Map, Overlay } from 'ol'
22
import { ContextMenuContent } from '@/map/ContextMenuContent'
33
import { useEffect, useRef, useState } from 'react'
4-
import { Coordinate, QueryPoint } from '@/stores/QueryStore'
4+
import { QueryPoint } from '@/stores/QueryStore'
55
import { fromLonLat, toLonLat } from 'ol/proj'
66
import styles from '@/layers/ContextMenu.module.css'
77
import { RouteStoreState } from '@/stores/RouteStore'
8+
import { Coordinate } from '@/utils'
89

910
interface ContextMenuProps {
1011
map: Map

src/layers/InstructionPopup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { useEffect } from 'react'
22
import styles from '@/layers/DefaultMapPopup.module.css'
33
import { Map } from 'ol'
44
import MapPopup from '@/layers/MapPopup'
5-
import { Coordinate } from '@/stores/QueryStore'
65
import Dispatcher from '@/stores/Dispatcher'
76
import { InstructionClicked } from '@/actions/Actions'
7+
import { Coordinate } from '@/utils'
88

99
interface InstructionPopupProps {
1010
map: Map

src/layers/MapFeaturePopup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react'
22
import styles from '@/layers/MapFeaturePopup.module.css'
33
import MapPopup from '@/layers/MapPopup'
44
import { Map } from 'ol'
5-
import { Coordinate } from '@/stores/QueryStore'
5+
6+
import { Coordinate } from '@/utils'
67

78
interface MapFeaturePopupProps {
89
map: Map

src/layers/MapPopup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Map, Overlay } from 'ol'
22
import { useEffect, useRef, useState } from 'react'
33
import { fromLonLat } from 'ol/proj'
4-
import { Coordinate } from '@/stores/QueryStore'
4+
5+
import { Coordinate } from '@/utils'
56

67
interface MapPopupProps {
78
map: Map

src/layers/UsePathDetailsLayer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Map } from 'ol'
22
import { useEffect } from 'react'
33
import { PathDetailsStoreState } from '@/stores/PathDetailsStore'
4-
import { Coordinate } from '@/stores/QueryStore'
54
import { FeatureCollection } from 'geojson'
65
import VectorLayer from 'ol/layer/Vector'
76
import VectorSource from 'ol/source/Vector'
87
import { Stroke, Style } from 'ol/style'
98
import { GeoJSON } from 'ol/format'
109
import { fromLonLat } from 'ol/proj'
10+
import { Coordinate } from '@/utils'
1111

1212
const highlightedPathSegmentLayerKey = 'highlightedPathSegmentLayer'
1313

0 commit comments

Comments
 (0)