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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6075e05ffaa3072f212363e9ea95a22d1b8643dfd909123bb1ae1afcde66de2
4
- data.tar.gz: 1e374d5a8668079b341ed3120e6f8be1b22f7972c2cab6f8b8153c6ab8f5770e
3
+ metadata.gz: 8feaaa2f9e992e40a1a90e217f0740456b3c27d82738dbe3d4bc918c08456f9c
4
+ data.tar.gz: 1059922372bcc067c1830686920b288be65600f7509edf634874d4e1cb4ac6e2
5
5
  SHA512:
6
- metadata.gz: 75621d2fab5359955a20e77a53be61ff8d279184d17911f970313ed9e290529bcc8c0131fa8746ec0e266ecb5a09a66096dc07221f8201df455b7bf2b48dc588
7
- data.tar.gz: 3edf1546c64fd3bd2300f7f9020098b5617416546b8e1c5e28f6da8c0e3b91f8109f485b6fc849390fcfea088dae9d704b021d03e072e01baf3afaf0385cfc5e
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.2)
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
- To create a calculator you have to pass it a zoom level, padding and the target map size
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
- calculator = Calculator.new(padding, target_size)
37
+
38
+ zoom_level = OSM::Calculator.get_zoom_level(path, padding, target_size)
39
+ zoom_level # => 13
33
40
  ```
34
41
 
35
- Once you have created a calculator, you can use it to calculate and set the required zoom
36
- level to fit your bounds
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
- path = [
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
@@ -11,7 +11,7 @@ module OSM
11
11
  @target_size = target_size
12
12
  end
13
13
 
14
- def zoom_level(path)
14
+ def self.get_zoom_level(path, padding, target_size)
15
15
  18.downto(1) do |level|
16
16
  d = Calculator.new(level, padding, target_size)
17
17
  path_size = d.path_pixel_dimensions(path)
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
@@ -1,5 +1,5 @@
1
1
  module OSM
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
 
4
4
  require_relative 'osm/calculator'
5
5
  require_relative 'osm/exporter'
data/osm-rb.gemspec CHANGED
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
 
37
37
  spec.add_dependency "typhoeus", "~> 1.3.1"
38
+ spec.add_dependency "oily_png", "~> 1.2.1"
38
39
  end
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.3
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",