smappy 0.0.2 → 0.0.3
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.
- data/Rakefile +7 -7
- data/lib/smappy.rb +1 -1
- data/lib/smappy/marker.rb +5 -6
- data/lib/smappy/static_map.rb +21 -7
- data/lib/smappy/tile.rb +4 -3
- data/spec/smappy/static_map_spec.rb +1 -1
- data/spec/smappy/tile_spec.rb +1 -1
- metadata +10 -4
data/Rakefile
CHANGED
@@ -3,6 +3,8 @@ require 'bundler'
|
|
3
3
|
Bundler.setup
|
4
4
|
Bundler.require
|
5
5
|
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
6
8
|
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
7
9
|
require 'smappy'
|
8
10
|
|
@@ -22,15 +24,13 @@ namespace :smappy do
|
|
22
24
|
# Google Maps tiles:
|
23
25
|
# map.tile_url_template = 'http://mt1.google.com/vt/x=%{x}&y=%{y}&z=%{zoomlevel}'
|
24
26
|
|
25
|
-
|
26
|
-
drawing = Magick::Draw.new
|
27
|
+
image = map.to_image
|
27
28
|
|
28
29
|
marker = Smappy::Marker.new(map.center.latitude, map.center.longitude)
|
29
30
|
position = marker.position_on_map(map)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
canvas.write 'tmp/map.png'
|
31
|
+
|
32
|
+
image.compose!(marker.marker_image, position[0], position[1])
|
33
|
+
|
34
|
+
image.save 'tmp/map.png'
|
35
35
|
end
|
36
36
|
end
|
data/lib/smappy.rb
CHANGED
data/lib/smappy/marker.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'open-uri'
|
2
|
-
require '
|
2
|
+
require 'chunky_png'
|
3
3
|
|
4
4
|
module Smappy
|
5
5
|
class Marker < Location
|
@@ -15,11 +15,11 @@ module Smappy
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def width
|
18
|
-
marker_image.
|
18
|
+
marker_image.width
|
19
19
|
end
|
20
20
|
|
21
21
|
def height
|
22
|
-
marker_image.
|
22
|
+
marker_image.height
|
23
23
|
end
|
24
24
|
|
25
25
|
def position_on_map(map)
|
@@ -30,9 +30,8 @@ module Smappy
|
|
30
30
|
|
31
31
|
# UNTESTED:
|
32
32
|
def marker_image
|
33
|
-
@marker_image ||= (
|
34
|
-
|
35
|
-
Magick::Image.from_blob(data).first
|
33
|
+
@marker_image ||= ChunkyPNG::Image.from_datastream(
|
34
|
+
ChunkyPNG::Datastream.from_io(open(image))
|
36
35
|
)
|
37
36
|
end
|
38
37
|
end
|
data/lib/smappy/static_map.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'chunky_png'
|
2
2
|
|
3
3
|
module Smappy
|
4
4
|
class StaticMap
|
@@ -67,16 +67,30 @@ module Smappy
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def to_image
|
70
|
-
canvas
|
71
|
-
drawing = Magick::Draw.new
|
70
|
+
canvas = ChunkyPNG::Image.new(width, height)
|
72
71
|
|
73
72
|
tiles.each do |tile|
|
74
|
-
|
75
|
-
|
73
|
+
x, y = tile.position_on_map(self)
|
74
|
+
image = tile.to_image
|
75
|
+
|
76
|
+
if x < 0 || y < 0
|
77
|
+
crop_x = x < 0 ? -x : 0
|
78
|
+
crop_y = y < 0 ? -y : 0
|
79
|
+
x, y = [0, x].max, [0, y].max
|
80
|
+
|
81
|
+
image.crop!(crop_x, crop_y, image.width - crop_x, image.height - crop_y)
|
82
|
+
end
|
83
|
+
|
84
|
+
if x + image.width > canvas.width || y + image.height > height
|
85
|
+
crop_width = [image.width, canvas.width - x].min
|
86
|
+
crop_height = [image.height, canvas.height - y].min
|
87
|
+
|
88
|
+
image.crop!(0, 0, crop_width, crop_height)
|
89
|
+
end
|
90
|
+
|
91
|
+
canvas.compose!(image, x, y)
|
76
92
|
end
|
77
93
|
|
78
|
-
drawing.draw(canvas)
|
79
|
-
|
80
94
|
canvas
|
81
95
|
end
|
82
96
|
end
|
data/lib/smappy/tile.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'open-uri'
|
2
|
-
require '
|
2
|
+
require 'chunky_png'
|
3
3
|
|
4
4
|
module Smappy
|
5
5
|
class Tile
|
@@ -33,8 +33,9 @@ module Smappy
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def to_image
|
36
|
-
|
37
|
-
|
36
|
+
@tile_image ||= ChunkyPNG::Image.from_datastream(
|
37
|
+
ChunkyPNG::Datastream.from_io(open(to_url))
|
38
|
+
)
|
38
39
|
end
|
39
40
|
|
40
41
|
def x
|
data/spec/smappy/tile_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smappy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,8 +12,8 @@ cert_chain: []
|
|
12
12
|
date: 2011-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: chunky_png
|
16
|
+
requirement: &70314486828360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70314486828360
|
25
25
|
description: Generate static maps of map tiles.
|
26
26
|
email: tomeric@eet.nu
|
27
27
|
executables: []
|
@@ -57,12 +57,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
57
|
- - ! '>='
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
hash: 1242191568019221092
|
60
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
64
|
none: false
|
62
65
|
requirements:
|
63
66
|
- - ! '>='
|
64
67
|
- !ruby/object:Gem::Version
|
65
68
|
version: '0'
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
hash: 1242191568019221092
|
66
72
|
requirements: []
|
67
73
|
rubyforge_project:
|
68
74
|
rubygems_version: 1.8.10
|