Tilemaker provides two methods for dealing with nested relations (e.g., a route inside a superroute):
1. Processing nested relations in relation_function
You can iterate through parent relations within relation_function using NextRelation() and FindInRelation(key), just as you would for ways or nodes. Note that you must Accept() the parent relations in relation_scan_function first.
2. Bouncing tags down with relation_postscan_function
Because the main processing functions (way_function, node_function, relation_function) only support one level of parent relations for performance, you can use relation_postscan_function to handle deeper hierarchies (grandparents, etc.).
This function runs after relation_scan_function when all accepted relations are in memory. You can read ancestor tags and use SetTag(key, value) to apply them to the child relation. These tags will then be available to the standard processing functions.
Note: In deeply nested hierarchies, tilemaker flattens the structure during the postscan, so the original hierarchy is not preserved.
-- Use relation_postscan_function to pass tags from a parent to a child
function relation_postscan_function()
while true do
local parent, role = NextRelation()
if not parent then break end
if FindInRelation("type")=="superroute" then
local parent_name = FindInRelation("name")
SetTag("name", parent_name)
end
end
end