dotter 0.1.1 → 0.1.2
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/README.rdoc +8 -8
- data/VERSION +1 -1
- data/dotter.gemspec +5 -4
- data/lib/dotter/tile.rb +21 -18
- data/spec/dotter/tile_spec.rb +7 -6
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -3,19 +3,19 @@
|
|
3
3
|
Simple library for drawing dots (for google maps).
|
4
4
|
|
5
5
|
== Usage
|
6
|
-
|
6
|
+
First you must create a tile (which will represent google maps tile). Tile takes tile start (latlng coordinates of upper left corner) and zoom. More on google maps tiles: http://code.google.com/apis/maps/documentation/overlays.html#Google_Maps_Coordinates
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
tile_start = Dotter::LatLng.new(tile_start_latitude, tile_start_longitude)
|
9
|
+
tile = Dotter::Tile.new(tile_start, zoom)
|
10
10
|
|
11
|
-
|
11
|
+
tile.places = places_array # places should respond_to latitude and longitude
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
dotter = Dotter::Dotter.new(:dots => tile.convert_places)
|
14
|
+
dotter.generate_image # Magick::Image instance containing transparent image with dots
|
15
15
|
|
16
|
-
|
16
|
+
This will generate image of a tile with dots representing given places.
|
17
17
|
|
18
|
-
|
18
|
+
Dots are black by default. If you want to color them, objects passed as a dots should respond_to :dot_color method. dot_color should return string representing color, for list of available color names visit: http://www.imagemagick.org/RMagick/doc/imusage.html#color_names
|
19
19
|
|
20
20
|
|
21
21
|
TODO: write short note about implementing it in google maps
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/dotter.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dotter}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Piotr Sarnacki"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-11-02}
|
13
13
|
s.description = %q{Simple lib drawing dots on transparent image}
|
14
14
|
s.email = %q{drogus@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -67,3 +67,4 @@ Gem::Specification.new do |s|
|
|
67
67
|
s.add_dependency(%q<rspec>, [">= 0"])
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
data/lib/dotter/tile.rb
CHANGED
@@ -9,36 +9,36 @@
|
|
9
9
|
# tile_start = Dotter::LatLng.new(tile_start_latitude, tile_start_longitude)
|
10
10
|
# tile = Dotter::Tile.new(tile_start, zoom)
|
11
11
|
#
|
12
|
-
# tile.
|
12
|
+
# tile.locations = locations_array # locations should respond_to latitude and longitude
|
13
13
|
#
|
14
14
|
# tile.image # generates RMagick::Magick image with "png" format set
|
15
15
|
#
|
16
16
|
# You can also use tile in Dotter::Dotter explicitly (tile.image is a simple helper, but if you want to set some specific options you will have to do that this way):
|
17
|
-
# dots = tile.
|
17
|
+
# dots = tile.generate_xy_coordinates!
|
18
18
|
# dotter = Dotter::Dotter.new(:dots => dots)
|
19
19
|
# dotter.generate_image
|
20
20
|
#
|
21
|
-
# It passes
|
21
|
+
# It passes locations changed into points relative to current tile's start.
|
22
22
|
#
|
23
23
|
class Dotter::Tile
|
24
|
-
attr_accessor :zoom, :start, :
|
24
|
+
attr_accessor :zoom, :start, :locations
|
25
25
|
def initialize(latlng, zoom)
|
26
26
|
@zoom = zoom.to_i
|
27
27
|
@start = Dotter::GMap.latlng_to_pixel(latlng, @zoom)
|
28
28
|
end
|
29
29
|
|
30
|
-
# Method that takes
|
30
|
+
# Method that takes loactions passed to Tile and converts them into points with x an y relative to tile start
|
31
31
|
#
|
32
32
|
# ==== Returns
|
33
33
|
# Array[~x, ~y]:: points array
|
34
|
-
def
|
34
|
+
def locations_as_points(options = {})
|
35
35
|
points = []
|
36
|
-
|
37
|
-
latlng = Dotter::LatLng.new(
|
36
|
+
locations.each do |location|
|
37
|
+
latlng = Dotter::LatLng.new(location.latitude, location.longitude)
|
38
38
|
point = Dotter::GMap.latlng_to_pixel(latlng, zoom)
|
39
|
-
point = point - start #
|
39
|
+
point = point - start # location is relative to big map, let's make it relative to start of tile
|
40
40
|
if block_given?
|
41
|
-
yield(point,
|
41
|
+
yield(point, location)
|
42
42
|
else
|
43
43
|
points << point
|
44
44
|
end
|
@@ -46,20 +46,23 @@ class Dotter::Tile
|
|
46
46
|
points
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
def convert_places_to_points
|
50
|
+
self.locations = locations_as_points
|
51
|
+
end
|
52
|
+
|
53
|
+
# Method sets x and y coordinates for each place
|
50
54
|
#
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
def generate_xy_coordinates!
|
56
|
+
locations_as_points do |point, location|
|
57
|
+
location.x = point.x
|
58
|
+
location.y = point.y
|
55
59
|
end
|
56
|
-
|
57
|
-
places
|
60
|
+
locations
|
58
61
|
end
|
59
62
|
|
60
63
|
# Generate tile image with Dotter
|
61
64
|
def image
|
62
|
-
dotter = Dotter::Dotter.new(:dots =>
|
65
|
+
dotter = Dotter::Dotter.new(:dots => locations)
|
63
66
|
img = dotter.generate_image
|
64
67
|
img.format = "png"
|
65
68
|
img
|
data/spec/dotter/tile_spec.rb
CHANGED
@@ -12,7 +12,8 @@ describe "Dotter::Tile" do
|
|
12
12
|
# i know that this isn't good spec, it's just to run code and see it if not fails
|
13
13
|
# need to add more specs fot Tile
|
14
14
|
tile = Dotter::Tile.new(Dotter::LatLng.new(0, 0), 0)
|
15
|
-
tile.
|
15
|
+
tile.locations = [Dotter::LatLng.new(0, 0)]
|
16
|
+
tile.convert_places_to_points
|
16
17
|
tile.image.class.should == Magick::Image
|
17
18
|
lambda { tile.image.to_blob }.should_not raise_error
|
18
19
|
end
|
@@ -21,11 +22,11 @@ describe "Dotter::Tile" do
|
|
21
22
|
before(:each) do
|
22
23
|
@tile = Dotter::Tile.new(Dotter::LatLng.new(0, 0), 1)
|
23
24
|
@places = [Dotter::LatLng.new(0, 0), Dotter::LatLng.new(-85.1, 180)]
|
24
|
-
@tile.
|
25
|
+
@tile.locations = @places
|
25
26
|
end
|
26
27
|
|
27
28
|
it "should convert places to points" do
|
28
|
-
points = @tile.
|
29
|
+
points = @tile.locations_as_points
|
29
30
|
points.should have(2).items
|
30
31
|
points.first.x.should == 0
|
31
32
|
points.first.y.should == 0
|
@@ -34,10 +35,10 @@ describe "Dotter::Tile" do
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should set x and y in current points if points responds_to x= and x=" do
|
37
|
-
stub_point(@tile.
|
38
|
-
stub_point(@tile.
|
38
|
+
stub_point(@tile.locations[0], 0, 0)
|
39
|
+
stub_point(@tile.locations[1], 111, 111)
|
39
40
|
|
40
|
-
@tile.
|
41
|
+
@tile.generate_xy_coordinates!
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Sarnacki
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-02 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|