diff --git a/profiles/debug.lua b/profiles/debug.lua index b8e52646d..8895e0bfc 100644 --- a/profiles/debug.lua +++ b/profiles/debug.lua @@ -43,7 +43,7 @@ mode = { -- input tags, normally extracted from OSM data local way = { - highway = 'primary', + highway = 'motorway', name = 'Main Street', --width = '3', --maxspeed = '30', @@ -57,6 +57,9 @@ local way = { --duration = '00:01:00', --hov = 'designated', --access = 'no' + --destination = 'Berlin', + ["destination:ref"] = 'Nuremberg', + --["destination:ref:forward"] = 'Hamburg;Dresden', } -- tag function normally provided via C++ function way:get_value_by_key(k) diff --git a/profiles/lib/destination.lua b/profiles/lib/destination.lua index 93c09b460..371e41ea8 100644 --- a/profiles/lib/destination.lua +++ b/profiles/lib/destination.lua @@ -1,53 +1,32 @@ 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) - 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 + destination_ref = Destination.get_directional_tag(way, is_forward, 'destination:ref') + destination = Destination.get_directional_tag(way, is_forward, 'destination') + return Destination.join(destination_ref, destination) or '' end return Destination \ No newline at end of file diff --git a/profiles/lib/guidance.lua b/profiles/lib/guidance.lua index 4935c0120..78517a74c 100644 --- a/profiles/lib/guidance.lua +++ b/profiles/lib/guidance.lua @@ -61,7 +61,7 @@ function Guidance.set_classification (highway, result, input_way) end 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) if lc ~= nil then result.road_classification.num_lanes = lc @@ -69,14 +69,14 @@ function Guidance.set_classification (highway, result, input_way) else local total_count = 0 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) if fc ~= nil then total_count = fc end end 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) if bc ~= nil then total_count = total_count + bc @@ -96,19 +96,19 @@ local function get_psv_counts(way) local fw = 0; local bw = 0; - if psv and psv ~= "" then + if psv then fw = tonumber(psv) if( fw == nil ) then fw = 0 end end - if psv_forward and psv_forward ~= "" then + if psv_forward then fw = tonumber(psv_forward) if( fw == nil ) then fw = 0 end end - if psv_backward and psv_backward ~= "" then + if psv_backward then bw = tonumber(psv_backward); if( bw == nil ) then bw = 0 @@ -119,8 +119,8 @@ end -- trims lane string with regard to supported lanes local function process_lanes(turn_lane,vehicle_lane,first_count,second_count) - if turn_lane and turn_lane ~= "" then - if vehicle_lane and vehicle_lane ~= "" then + if turn_lane then + if vehicle_lane then turn_lane = applyAccessTokens(turn_lane,vehicle_lane) elseif first_count ~= 0 or second_count ~= 0 then turn_lane = trimLaneString(turn_lane, first_count, second_count)