osm-rb 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -1
- data/README.md +12 -11
- data/lib/osm/calculator.rb +1 -1
- data/lib/osm/exporter.rb +25 -0
- data/lib/osm.rb +1 -1
- data/osm-rb.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8feaaa2f9e992e40a1a90e217f0740456b3c27d82738dbe3d4bc918c08456f9c
|
4
|
+
data.tar.gz: 1059922372bcc067c1830686920b288be65600f7509edf634874d4e1cb4ac6e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29a57400d2768ebb8b43efb2628dd678cad766e5a6c67368409d74861f9168931f98061ab8c2170df71d8cde6902017edf1941e311511ffbbb60774a0a1402a9
|
7
|
+
data.tar.gz: fca6d5e9e6231adce2016b94b839702399711893e8a74620bb718d91759b6d753cbc722045a0d518d4c95ff1b1674c62e10f68538bf1cca88f440bb1f3f9c6f4
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
osm-rb (0.0.
|
4
|
+
osm-rb (0.0.3)
|
5
|
+
oily_png (~> 1.2.1)
|
5
6
|
typhoeus (~> 1.3.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
chunky_png (1.3.11)
|
10
12
|
diff-lcs (1.3)
|
11
13
|
ethon (0.12.0)
|
12
14
|
ffi (>= 1.3.0)
|
13
15
|
ffi (1.12.2)
|
16
|
+
oily_png (1.2.1)
|
17
|
+
chunky_png (~> 1.3.7)
|
14
18
|
rake (13.0.1)
|
15
19
|
rspec (3.9.0)
|
16
20
|
rspec-core (~> 3.9.0)
|
data/README.md
CHANGED
@@ -24,25 +24,26 @@ OSM-rb exposes two distincts APIs.
|
|
24
24
|
|
25
25
|
The calculator helps you with everything regarding projections, tile names and bounds.
|
26
26
|
|
27
|
-
|
27
|
+
You can use the calculator to calculate and set the required zoom level to fit your bounds
|
28
28
|
|
29
29
|
```ruby
|
30
|
+
path = [
|
31
|
+
OpenStruct.new(lat: 46.95127, lng: 7.43878),
|
32
|
+
OpenStruct.new(lat: 46.92771, lng: 7.44610),
|
33
|
+
OpenStruct.new(lat: 46.94764, lng: 7.37527)
|
34
|
+
]
|
30
35
|
padding = OpenStruct.new(x: 50, y: 40)
|
31
36
|
target_size = OpenStruct.new(x: 800, y: 600)
|
32
|
-
|
37
|
+
|
38
|
+
zoom_level = OSM::Calculator.get_zoom_level(path, padding, target_size)
|
39
|
+
zoom_level # => 13
|
33
40
|
```
|
34
41
|
|
35
|
-
Once you
|
36
|
-
level
|
42
|
+
Once you know the required zoom level, you can create a calculator. You always need to
|
43
|
+
pass it a zoom level, target padding and the target map size
|
37
44
|
|
38
45
|
```ruby
|
39
|
-
|
40
|
-
OpenStruct.new(lat: 46.95127, lng: 7.43878),
|
41
|
-
OpenStruct.new(lat: 46.92771, lng: 7.44610),
|
42
|
-
OpenStruct.new(lat: 46.94764, lng: 7.37527)
|
43
|
-
]
|
44
|
-
zoom = calculator.zoom_level(path)
|
45
|
-
zoom # => 13
|
46
|
+
calculator = Calculator.new(padding, target_size)
|
46
47
|
```
|
47
48
|
|
48
49
|
Calculate required tiles to fit the map as specified
|
data/lib/osm/calculator.rb
CHANGED
data/lib/osm/exporter.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'typhoeus'
|
2
|
+
require 'chunky_png'
|
2
3
|
|
3
4
|
module OSM
|
4
5
|
class Exporter
|
@@ -25,5 +26,29 @@ module OSM
|
|
25
26
|
request.response.body
|
26
27
|
end
|
27
28
|
end
|
29
|
+
|
30
|
+
def stitch(blobs, tile_dimensions)
|
31
|
+
width = tile_dimensions.x
|
32
|
+
height = tile_dimensions.y
|
33
|
+
png = ChunkyPNG::Image.new(width * TILE_SIZE, height * TILE_SIZE, ChunkyPNG::Color::WHITE)
|
34
|
+
count = 0
|
35
|
+
(0...height).each do |y|
|
36
|
+
(0...width).each do |x|
|
37
|
+
tile = ChunkyPNG::Image.from_blob(blobs[count])
|
38
|
+
png.replace!(tile, x * TILE_SIZE, y * TILE_SIZE)
|
39
|
+
count += 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
png
|
43
|
+
end
|
44
|
+
|
45
|
+
def draw_line(png, coordinates)
|
46
|
+
str = coordinates.map { |c| "(#{c.x},#{c.y})" }.join(' ')
|
47
|
+
png.polygon(str, ChunkyPNG::Color.rgb(255, 0, 0))
|
48
|
+
end
|
49
|
+
|
50
|
+
def crop(png, crop_dimensions, target_size)
|
51
|
+
png.crop(crop_dimensions.x, crop_dimensions.y, target_size.x, target_size.y)
|
52
|
+
end
|
28
53
|
end
|
29
54
|
end
|
data/lib/osm.rb
CHANGED
data/osm-rb.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osm-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas_Skywalker
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.3.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: oily_png
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.2.1
|
69
83
|
description: '["OSM-rb", "allows", "you", "to", "manipulate", "and", "export", "OSM",
|
70
84
|
"map", "tiles.", "This", "includes", "downloading", "tiles,cropping", "to", "any",
|
71
85
|
"specified", "region,", "drawing", "routes", "on", "the", "map", "and", "exporting",
|