Skip to content

Commit 9fff35a

Browse files
committed
add point_hints to query
1 parent 0c92513 commit 9fff35a

File tree

14 files changed

+59
-23
lines changed

14 files changed

+59
-23
lines changed

src/NavBar.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { coordinateToText } from '@/Converters'
22
import Dispatcher from '@/stores/Dispatcher'
3-
import { ClearPoints, SelectMapLayer, SetBBox, SetQueryPoints, SetVehicleProfile } from '@/actions/Actions'
3+
import { ClearPoints, SelectMapLayer, SetBBox, SetPOIs, SetQueryPoints, SetVehicleProfile } from '@/actions/Actions'
44
// import the window like this so that it can be mocked during testing
55
import { window } from '@/Window'
66
import QueryStore, { getBBoxFromCoord, QueryPoint, QueryPointType, QueryStoreState } from '@/stores/QueryStore'
@@ -57,6 +57,7 @@ export default class NavBar {
5757
isInitialized: false,
5858
id: idx,
5959
queryText: parameter,
60+
streetName: '' /**/,
6061
color: '',
6162
type: QueryPointType.Via,
6263
}
@@ -132,6 +133,7 @@ export default class NavBar {
132133
return {
133134
...p,
134135
queryText: res.hits[0].name,
136+
streetName: res.hits[0].street,
135137
coordinate: { lat: res.hits[0].point.lat, lng: res.hits[0].point.lng },
136138
isInitialized: true,
137139
}

src/api/Api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ export class ApiImpl implements Api {
277277

278278
const request: RoutingRequest = {
279279
points: args.points,
280+
point_hints: args.pointHints,
280281
profile: args.profile,
281282
elevation: true,
282283
instructions: true,

src/api/graphhopper.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ export type Bbox = [number, number, number, number]
66

77
export interface RoutingArgs {
88
readonly points: [number, number][]
9+
readonly pointHints: string[]
910
readonly profile: string
1011
readonly maxAlternativeRoutes: number
1112
readonly customModel: CustomModel | null
1213
}
1314

1415
export interface RoutingRequest {
1516
readonly points: ReadonlyArray<[number, number]>
17+
readonly point_hints: string[]
1618
profile: string
1719
locale: string
1820
points_encoded: boolean

src/map/MapComponent.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ export default function ({ map }: MapComponentProps) {
2222
}
2323

2424
export function onCurrentLocationSelected(
25-
onSelect: (queryText: string, coordinate: Coordinate | undefined, bbox: Bbox | undefined) => void
25+
onSelect: (queryText: string, street: string, coordinate: Coordinate | undefined, bbox: Bbox | undefined) => void
2626
) {
2727
if (!navigator.geolocation) {
2828
Dispatcher.dispatch(new ErrorAction('Geolocation is not supported in this browser'))
2929
return
3030
}
3131

32-
onSelect(tr('searching_location') + ' ...', undefined, undefined)
32+
onSelect(tr('searching_location') + ' ...', '', undefined, undefined)
3333
navigator.geolocation.getCurrentPosition(
3434
position => {
3535
const coordinate = { lat: position.coords.latitude, lng: position.coords.longitude }
36-
onSelect(tr('current_location'), coordinate, getBBoxFromCoord(coordinate))
36+
onSelect(tr('current_location'), '', coordinate, getBBoxFromCoord(coordinate))
3737
},
3838
error => {
3939
Dispatcher.dispatch(new ErrorAction(tr('searching_location_failed') + ': ' + error.message))
40-
onSelect('', undefined, undefined)
40+
onSelect('', '', undefined, undefined)
4141
},
4242
// DO NOT use e.g. maximumAge: 5_000 -> getCurrentPosition will then never return on mobile firefox!?
4343
{ timeout: 300_000, enableHighAccuracy: true }

src/pois/AddressParseResult.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export class AddressParseResult {
1010
location: string
1111
query: POIQuery
1212
icon: string
13-
poi: string
13+
poiType: string
1414
static TRIGGER_VALUES: PoiTriggerPhrases[]
1515
static REMOVE_VALUES: string[]
1616

17-
constructor(location: string, query: POIQuery, icon: string, poi: string) {
17+
constructor(location: string, query: POIQuery, icon: string, poiType: string) {
1818
this.location = location
1919
this.query = query
2020
this.icon = icon
21-
this.poi = poi
21+
this.poiType = poiType
2222
}
2323

2424
hasPOIs(): boolean {

src/sidebar/search/AddressInput.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface AddressInputProps {
2323
point: QueryPoint
2424
points: QueryPoint[]
2525
onCancel: () => void
26-
onAddressSelected: (queryText: string, coord: Coordinate | undefined) => void
26+
onAddressSelected: (queryText: string, streetHint: string, coord: Coordinate | undefined) => void
2727
onChange: (value: string) => void
2828
clearDragDrop: () => void
2929
moveStartIndex: number
@@ -59,6 +59,7 @@ export default function AddressInput(props: AddressInputProps) {
5959
new GeocodingItem(
6060
obj.mainText,
6161
obj.secondText,
62+
hit.street,
6263
hit.point,
6364
hit.extent ? hit.extent : getBBoxFromCoord(hit.point)
6465
)
@@ -120,13 +121,13 @@ export default function AddressInput(props: AddressInputProps) {
120121
// try to parse input as coordinate. Otherwise query nominatim
121122
const coordinate = textToCoordinate(text)
122123
if (coordinate) {
123-
props.onAddressSelected(text, coordinate)
124+
props.onAddressSelected(text, '', coordinate)
124125
} else if (autocompleteItems.length > 0) {
125126
const index = highlightedResult >= 0 ? highlightedResult : 0
126127
const item = autocompleteItems[index]
127128
if (item instanceof POIQueryItem) {
128129
handlePoiSearch(poiSearch, item.result, props.map)
129-
props.onAddressSelected(item.result.text(item.result.poi), undefined)
130+
props.onAddressSelected(item.result.text(item.result.poiType), '', undefined)
130131
} else if (highlightedResult < 0 && !props.point.isInitialized) {
131132
// by default use the first result, otherwise the highlighted one
132133
getApi()
@@ -135,13 +136,17 @@ export default function AddressInput(props: AddressInputProps) {
135136
if (result && result.hits.length > 0) {
136137
const hit: GeocodingHit = result.hits[0]
137138
const res = nominatimHitToItem(hit)
138-
props.onAddressSelected(res.mainText + ', ' + res.secondText, hit.point)
139+
props.onAddressSelected(
140+
res.mainText + ', ' + res.secondText,
141+
hit.street,
142+
hit.point
143+
)
139144
} else if (item instanceof GeocodingItem) {
140-
props.onAddressSelected(item.toText(), item.point)
145+
props.onAddressSelected(item.toText(), item.street, item.point)
141146
}
142147
})
143148
} else if (item instanceof GeocodingItem) {
144-
props.onAddressSelected(item.toText(), item.point)
149+
props.onAddressSelected(item.toText(), item.street, item.point)
145150
}
146151
}
147152
// do not disturb 'tab' cycle
@@ -262,10 +267,10 @@ export default function AddressInput(props: AddressInputProps) {
262267
highlightedItem={autocompleteItems[highlightedResult]}
263268
onSelect={item => {
264269
if (item instanceof GeocodingItem) {
265-
props.onAddressSelected(item.toText(), item.point)
270+
props.onAddressSelected(item.toText(), item.street, item.point)
266271
} else if (item instanceof POIQueryItem) {
267272
handlePoiSearch(poiSearch, item.result, props.map)
268-
setText(item.result.text(item.result.poi))
273+
setText(item.result.text(item.result.poiType))
269274
}
270275
searchInput.current!.blur() // see also AutocompleteEntry->onMouseDown
271276
}}

src/sidebar/search/AddressInputAutocomplete.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export interface AutocompleteItem {}
77
export class GeocodingItem implements AutocompleteItem {
88
mainText: string
99
secondText: string
10+
street: string
1011
point: { lat: number; lng: number }
1112
bbox: Bbox
1213

13-
constructor(mainText: string, secondText: string, point: { lat: number; lng: number }, bbox: Bbox) {
14+
constructor(mainText: string, secondText: string, street: string, point: { lat: number; lng: number }, bbox: Bbox) {
1415
this.mainText = mainText
1516
this.secondText = secondText
17+
this.street = street
1618
this.point = point
1719
this.bbox = bbox
1820
}
@@ -65,7 +67,7 @@ export function POIQueryEntry({
6567
isHighlighted: boolean
6668
onSelect: (item: POIQueryItem) => void
6769
}) {
68-
const poi = item.result.poi ? item.result.poi : ''
70+
const poi = item.result.poiType ? item.result.poiType : ''
6971
return (
7072
<AutocompleteEntry isHighlighted={isHighlighted} onSelect={() => onSelect(item)}>
7173
<div className={styles.poiEntry}>

src/sidebar/search/Search.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const SearchBox = ({
164164
point={point}
165165
points={points}
166166
onCancel={() => console.log('cancel')}
167-
onAddressSelected={(queryText, coordinate) => {
167+
onAddressSelected={(queryText, street, coordinate) => {
168168
const initCount = points.filter(p => p.isInitialized).length
169169
if (coordinate && initCount != points.length)
170170
Dispatcher.dispatch(new SetBBox(getBBoxFromCoord(coordinate)))
@@ -175,6 +175,7 @@ const SearchBox = ({
175175
...point,
176176
isInitialized: !!coordinate,
177177
queryText: queryText,
178+
streetName: street,
178179
coordinate: coordinate ? coordinate : point.coordinate,
179180
},
180181
initCount > 0

src/stores/QueryStore.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface QueryStoreState {
4646
export interface QueryPoint {
4747
readonly coordinate: Coordinate
4848
readonly queryText: string
49+
readonly streetName: string
4950
readonly isInitialized: boolean
5051
readonly color: string
5152
readonly id: number
@@ -176,6 +177,7 @@ export default class QueryStore extends Store<QueryStoreState> {
176177
coordinate: action.coordinate,
177178
id: state.nextQueryPointId,
178179
queryText: queryText,
180+
streetName: '',
179181
color: '',
180182
isInitialized: action.isInitialized,
181183
type: QueryPointType.Via,
@@ -215,6 +217,7 @@ export default class QueryStore extends Store<QueryStoreState> {
215217
id: queryPoints.length,
216218
type: type,
217219
color: QueryStore.getMarkerColor(type),
220+
streetName: '',
218221
queryText: '',
219222
isInitialized: false,
220223
coordinate: { lat: 0, lng: 0 },
@@ -450,6 +453,7 @@ export default class QueryStore extends Store<QueryStoreState> {
450453

451454
return {
452455
points: coordinates,
456+
pointHints: state.queryPoints.map(point => point.streetName),
453457
profile: state.routingProfile.name,
454458
maxAlternativeRoutes: state.maxAlternativeRoutes,
455459
customModel: customModel,
@@ -460,6 +464,7 @@ export default class QueryStore extends Store<QueryStoreState> {
460464
return {
461465
isInitialized: false,
462466
queryText: '',
467+
streetName: '',
463468
coordinate: { lat: 0, lng: 0 },
464469
id: id,
465470
color: QueryStore.getMarkerColor(type),

test/NavBar.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ describe('NavBar', function () {
120120
type: QueryPointType.To,
121121
isInitialized: false,
122122
queryText: 'some1address-with!/<symb0ls',
123+
streetName: '',
123124
color: '',
124125
}
125126
const profile = 'some-profile'
@@ -293,6 +294,7 @@ describe('NavBar', function () {
293294
type: QueryPointType.To,
294295
isInitialized: false,
295296
queryText: '',
297+
streetName: '',
296298
color: '',
297299
}
298300
const profile = 'some-profile'

0 commit comments

Comments
 (0)