Skip to content

Commit 007e639

Browse files
committed
Use Digitraffic v2 routing API
1 parent b6a33a5 commit 007e639

File tree

2 files changed

+78
-46
lines changed

2 files changed

+78
-46
lines changed

apigw/src/enduser/mapRoutes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ router.get(
9090
router.post(
9191
'/query',
9292
digitransitApiEnabled
93-
? createDigitransitProxy('/routing/v1/routers/finland/index/graphql')
93+
? createDigitransitProxy('/routing/v2/finland/gtfs/v1')
9494
: enableDevApi
9595
? createProxy({
9696
getUserHeader: () => undefined,

frontend/src/citizen-frontend/map/api.ts

+77-45
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ type ItineraryResponse = {
6868
data: Record<
6969
string,
7070
{
71-
itineraries: {
72-
legs: {
73-
distance: number
74-
}[]
71+
edges: {
72+
node: {
73+
walkDistance: number
74+
}
7575
}[]
7676
}
7777
>
@@ -112,25 +112,43 @@ export async function fetchUnitsWithDistances(
112112
${unitsToQuery
113113
.map(
114114
({ id, location }) => `
115-
${uuidToKey(id)}: plan(
116-
from: {
117-
lat: ${startLocation.lat},
118-
lon: ${startLocation.lon}
119-
},
120-
to: {
121-
lat: ${location?.lat ?? 0},
122-
lon: ${location?.lon ?? 0}
123-
},
124-
modes: "WALK"
125-
) {
126-
itineraries{
127-
legs {
128-
distance
115+
${uuidToKey(id)}: planConnection(
116+
origin: {
117+
location: {
118+
coordinate: {
119+
latitude: ${startLocation.lat}
120+
longitude: ${startLocation.lon}
129121
}
130122
}
131123
}
124+
destination: {
125+
location: {
126+
coordinate: {
127+
latitude: ${location?.lat ?? 0}
128+
longitude: ${location?.lon ?? 0}
129+
}
130+
}
131+
}
132+
modes: {
133+
direct: WALK
134+
directOnly: true
135+
}
136+
preferences: {
137+
street: {
138+
walk: {
139+
speed: 300
140+
}
141+
}
142+
}
143+
) {
144+
edges {
145+
node {
146+
walkDistance
147+
}
148+
}
149+
}
132150
133-
`
151+
`
134152
)
135153
.join('')}
136154
}`
@@ -156,18 +174,14 @@ export async function fetchUnitsWithDistances(
156174
drivingDistance: null
157175
}
158176

159-
const itineraries = plan.itineraries
160-
if (itineraries.length === 0)
177+
const edges = plan.edges
178+
if (edges.length === 0)
161179
return {
162180
...unit,
163181
drivingDistance: null
164182
}
165183

166-
const itinerary = itineraries[0]
167-
const drivingDistance = itinerary.legs.reduce(
168-
(acc, leg) => acc + leg.distance,
169-
0
170-
)
184+
const drivingDistance = edges[0].node.walkDistance
171185
return {
172186
...unit,
173187
drivingDistance
@@ -182,23 +196,41 @@ export const fetchDistance = async (
182196
): Promise<number> => {
183197
const query = `
184198
{
185-
plan(
186-
from: {
187-
lat: ${startLocation.lat},
188-
lon: ${startLocation.lon}
189-
},
190-
to: {
191-
lat: ${endLocation.lat},
192-
lon: ${endLocation.lon}
193-
},
194-
modes: "WALK"
195-
) {
196-
itineraries{
197-
legs {
198-
distance
199+
planConnection(
200+
origin: {
201+
location: {
202+
coordinate: {
203+
latitude: ${startLocation.lat}
204+
longitude: ${startLocation.lon}
205+
}
206+
}
207+
}
208+
destination: {
209+
location: {
210+
coordinate: {
211+
latitude: ${endLocation.lat}
212+
longitude: ${endLocation.lon}
213+
}
214+
}
215+
}
216+
modes: {
217+
direct: WALK
218+
directOnly: true
219+
}
220+
preferences: {
221+
street: {
222+
walk: {
223+
speed: 300
199224
}
200225
}
201226
}
227+
) {
228+
edges {
229+
node {
230+
walkDistance
231+
}
232+
}
233+
}
202234
}`
203235

204236
return axios
@@ -214,12 +246,12 @@ export const fetchDistance = async (
214246
}
215247
)
216248
.then((res) => {
217-
const plan = res.data.data.plan
218-
if (!plan) throw Error('No plan found')
249+
const planConnection = res.data.data.planConnection
250+
if (!planConnection) throw Error('No planConnection found')
219251

220-
const itineraries = plan.itineraries
221-
if (itineraries.length === 0) throw Error('No itineraries found')
252+
const edges = planConnection.edges
253+
if (edges.length === 0) throw Error('No edges found')
222254

223-
return itineraries[0].legs.reduce((acc, leg) => acc + leg.distance, 0)
255+
return edges[0].node.walkDistance
224256
})
225257
}

0 commit comments

Comments
 (0)