Merge f2f9990f01 into 06699132eb
This commit is contained in:
commit
8ea0090c0b
@ -5,6 +5,7 @@ api_version = 4
|
||||
Set = require('lib/set')
|
||||
Sequence = require('lib/sequence')
|
||||
Handlers = require("lib/way_handlers")
|
||||
Relations = require("lib/relations")
|
||||
find_access_tag = require("lib/access").find_access_tag
|
||||
limit = require("lib/maxspeed").limit
|
||||
|
||||
@ -32,6 +33,7 @@ function setup()
|
||||
turn_penalty = 6,
|
||||
turn_bias = 1.4,
|
||||
use_public_transport = true,
|
||||
route_preference = 1.1,
|
||||
|
||||
allowed_start_modes = Set {
|
||||
mode.cycling,
|
||||
@ -314,6 +316,7 @@ function handle_bicycle_tags(profile,way,result,data)
|
||||
end
|
||||
|
||||
safety_handler(profile,way,result,data)
|
||||
bicycle_relation_handler(profile,way,result,data,relations)
|
||||
end
|
||||
|
||||
|
||||
@ -454,6 +457,16 @@ function cycleway_handler(profile,way,result,data)
|
||||
end
|
||||
end
|
||||
|
||||
function bicycle_relation_handler(profile,way,result,data,relations)
|
||||
-- prefer ways on route=bicycle by factor of profile.route_preference
|
||||
if result.forward_rate and Relations.filter_relations(relations, way, "route", "bicycle", "route", "forward") == "bicycle" then
|
||||
result.forward_rate = result.forward_rate * profile.route_preference
|
||||
end
|
||||
if result.backward_rate and Relations.filter_relations(relations, way, "route", "bicycle", "route", "backward") == "bicycle" then
|
||||
result.backward_rate = result.backward_rate * profile.route_preference
|
||||
end
|
||||
end
|
||||
|
||||
function bike_push_handler(profile,way,result,data)
|
||||
-- pushing bikes - if no other mode found
|
||||
if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or
|
||||
|
||||
@ -258,4 +258,18 @@ function Relations.process_way_refs(way, relations, result)
|
||||
end
|
||||
end
|
||||
|
||||
function Relations.filter_relations(relations, way, key, value, ret, forward)
|
||||
-- if any of way's relation have key=value, return tag ret; else return nil
|
||||
-- todo: check backward and forward
|
||||
if not forward then forward = 'forward'; end -- ignored at the moment
|
||||
local rel_id_list = relations:get_relations(way)
|
||||
for i, rel_id in ipairs(rel_id_list) do
|
||||
local rel = relations:relation(rel_id);
|
||||
local p = rel:get_value_by_key(key);
|
||||
if value == '*' and p then return rel:get_value_by_key(ret); end
|
||||
if p == value then return rel:get_value_by_key(ret); end
|
||||
end
|
||||
return nil;
|
||||
end
|
||||
|
||||
return Relations
|
||||
|
||||
Loading…
Reference in New Issue
Block a user