osrm-backend/profiles/lib/destination.lua
Kajari Ghosh 3f0f0e306b Directional Destination Tags (#3061)
* cucumber test scenarios, #3027

* post review comments

* two tests are still failing

* fixed one test

* passing tests

* cleaner code refactor

* possible sceanrios for destination:ref:forward/backward

* added code for direction:ref:forward/backward, tests pass

* changelog

* store direction in variable

* added tags to taginfo

* fixed dumb error

* use boolean flags

* null pointer checks

* hopefully better null pointer checks
2016-10-18 23:09:19 -04:00

53 lines
1.5 KiB
Lua

local Destination = {}
function Destination.get_destination(way, is_forward)
local destination = way:get_value_by_key("destination")
local destination_forward = way:get_value_by_key("destination:forward")
local destination_backward = way:get_value_by_key("destination:backward")
local destination_ref = way:get_value_by_key("destination:ref")
local destination_ref_forward = way:get_value_by_key("destination:ref:forward")
local destination_ref_backward = way:get_value_by_key("destination:ref:backward")
-- Assemble destination as: "A59: Düsseldorf, Köln"
-- destination:ref ^ ^ destination
local rv = ""
if destination_ref then
if is_forward == true and destination_ref == "" then
if destination_ref_forward then
destination_ref = destination_ref_forward
end
elseif is_forward == false then
if destination_ref_backward then
destination_ref = destination_ref_backward
end
end
rv = rv .. string.gsub(destination_ref, ";", ", ")
end
if destination then
if is_forward == true and destination == "" then
if destination_forward then
destination = destination_forward
end
elseif is_forward == false then
if destination_backward then
destination = destination_backward
end
end
if destination ~= "" then
if rv ~= "" then
rv = rv .. ": "
end
rv = rv .. string.gsub(destination, ";", ", ")
end
end
return rv
end
return Destination