Some improvements in code

This commit is contained in:
Denis Koronchik 2017-09-14 18:44:24 +03:00 committed by Patrick Niklaus
parent 3634aa9a3c
commit 3fd961a551
2 changed files with 17 additions and 32 deletions

View File

@ -403,20 +403,16 @@ function process_way(profile, way, result, relations)
if result.ref then
local match_res = Relations.match_to_ref(relations, result.ref)
order = match_res['order']
matched_refs = match_res['match']
local ref = ''
for _, k in pairs(order) do
local v = matched_refs[k]
for _, m in pairs(match_res) do
if ref ~= '' then
ref = ref .. '; '
end
if v then
ref = ref .. k .. ' $' .. v
if m.dir then
ref = ref .. m.ref .. ' $' .. m.dir
else
ref = ref .. k
ref = ref .. m.ref
end
end
@ -431,35 +427,35 @@ function process_relation(profile, relation, result)
function add_extra_data(m)
local name = relation:get_value_by_key("name")
if name then
result[m]["route_name"] = name
result[m]['route_name'] = name
end
local ref = relation:get_value_by_key("ref")
if ref then
result[m]["route_ref"] = ref
result[m]['route_ref'] = ref
end
end
if t == "route" then
if t == 'route' then
local route = relation:get_value_by_key("route")
if route == "road" then
if route == 'road' then
for _, m in ipairs(relation:members()) do
-- process case, where directions set as role
local role = string.lower(m:role())
if role == "north" or role == "south" or role == "west" or role == "east" then
result[m]["route_direction"] = role
if role == 'north' or role == 'south' or role == 'west' or role == 'east' then
result[m]['route_direction'] = role
add_extra_data(m)
end
end
end
local direction = relation:get_value_by_key("direction")
local direction = relation:get_value_by_key('direction')
if direction then
direction = string.lower(direction)
if direction == "north" or direction == "south" or direction == "west" or direction == "east" then
if direction == 'north' or direction == 'south' or direction == 'west' or direction == 'east' then
for _, m in ipairs(relation:members()) do
if m:role() == "forward" then
result[m]["route_direction"] = direction
if m:role() == 'forward' then
result[m]['route_direction'] = direction
add_extra_data(m)
end
end

View File

@ -7,18 +7,6 @@ Utils = require('lib/utils')
Relations = {}
function Relations.Merge(relations)
local result = {}
for _, r in ipairs(relations) do
for k, v in pairs(r) do
result[k] = v
end
end
return result
end
-- match ref values to relations data
function Relations.match_to_ref(relations, ref)
@ -96,8 +84,9 @@ function Relations.match_to_ref(relations, ref)
end
local result = {}
result['order'] = order
result['match'] = result_match
for i, r in ipairs(order) do
result[i] = { ref = r, dir = result_match[r] };
end
return result
end