Add local left_hand_driving flag in API version 2

This commit is contained in:
Michael Krasnyk
2017-08-15 16:53:27 +02:00
parent af3f0a4782
commit de942155bf
11 changed files with 96 additions and 39 deletions
+6 -9
View File
@@ -9,11 +9,9 @@ find_access_tag = require("lib/access").find_access_tag
limit = require("lib/maxspeed").limit
function setup()
local use_left_hand_driving = false
return {
properties = {
max_speed_for_map_matching = 180/3.6, -- 180kmph -> m/s
left_hand_driving = use_left_hand_driving,
-- For routing based on duration, but weighted for preferring certain roads
weight_name = 'routability',
-- For shortest duration without penalties for accessibility
@@ -27,16 +25,14 @@ function setup()
traffic_light_penalty = 2,
},
left_hand_driving = false,
default_mode = mode.driving,
default_speed = 10,
oneway_handling = true,
side_road_multiplier = 0.8,
turn_penalty = 7.5,
speed_reduction = 0.8,
-- Note: this biases right-side driving.
-- Should be inverted for left-driving countries.
turn_bias = use_left_hand_driving and 1/1.075 or 1.075,
turn_bias = 1.075,
-- a list of suffixes to suppress in name change instructions
suffix_list = {
@@ -307,7 +303,7 @@ function process_node(profile, node, result)
end
end
function process_way(profile, way, result)
function process_way(profile, way, result, location_data)
-- the intial filtering of ways based on presence of tags
-- affects processing times significantly, because all ways
-- have to be checked.
@@ -382,6 +378,7 @@ function process_way(profile, way, result)
-- handle various other flags
WayHandlers.roundabouts,
WayHandlers.startpoint,
WayHandlers.driving_side,
-- set name, ref and pronunciation
WayHandlers.names,
@@ -390,7 +387,7 @@ function process_way(profile, way, result)
WayHandlers.weights
}
WayHandlers.run(profile,way,result,data,handlers)
WayHandlers.run(profile, way, result, data, handlers, location_data)
end
function process_turn(profile, turn)
@@ -398,7 +395,7 @@ function process_turn(profile, turn)
-- over the space of 0-180 degrees. Values here were chosen by fitting
-- the function to some turn penalty samples from real driving.
local turn_penalty = profile.turn_penalty
local turn_bias = profile.turn_bias
local turn_bias = turn.is_left_hand_driving and 1. / profile.turn_bias or profile.turn_bias
if turn.has_traffic_light then
turn.duration = profile.properties.traffic_light_penalty
+17 -3
View File
@@ -552,6 +552,20 @@ function WayHandlers.blocked_ways(profile,way,result,data)
end
end
function WayHandlers.driving_side(profile, way, result, data, location_data)
local driving_side = way:get_value_by_key("driving_side")
if driving_side == 'left' then
result.is_left_hand_driving = true
elseif driving_side == 'right' then
result.is_left_hand_driving = false
elseif location_data then
result.is_left_hand_driving = location_data['driving_side'] == 'left'
elseif profile.left_hand_driving then
result.is_left_hand_driving = true
end
end
-- Call a sequence of handlers, aborting in case a handler returns false. Example:
--
-- handlers = Sequence {
@@ -566,13 +580,13 @@ end
-- WayHandlers.run(handlers,way,result,data,profile)
--
-- Each method in the list will be called on the WayHandlers object.
-- All handlers must accept the parameteres (profile,way,result,data) and return false
-- All handlers must accept the parameteres (profile, way, result, data[, location_data]) and return false
-- if the handler chain should be aborted.
-- To ensure the correct order of method calls, use a Sequence of handler names.
function WayHandlers.run(profile,way,result,data,handlers)
function WayHandlers.run(profile, way, result, data, handlers, location_data)
for i,handler in ipairs(handlers) do
if handler(profile,way,result,data) == false then
if handler(profile, way, result, data, location_data) == false then
return false
end
end