lua: refactor destination helper
This commit is contained in:
parent
dce685c780
commit
00f7d7776d
@ -43,7 +43,7 @@ mode = {
|
|||||||
|
|
||||||
-- input tags, normally extracted from OSM data
|
-- input tags, normally extracted from OSM data
|
||||||
local way = {
|
local way = {
|
||||||
highway = 'primary',
|
highway = 'motorway',
|
||||||
name = 'Main Street',
|
name = 'Main Street',
|
||||||
--width = '3',
|
--width = '3',
|
||||||
--maxspeed = '30',
|
--maxspeed = '30',
|
||||||
@ -57,6 +57,9 @@ local way = {
|
|||||||
--duration = '00:01:00',
|
--duration = '00:01:00',
|
||||||
--hov = 'designated',
|
--hov = 'designated',
|
||||||
--access = 'no'
|
--access = 'no'
|
||||||
|
--destination = 'Berlin',
|
||||||
|
["destination:ref"] = 'Nuremberg',
|
||||||
|
--["destination:ref:forward"] = 'Hamburg;Dresden',
|
||||||
}
|
}
|
||||||
-- tag function normally provided via C++
|
-- tag function normally provided via C++
|
||||||
function way:get_value_by_key(k)
|
function way:get_value_by_key(k)
|
||||||
|
@ -1,53 +1,32 @@
|
|||||||
local Destination = {}
|
local Destination = {}
|
||||||
|
|
||||||
|
function Destination.get_directional_tag(way, is_forward, tag)
|
||||||
|
local v
|
||||||
|
if is_forward then
|
||||||
|
v = way:get_value_by_key(tag .. ':forward') or way:get_value_by_key(tag)
|
||||||
|
else
|
||||||
|
v = way:get_value_by_key(tag .. ':backward') or way:get_value_by_key(tag)
|
||||||
|
end
|
||||||
|
if v then
|
||||||
|
return v.gsub(v, ';', ', ')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Destination.join(a,b)
|
||||||
|
if a and b then
|
||||||
|
return a .. ': ' .. b
|
||||||
|
else
|
||||||
|
return a or b
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Assemble destination as: "A59: Düsseldorf, Köln"
|
||||||
|
-- destination:ref ^ ^ destination
|
||||||
|
|
||||||
function Destination.get_destination(way, is_forward)
|
function Destination.get_destination(way, is_forward)
|
||||||
local destination = way:get_value_by_key("destination")
|
destination_ref = Destination.get_directional_tag(way, is_forward, 'destination:ref')
|
||||||
local destination_forward = way:get_value_by_key("destination:forward")
|
destination = Destination.get_directional_tag(way, is_forward, 'destination')
|
||||||
local destination_backward = way:get_value_by_key("destination:backward")
|
return Destination.join(destination_ref, destination) or ''
|
||||||
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
|
end
|
||||||
|
|
||||||
return Destination
|
return Destination
|
@ -61,7 +61,7 @@ function Guidance.set_classification (highway, result, input_way)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local lane_count = input_way:get_value_by_key("lanes")
|
local lane_count = input_way:get_value_by_key("lanes")
|
||||||
if lane_count and lane_count ~= "" then
|
if lane_count then
|
||||||
local lc = tonumber(lane_count)
|
local lc = tonumber(lane_count)
|
||||||
if lc ~= nil then
|
if lc ~= nil then
|
||||||
result.road_classification.num_lanes = lc
|
result.road_classification.num_lanes = lc
|
||||||
@ -69,14 +69,14 @@ function Guidance.set_classification (highway, result, input_way)
|
|||||||
else
|
else
|
||||||
local total_count = 0
|
local total_count = 0
|
||||||
local forward_count = input_way:get_value_by_key("lanes:forward")
|
local forward_count = input_way:get_value_by_key("lanes:forward")
|
||||||
if forward_count and forward_count ~= "" then
|
if forward_count then
|
||||||
local fc = tonumber(forward_count)
|
local fc = tonumber(forward_count)
|
||||||
if fc ~= nil then
|
if fc ~= nil then
|
||||||
total_count = fc
|
total_count = fc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local backward_count = input_way:get_value_by_key("lanes:backward")
|
local backward_count = input_way:get_value_by_key("lanes:backward")
|
||||||
if backward_count and backward_count ~= "" then
|
if backward_count then
|
||||||
local bc = tonumber(backward_count)
|
local bc = tonumber(backward_count)
|
||||||
if bc ~= nil then
|
if bc ~= nil then
|
||||||
total_count = total_count + bc
|
total_count = total_count + bc
|
||||||
@ -96,19 +96,19 @@ local function get_psv_counts(way)
|
|||||||
|
|
||||||
local fw = 0;
|
local fw = 0;
|
||||||
local bw = 0;
|
local bw = 0;
|
||||||
if psv and psv ~= "" then
|
if psv then
|
||||||
fw = tonumber(psv)
|
fw = tonumber(psv)
|
||||||
if( fw == nil ) then
|
if( fw == nil ) then
|
||||||
fw = 0
|
fw = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if psv_forward and psv_forward ~= "" then
|
if psv_forward then
|
||||||
fw = tonumber(psv_forward)
|
fw = tonumber(psv_forward)
|
||||||
if( fw == nil ) then
|
if( fw == nil ) then
|
||||||
fw = 0
|
fw = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if psv_backward and psv_backward ~= "" then
|
if psv_backward then
|
||||||
bw = tonumber(psv_backward);
|
bw = tonumber(psv_backward);
|
||||||
if( bw == nil ) then
|
if( bw == nil ) then
|
||||||
bw = 0
|
bw = 0
|
||||||
@ -119,8 +119,8 @@ end
|
|||||||
|
|
||||||
-- trims lane string with regard to supported lanes
|
-- trims lane string with regard to supported lanes
|
||||||
local function process_lanes(turn_lane,vehicle_lane,first_count,second_count)
|
local function process_lanes(turn_lane,vehicle_lane,first_count,second_count)
|
||||||
if turn_lane and turn_lane ~= "" then
|
if turn_lane then
|
||||||
if vehicle_lane and vehicle_lane ~= "" then
|
if vehicle_lane then
|
||||||
turn_lane = applyAccessTokens(turn_lane,vehicle_lane)
|
turn_lane = applyAccessTokens(turn_lane,vehicle_lane)
|
||||||
elseif first_count ~= 0 or second_count ~= 0 then
|
elseif first_count ~= 0 or second_count ~= 0 then
|
||||||
turn_lane = trimLaneString(turn_lane, first_count, second_count)
|
turn_lane = trimLaneString(turn_lane, first_count, second_count)
|
||||||
|
Loading…
Reference in New Issue
Block a user