Skip to content

add point_hints to route request #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ on: push

jobs:
test_and_build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
registry-url: https://registry.npmjs.org/
node-version: v20.14.0
Expand Down
4 changes: 3 additions & 1 deletion src/NavBar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { coordinateToText } from '@/Converters'
import Dispatcher from '@/stores/Dispatcher'
import { ClearPoints, SelectMapLayer, SetBBox, SetQueryPoints, SetVehicleProfile } from '@/actions/Actions'
import { ClearPoints, SelectMapLayer, SetBBox, SetPOIs, SetQueryPoints, SetVehicleProfile } from '@/actions/Actions'
// import the window like this so that it can be mocked during testing
import { window } from '@/Window'
import QueryStore, { getBBoxFromCoord, QueryPoint, QueryPointType, QueryStoreState } from '@/stores/QueryStore'
Expand Down Expand Up @@ -57,6 +57,7 @@ export default class NavBar {
isInitialized: false,
id: idx,
queryText: parameter,
streetName: '' /**/,
color: '',
type: QueryPointType.Via,
}
Expand Down Expand Up @@ -132,6 +133,7 @@ export default class NavBar {
return {
...p,
queryText: res.hits[0].name,
streetName: res.hits[0].street,
coordinate: { lat: res.hits[0].point.lat, lng: res.hits[0].point.lng },
isInitialized: true,
}
Expand Down
1 change: 1 addition & 0 deletions src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export class ApiImpl implements Api {

const request: RoutingRequest = {
points: args.points,
point_hints: args.pointHints,
profile: args.profile,
elevation: true,
instructions: true,
Expand Down
2 changes: 2 additions & 0 deletions src/api/graphhopper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export type Bbox = [number, number, number, number]

export interface RoutingArgs {
readonly points: [number, number][]
readonly pointHints: string[]
readonly profile: string
readonly maxAlternativeRoutes: number
readonly customModel: CustomModel | null
}

export interface RoutingRequest {
readonly points: ReadonlyArray<[number, number]>
readonly point_hints: string[]
profile: string
locale: string
points_encoded: boolean
Expand Down
8 changes: 4 additions & 4 deletions src/map/MapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ export default function ({ map }: MapComponentProps) {
}

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

onSelect(tr('searching_location') + ' ...', undefined, undefined)
onSelect(tr('searching_location') + ' ...', '', undefined, undefined)
navigator.geolocation.getCurrentPosition(
position => {
const coordinate = { lat: position.coords.latitude, lng: position.coords.longitude }
onSelect(tr('current_location'), coordinate, getBBoxFromCoord(coordinate))
onSelect(tr('current_location'), '', coordinate, getBBoxFromCoord(coordinate))
},
error => {
Dispatcher.dispatch(new ErrorAction(tr('searching_location_failed') + ': ' + error.message))
onSelect('', undefined, undefined)
onSelect('', '', undefined, undefined)
},
// DO NOT use e.g. maximumAge: 5_000 -> getCurrentPosition will then never return on mobile firefox!?
{ timeout: 300_000, enableHighAccuracy: true }
Expand Down
6 changes: 3 additions & 3 deletions src/pois/AddressParseResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export class AddressParseResult {
location: string
query: POIQuery
icon: string
poi: string
poiType: string
static TRIGGER_VALUES: PoiTriggerPhrases[]
static REMOVE_VALUES: string[]

constructor(location: string, query: POIQuery, icon: string, poi: string) {
constructor(location: string, query: POIQuery, icon: string, poiType: string) {
this.location = location
this.query = query
this.icon = icon
this.poi = poi
this.poiType = poiType
}

hasPOIs(): boolean {
Expand Down
21 changes: 13 additions & 8 deletions src/sidebar/search/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface AddressInputProps {
point: QueryPoint
points: QueryPoint[]
onCancel: () => void
onAddressSelected: (queryText: string, coord: Coordinate | undefined) => void
onAddressSelected: (queryText: string, streetHint: string, coord: Coordinate | undefined) => void
onChange: (value: string) => void
clearDragDrop: () => void
moveStartIndex: number
Expand Down Expand Up @@ -59,6 +59,7 @@ export default function AddressInput(props: AddressInputProps) {
new GeocodingItem(
obj.mainText,
obj.secondText,
hit.street,
hit.point,
hit.extent ? hit.extent : getBBoxFromCoord(hit.point)
)
Expand Down Expand Up @@ -120,13 +121,13 @@ export default function AddressInput(props: AddressInputProps) {
// try to parse input as coordinate. Otherwise query nominatim
const coordinate = textToCoordinate(text)
if (coordinate) {
props.onAddressSelected(text, coordinate)
props.onAddressSelected(text, '', coordinate)
} else if (autocompleteItems.length > 0) {
const index = highlightedResult >= 0 ? highlightedResult : 0
const item = autocompleteItems[index]
if (item instanceof POIQueryItem) {
handlePoiSearch(poiSearch, item.result, props.map)
props.onAddressSelected(item.result.text(item.result.poi), undefined)
props.onAddressSelected(item.result.text(item.result.poiType), '', undefined)
} else if (highlightedResult < 0 && !props.point.isInitialized) {
// by default use the first result, otherwise the highlighted one
getApi()
Expand All @@ -135,13 +136,17 @@ export default function AddressInput(props: AddressInputProps) {
if (result && result.hits.length > 0) {
const hit: GeocodingHit = result.hits[0]
const res = nominatimHitToItem(hit)
props.onAddressSelected(res.mainText + ', ' + res.secondText, hit.point)
props.onAddressSelected(
res.mainText + ', ' + res.secondText,
hit.street,
hit.point
)
} else if (item instanceof GeocodingItem) {
props.onAddressSelected(item.toText(), item.point)
props.onAddressSelected(item.toText(), item.street, item.point)
}
})
} else if (item instanceof GeocodingItem) {
props.onAddressSelected(item.toText(), item.point)
props.onAddressSelected(item.toText(), item.street, item.point)
}
}
// do not disturb 'tab' cycle
Expand Down Expand Up @@ -262,10 +267,10 @@ export default function AddressInput(props: AddressInputProps) {
highlightedItem={autocompleteItems[highlightedResult]}
onSelect={item => {
if (item instanceof GeocodingItem) {
props.onAddressSelected(item.toText(), item.point)
props.onAddressSelected(item.toText(), item.street, item.point)
} else if (item instanceof POIQueryItem) {
handlePoiSearch(poiSearch, item.result, props.map)
setText(item.result.text(item.result.poi))
setText(item.result.text(item.result.poiType))
}
searchInput.current!.blur() // see also AutocompleteEntry->onMouseDown
}}
Expand Down
6 changes: 4 additions & 2 deletions src/sidebar/search/AddressInputAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export interface AutocompleteItem {}
export class GeocodingItem implements AutocompleteItem {
mainText: string
secondText: string
street: string
point: { lat: number; lng: number }
bbox: Bbox

constructor(mainText: string, secondText: string, point: { lat: number; lng: number }, bbox: Bbox) {
constructor(mainText: string, secondText: string, street: string, point: { lat: number; lng: number }, bbox: Bbox) {
this.mainText = mainText
this.secondText = secondText
this.street = street
this.point = point
this.bbox = bbox
}
Expand Down Expand Up @@ -65,7 +67,7 @@ export function POIQueryEntry({
isHighlighted: boolean
onSelect: (item: POIQueryItem) => void
}) {
const poi = item.result.poi ? item.result.poi : ''
const poi = item.result.poiType ? item.result.poiType : ''
return (
<AutocompleteEntry isHighlighted={isHighlighted} onSelect={() => onSelect(item)}>
<div className={styles.poiEntry}>
Expand Down
3 changes: 2 additions & 1 deletion src/sidebar/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const SearchBox = ({
point={point}
points={points}
onCancel={() => console.log('cancel')}
onAddressSelected={(queryText, coordinate) => {
onAddressSelected={(queryText, street, coordinate) => {
const initCount = points.filter(p => p.isInitialized).length
if (coordinate && initCount != points.length)
Dispatcher.dispatch(new SetBBox(getBBoxFromCoord(coordinate)))
Expand All @@ -175,6 +175,7 @@ const SearchBox = ({
...point,
isInitialized: !!coordinate,
queryText: queryText,
streetName: street,
coordinate: coordinate ? coordinate : point.coordinate,
},
initCount > 0
Expand Down
5 changes: 5 additions & 0 deletions src/stores/QueryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface QueryStoreState {
export interface QueryPoint {
readonly coordinate: Coordinate
readonly queryText: string
readonly streetName: string
readonly isInitialized: boolean
readonly color: string
readonly id: number
Expand Down Expand Up @@ -176,6 +177,7 @@ export default class QueryStore extends Store<QueryStoreState> {
coordinate: action.coordinate,
id: state.nextQueryPointId,
queryText: queryText,
streetName: '',
color: '',
isInitialized: action.isInitialized,
type: QueryPointType.Via,
Expand Down Expand Up @@ -215,6 +217,7 @@ export default class QueryStore extends Store<QueryStoreState> {
id: queryPoints.length,
type: type,
color: QueryStore.getMarkerColor(type),
streetName: '',
queryText: '',
isInitialized: false,
coordinate: { lat: 0, lng: 0 },
Expand Down Expand Up @@ -450,6 +453,7 @@ export default class QueryStore extends Store<QueryStoreState> {

return {
points: coordinates,
pointHints: state.queryPoints.map(point => point.streetName),
profile: state.routingProfile.name,
maxAlternativeRoutes: state.maxAlternativeRoutes,
customModel: customModel,
Expand All @@ -460,6 +464,7 @@ export default class QueryStore extends Store<QueryStoreState> {
return {
isInitialized: false,
queryText: '',
streetName: '',
coordinate: { lat: 0, lng: 0 },
id: id,
color: QueryStore.getMarkerColor(type),
Expand Down
2 changes: 2 additions & 0 deletions test/NavBar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('NavBar', function () {
type: QueryPointType.To,
isInitialized: false,
queryText: 'some1address-with!/<symb0ls',
streetName: '',
color: '',
}
const profile = 'some-profile'
Expand Down Expand Up @@ -293,6 +294,7 @@ describe('NavBar', function () {
type: QueryPointType.To,
isInitialized: false,
queryText: '',
streetName: '',
color: '',
}
const profile = 'some-profile'
Expand Down
8 changes: 4 additions & 4 deletions test/poi/AddressParseResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ describe('reverse geocoder', () => {

res = AddressParseResult.parse('dresden super market', false)
expect(res.location).toEqual('dresden')
expect(res.poi).toEqual('super markets')
expect(res.poiType).toEqual('super markets')

res = AddressParseResult.parse('dresden park', false)
expect(res.location).toEqual('dresden')
expect(res.poi).toEqual('parks')
expect(res.poiType).toEqual('parks')

res = AddressParseResult.parse('dresden parking', false)
expect(res.location).toEqual('dresden')
expect(res.poi).toEqual('parking')
expect(res.poiType).toEqual('parking')

res = AddressParseResult.parse('restaurants in this area', false)
expect(res.location).toEqual('')
expect(res.poi).toEqual('restaurants')
expect(res.poiType).toEqual('restaurants')
})

it('should parse generic', async () => {
Expand Down
12 changes: 12 additions & 0 deletions test/routing/Api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('route', () => {
it('should use correct metadata', async () => {
const args: RoutingArgs = {
points: [],
pointHints: [],
maxAlternativeRoutes: 1,
profile: 'profile',
customModel: null,
Expand Down Expand Up @@ -99,13 +100,15 @@ describe('route', () => {
it('transforms routingArgs into routing request with default algorithm for maxAlternativeRoutes: 1', async () => {
const args: RoutingArgs = {
points: [],
pointHints: [],
maxAlternativeRoutes: 1,
profile: 'car',
customModel: null,
}

const expectedBody: RoutingRequest = {
points: args.points,
point_hints: [],
profile: args.profile,
elevation: true,
instructions: true,
Expand Down Expand Up @@ -141,13 +144,15 @@ describe('route', () => {
it('transforms routingArgs into routing request with alternative_route algorithm for maxAlternativeRoutes > 1', async () => {
const args: RoutingArgs = {
points: [],
pointHints: [],
maxAlternativeRoutes: 2,
profile: 'car',
customModel: null,
}

const expectedBody: RoutingRequest = {
points: args.points,
point_hints: [],
profile: args.profile,
elevation: true,
instructions: true,
Expand Down Expand Up @@ -185,6 +190,7 @@ describe('route', () => {
it('transforms routingArgs into routing request with custom model', async () => {
const args: RoutingArgs = {
points: [],
pointHints: [],
maxAlternativeRoutes: 1,
profile: 'car',
customModel: {
Expand All @@ -199,6 +205,7 @@ describe('route', () => {

const expectedBody: RoutingRequest = {
points: args.points,
point_hints: [],
profile: args.profile,
elevation: true,
instructions: true,
Expand Down Expand Up @@ -240,6 +247,7 @@ describe('route', () => {
[0, 0],
[1, 1],
],
pointHints: [],
maxAlternativeRoutes: 1,
profile: 'bla',
customModel: null,
Expand All @@ -261,6 +269,7 @@ describe('route', () => {
[0, 0],
[1, 1],
],
pointHints: [],
maxAlternativeRoutes: 1,
profile: 'bla',
customModel: null,
Expand All @@ -285,6 +294,7 @@ describe('route', () => {
const args: RoutingArgs = {
profile: 'car',
points: [],
pointHints: [],
maxAlternativeRoutes: 3,
customModel: null,
}
Expand All @@ -299,13 +309,15 @@ describe('route', () => {
setTranslation('de', true)
const args: RoutingArgs = {
points: [],
pointHints: [],
maxAlternativeRoutes: 1,
profile: 'car',
customModel: null,
}

const expectedBody: RoutingRequest = {
points: args.points,
point_hints: [],
profile: args.profile,
elevation: true,
instructions: true,
Expand Down
Loading
Loading