osrm 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -1
- data/lib/osrm.rb +4 -4
- data/lib/osrm/configuration.rb +14 -1
- data/lib/osrm/query.rb +13 -5
- data/lib/osrm/route.rb +4 -3
- data/lib/osrm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 169960f4f55e9adb038d4d74352338acf90947b6
|
|
4
|
+
data.tar.gz: 713c1b28e080c8c48e1f3d3327ae80f2ecf15dc3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec89dcde3038a0ad936478b4fe8315494a25bcf4740eecbdaf7b71b8f1c822435385284d761491457b89810ceb00ca177756ea479eb94fb805dfdcd7f6e61238
|
|
7
|
+
data.tar.gz: caa178c62c8ac16d7182da470afa56e58168c698289293a466fa236ff23115561877f9f6d48418322fa5d7226c43e3871efdc6cae96e06edb56884a3f440a300
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -29,7 +29,11 @@ You can [run your own server](https://github.com/Project-OSRM/osrm-backend/wiki)
|
|
|
29
29
|
# The cache can be any object providing [] and []= methods.
|
|
30
30
|
# The cache key must contain the {url} pattern.
|
|
31
31
|
cache: {}, # Default: nil (no cache)
|
|
32
|
-
cache_key: 'my-script:{url}'
|
|
32
|
+
cache_key: 'my-script:{url}', # Default: 'osrm:{url}'
|
|
33
|
+
|
|
34
|
+
# Requests
|
|
35
|
+
# Specify the precision of the overview geometries returned
|
|
36
|
+
overview: :full # Possible values: false, :simplified (default), :full
|
|
33
37
|
|
|
34
38
|
)
|
|
35
39
|
|
data/lib/osrm.rb
CHANGED
|
@@ -12,11 +12,11 @@ module OSRM
|
|
|
12
12
|
Configuration.instance
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def self.routes(*locations)
|
|
16
|
-
Query.new(*locations).execute
|
|
15
|
+
def self.routes(*locations, overview: nil)
|
|
16
|
+
Query.new(*locations).execute(alternatives: true, overview: overview)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def self.route(*locations)
|
|
20
|
-
|
|
19
|
+
def self.route(*locations, overview: nil)
|
|
20
|
+
Query.new(*locations).execute(alternatives: false, overview: overview).first
|
|
21
21
|
end
|
|
22
22
|
end
|
data/lib/osrm/configuration.rb
CHANGED
|
@@ -16,7 +16,9 @@ module OSRM
|
|
|
16
16
|
after_request: nil,
|
|
17
17
|
|
|
18
18
|
cache: nil,
|
|
19
|
-
cache_key: 'osrm:{url}'
|
|
19
|
+
cache_key: 'osrm:{url}',
|
|
20
|
+
|
|
21
|
+
overview: :simplified
|
|
20
22
|
}.freeze
|
|
21
23
|
|
|
22
24
|
DEMO_SERVER = 'router.project-osrm.org'.freeze
|
|
@@ -105,6 +107,17 @@ module OSRM
|
|
|
105
107
|
ensure_cache_version
|
|
106
108
|
end
|
|
107
109
|
|
|
110
|
+
def overview=(overview)
|
|
111
|
+
ensure_valid_overview(overview)
|
|
112
|
+
@data[:overview] = overview
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def ensure_valid_overview(overview)
|
|
116
|
+
unless [false, :simplified, :full].include?(overview)
|
|
117
|
+
raise "OSRM API error: Invalid overview type #{overview.inspect}"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
108
121
|
# Dynamically add missing accessors
|
|
109
122
|
DEFAULTS.each do |option, default_value|
|
|
110
123
|
reader = case default_value
|
data/lib/osrm/query.rb
CHANGED
|
@@ -11,8 +11,8 @@ module OSRM
|
|
|
11
11
|
@locations = locations.compact.reject(&:empty?)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def execute
|
|
15
|
-
build_uri
|
|
14
|
+
def execute(alternatives: nil, overview: nil)
|
|
15
|
+
build_uri(alternatives: alternatives, overview: overview)
|
|
16
16
|
fetch_json_data[:routes].map { |route| Route.new(route) }
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -86,7 +86,7 @@ module OSRM
|
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
def build_uri
|
|
89
|
+
def build_uri(alternatives: nil, overview: nil)
|
|
90
90
|
raise "OSRM API error: Server isn't configured" unless configuration.server
|
|
91
91
|
|
|
92
92
|
service = 'route'
|
|
@@ -94,9 +94,17 @@ module OSRM
|
|
|
94
94
|
profile = 'driving'
|
|
95
95
|
format = 'json'
|
|
96
96
|
|
|
97
|
+
alternatives = alternatives.nil? ? false : (alternatives == true)
|
|
98
|
+
if overview.nil?
|
|
99
|
+
overview = configuration.overview
|
|
100
|
+
else
|
|
101
|
+
configuration.ensure_valid_overview(overview)
|
|
102
|
+
end
|
|
103
|
+
|
|
97
104
|
params = [
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
['alternatives', alternatives.to_s],
|
|
106
|
+
['geometries', 'polyline'],
|
|
107
|
+
['overview', overview.to_s]
|
|
100
108
|
]
|
|
101
109
|
|
|
102
110
|
uri_class = configuration.use_ssl? ? URI::HTTPS : URI::HTTP
|
data/lib/osrm/route.rb
CHANGED
|
@@ -6,14 +6,15 @@ module OSRM
|
|
|
6
6
|
|
|
7
7
|
def initialize(json = {})
|
|
8
8
|
@geometry = decode_geometry(json[:geometry])
|
|
9
|
-
@distance = json[:distance]
|
|
10
|
-
@duration = json[:duration]
|
|
9
|
+
@distance = json[:distance].to_f
|
|
10
|
+
@duration = json[:duration].to_f
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
private
|
|
14
14
|
|
|
15
15
|
def decode_geometry(geometry)
|
|
16
|
-
return
|
|
16
|
+
return nil if geometry.nil?
|
|
17
|
+
return [] if geometry.empty?
|
|
17
18
|
|
|
18
19
|
EncodedPolyline.decode_points(geometry, 5).map do |point|
|
|
19
20
|
point.map { |coordinate| fix_float_precision(coordinate) }
|
data/lib/osrm/version.rb
CHANGED