Skip to content

Commit

Permalink
refactor: More shape refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson committed Jul 16, 2024
1 parent 0d93ab0 commit b78f24b
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/realtime/shape.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,19 @@ defmodule Realtime.Shape do
encoded_polyline:
(before_detour ++ detour_coordinates ++ after_detour)
|> Enum.map(fn
%Schedule.Gtfs.Shape.Point{} = point ->
{:ok, location} = Util.Location.From.as_location(point)
location

other ->
other
end)
|> Enum.map(fn
# The coordinates that come from the route segments are
# formatted as `Util.Location`'s.
%Location{latitude: latitude, longitude: longitude} ->
# The coordinates that come from the detour shape, from
# `OpenRouteServiceAPI`, are formatted as "lat"/"lon"
# `Map`'s,
%{"lat" => latitude, "lon" => longitude} ->
{longitude, latitude}

# ...but the coordinates that come from the detour shape, from
# `OpenRouteServiceAPI`, are formatted as "lat"/"lon" `Map`'s,
# so we need to handle both cases.
%{"lat" => latitude, "lon" => longitude} ->
# ...but the coordinates that come from the route segments
# are formatted as `Util.Location.From`'s, so we need to
# handle both cases.
point ->
%Location{latitude: latitude, longitude: longitude} =
Util.Location.as_location!(point)

{longitude, latitude}
end)
|> Polyline.encode()
Expand Down

0 comments on commit b78f24b

Please sign in to comment.