-
Notifications
You must be signed in to change notification settings - Fork 2
/
bicycle_handlers.lua
88 lines (81 loc) · 3.26 KB
/
bicycle_handlers.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
MyHandlers = {}
function MyHandlers.segregated(profile,way,result,data)
-- set speed to normal on a footway that has segregated bikelane
if way:get_value_by_key("segregated") == "yes" and data.bicycle and profile.access_tag_whitelist[data.bicycle] then
result.forward_speed = default_speed
result.backward_speed = default_speed
result.forward_mode = mode.cycling
result.backward_mode = mode.cycling
end
end
function MyHandlers.cycleways(profile,way,result,data)
-- higher rates on cycleways
if data.highway == 'cycleway' then
if way:get_value_by_key("segregated") == "no" then
result.forward_rate = result.forward_rate*1.2
result.backward_rate = result.backward_rate*1.2
else
result.forward_rate = result.forward_rate*1.4
result.backward_rate = result.backward_rate*1.4
end
end
if data.highway == 'cycleway' and foot ~= 'yes' and foot ~= 'designated' then
result.forward_rate = result.forward_rate*1.5
result.backward_rate = result.backward_rate*1.5
end
end
function MyHandlers.bicycleways(profile,way,result,data)
-- higher rate on sharrows or lanes
if data.bicycle and profile.cycleway_tags[bicycle] and data.highway ~= 'cycleway' then
if result.forward_mode == mode.cycling then result.forward_rate = result.forward_rate*1.2 end
if result.backward_mode == mode.cycling then result.backward_rate = result.backward_rate*1.2 end
end
end
function MyHandlers.bicyclerelations(profile,way,result,data, relations)
-- higher rate on ways that are a part of bicycle relation
local rels = get_from_rel(relations, way, "route", 'bicycle', "route")
if rels and rels == 'bicycle' then
if result.forward_mode == mode.cycling then result.forward_rate = result.forward_rate*1.4 end
if result.backward_mode == mode.cycling then result.backward_rate = result.backward_rate*1.4 end
end
end
function MyHandlers.penaltymajorroads(profile,way,result,data, relations)
-- penalty if maxspeed
local bus = get_from_rel(relations, way, "route", 'bus', "route")
local trolleybus = get_from_rel(relations, way, "route", 'bus', "route")
local lanes = tonumber(way:get_value_by_key("lanes"));
local maxspeed = tonumber(way:get_value_by_key("maxspeed"));
if bus and bus== 'bus' or trolleybus and trolleybus == 'trolleybus' or lanes and lanes >= 2 or maxspeed and maxspeed >= 60 then
result.forward_rate = result.forward_rate * 0.5;
result.backward_rate = result.backward_rate * 0.5
end
end
function bicycleaccess(profile,source)
-- test access tags: bicycle, (vehicle=no and foot=yes=> dismount), vehicle, access
local bicycle = source:get_value_by_key('bicycle')
if bicycle and profile.access_tag_blacklist[bicycle] then
return false
end
if bicycle then
return true
end
local foot = source:get_value_by_key('foot')
local vehicle = source:get_value_by_key('vehicle')
if vehicle and profile.access_tag_blacklist[vehicle] and foot and not profile.access_tag_blacklist[foot] then
return true
end
if vehicle and profile.access_tag_blacklist[vehicle] then
return false
end
if vehicle then
return true
end
local access = source:get_value_by_key('access')
if access and profile.access_tag_blacklist[access] then
return false
end
if access then
return true
end
return true
end