@@ -57,13 +57,6 @@ func NewRouter(client *http.Client, endpoint string, apikey string) *Router {
5757 }
5858}
5959
60- func (h * Router ) Capabilities () directions.Capabilities {
61- return directions.Capabilities {
62- SupportedModes : []model.StepMode {model .StepModeAuto , model .StepModeBicycle , model .StepModeWalk },
63- SupportsArriveBy : true ,
64- }
65- }
66-
6760func (h * Router ) Request (ctx context.Context , req model.DirectionRequest ) (* model.Directions , error ) {
6861 if err := directions .ValidateDirectionRequest (req ); err != nil {
6962 return & model.Directions {Success : false , Exception : aws .String ("invalid input" )}, nil
@@ -78,7 +71,7 @@ func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*mode
7871 input .Costing = "auto"
7972 case model .StepModeBicycle :
8073 input .Costing = "bicycle"
81- case model .StepModeWalk :
74+ case model .StepModeWalk , model . StepModeTransit :
8275 input .Costing = "pedestrian"
8376 default :
8477 return & model.Directions {Success : false , Exception : aws .String ("unsupported travel mode" )}, nil
@@ -97,27 +90,14 @@ func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*mode
9790 // Ensure we are in UTC
9891 departAt = departAt .In (time .UTC )
9992
100- // Set date_time for time-aware routing
101- arriveBy := req .ArriveBy != nil && * req .ArriveBy
102- if req .DepartAt != nil {
103- dtType := 1 // depart_at
104- if arriveBy {
105- dtType = 2 // arrive_by
106- }
107- input .DateTime = & DateTime {
108- Type : dtType ,
109- Value : departAt .Format ("2006-01-02T15:04" ),
110- }
111- }
112-
11393 // Make request
11494 res , err := makeRequest (ctx , input , h .client , h .endpoint , h .apikey )
11595 if err != nil || len (res .Trip .Legs ) == 0 {
11696 log .For (ctx ).Error ().Err (err ).Msg ("valhalla router failed to calculate route" )
11797 return & model.Directions {Success : false , Exception : aws .String ("could not calculate route" )}, nil
11898 }
11999 // Prepare response
120- ret := makeDirections (res , departAt , arriveBy )
100+ ret := makeDirections (res , departAt )
121101 ret .Origin = wpiWaypoint (req .From )
122102 ret .Destination = wpiWaypoint (req .To )
123103 ret .Success = true
@@ -154,7 +134,7 @@ func makeRequest(ctx context.Context, req Request, client *http.Client, endpoint
154134 return & res , nil
155135}
156136
157- func makeDirections (res * Response , requestedTime time.Time , arriveBy bool ) * model.Directions {
137+ func makeDirections (res * Response , departAt time.Time ) * model.Directions {
158138 // Create itinerary summary
159139 itin := model.Itinerary {}
160140
@@ -166,15 +146,8 @@ func makeDirections(res *Response, requestedTime time.Time, arriveBy bool) *mode
166146 ret .EndTime = & itin .EndTime
167147 ret .DataSource = aws .String ("OSM" )
168148
169- // When arrive_by is set, requestedTime is the desired arrival time;
170- // compute the actual start time by subtracting the total duration.
171- startAt := requestedTime
172- if arriveBy {
173- startAt = requestedTime .Add (- time .Duration (res .Trip .Summary .Time ) * time .Second )
174- }
175-
176149 // Create legs for itinerary
177- prevLegDepartAt := startAt
150+ prevLegDepartAt := departAt
178151 for _ , vleg := range res .Trip .Legs {
179152 // Decode shape using custom 1e6 scale
180153 shapeDecoder := polyline.Codec {
@@ -255,8 +228,8 @@ func makeDirections(res *Response, requestedTime time.Time, arriveBy bool) *mode
255228 // Add summary
256229 itin .Duration = makeDuration (res .Trip .Summary .Time )
257230 itin .Distance = makeDistance (res .Trip .Summary .Length , res .Units )
258- itin .StartTime = startAt
259- itin .EndTime = startAt .Add (time .Duration (res .Trip .Summary .Time ) * time .Second )
231+ itin .StartTime = departAt
232+ itin .EndTime = departAt .Add (time .Duration (res .Trip .Summary .Time ) * time .Second )
260233 itin .From = itin .Legs [0 ].From
261234 itin .To = itin .Legs [0 ].To
262235 ret .Duration = itin .Duration
@@ -269,13 +242,6 @@ func makeDirections(res *Response, requestedTime time.Time, arriveBy bool) *mode
269242type Request struct {
270243 Locations []RequestLocation `json:"locations"`
271244 Costing string `json:"costing"`
272- DateTime * DateTime `json:"date_time,omitempty"`
273- }
274-
275- type DateTime struct {
276- // Type: 0 = current depart, 1 = depart_at, 2 = arrive_by
277- Type int `json:"type"`
278- Value string `json:"value"`
279245}
280246
281247type RequestLocation struct {
0 commit comments