This commit is contained in:
MichalPP 2018-05-30 10:51:48 +00:00 committed by GitHub
commit 8ea0090c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -5,6 +5,7 @@ api_version = 4
Set = require('lib/set') Set = require('lib/set')
Sequence = require('lib/sequence') Sequence = require('lib/sequence')
Handlers = require("lib/way_handlers") Handlers = require("lib/way_handlers")
Relations = require("lib/relations")
find_access_tag = require("lib/access").find_access_tag find_access_tag = require("lib/access").find_access_tag
limit = require("lib/maxspeed").limit limit = require("lib/maxspeed").limit
@ -32,6 +33,7 @@ function setup()
turn_penalty = 6, turn_penalty = 6,
turn_bias = 1.4, turn_bias = 1.4,
use_public_transport = true, use_public_transport = true,
route_preference = 1.1,
allowed_start_modes = Set { allowed_start_modes = Set {
mode.cycling, mode.cycling,
@ -314,6 +316,7 @@ function handle_bicycle_tags(profile,way,result,data)
end end
safety_handler(profile,way,result,data) safety_handler(profile,way,result,data)
bicycle_relation_handler(profile,way,result,data,relations)
end end
@ -454,6 +457,16 @@ function cycleway_handler(profile,way,result,data)
end end
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) function bike_push_handler(profile,way,result,data)
-- pushing bikes - if no other mode found -- pushing bikes - if no other mode found
if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or

View File

@ -258,4 +258,18 @@ function Relations.process_way_refs(way, relations, result)
end end
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 return Relations