mapkit 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,12 @@
1
1
  require File.dirname(__FILE__) + "/mapkit"
2
- require "gd2"
2
+ require 'RMagick' unless defined? Magick
3
3
 
4
4
  # this module helps drawing icons on tile images
5
5
  module TileKit
6
6
  # this class represents an icon that can be drawn on an Image
7
7
  class Icon
8
8
  attr_reader :image, :size
9
-
9
+
10
10
  # initializes the icon with a path, image size [width, height], the peak#
11
11
  # position (where the pointer should be placed) [x, y] and a bounding box
12
12
  # that represents a clickable area
@@ -15,21 +15,21 @@ module TileKit
15
15
  # peak_position:: the peak position as array [x, y]
16
16
  # clickable_area:: the clickable area of the icon as array [top, left, bottom, right]
17
17
  def initialize(path, size, peak_position, clickable_area)
18
- @image = GD2::Image.import(path)
18
+ @image = Magick::Image.read(path)[0]
19
19
  @size_x, @size_y = size
20
20
  @peak_x, @peak_y = peak_position
21
21
  @shift_x, @shift_y, @width, @height = clickable_area
22
22
  end
23
-
23
+
24
24
  # draws the icon on the canvas at passed position (x, y)
25
25
  def draw(canvas, x, y)
26
26
  # position icon at peak point
27
27
  x, y = x - @peak_x, y - @peak_y
28
-
28
+
29
29
  # copy image
30
- canvas.copy_from(@image, x, y, 0, 0, @size_x, @size_y)
30
+ canvas.composite!(@image, Magick::ForgetGravity, x, y, Magick::CopyCompositeOp)
31
31
  end
32
-
32
+
33
33
  # returns a boundingbox (with lat/lng) that contains the bounds of the
34
34
  # image for the passed position
35
35
  def bounding_box(lat, lng, zoom)
@@ -38,27 +38,22 @@ module TileKit
38
38
  MapKit::BoundingBox.new(top, left, bottom, right, zoom)
39
39
  end
40
40
  end
41
-
41
+
42
42
  # this image class represents a tile in the google maps
43
43
  class Image
44
44
  attr_reader :canvas, :bounding_box
45
-
45
+
46
46
  # initialize the image with a (lat/lng) bounding box of the tile it
47
47
  # represents
48
48
  def initialize(bounding_box)
49
49
  @bounding_box = bounding_box
50
-
51
- # create image canvas
52
- @canvas = GD2::Image.new(MapKit::TILE_SIZE, MapKit::TILE_SIZE)
53
50
 
54
- # make image transparent
55
- @canvas.save_alpha = true
56
- @canvas.draw do |context|
57
- context.color = GD2::Color::TRANSPARENT
58
- context.fill
51
+ # create transparent image canvas
52
+ @canvas = Magick::Image.new(MapKit::TILE_SIZE, MapKit::TILE_SIZE) do |c|
53
+ c.background_color= "Transparent"
59
54
  end
60
55
  end
61
-
56
+
62
57
  # draws passed icon at passed position
63
58
  def draw_icon(point, icon)
64
59
  x, y = point.pixel(@bounding_box)
@@ -67,7 +62,7 @@ module TileKit
67
62
 
68
63
  # returns the png binary string of the image
69
64
  def png
70
- @canvas.png
65
+ @canvas.to_blob { |attrs| attrs.format = 'PNG' }
71
66
  end
72
67
  end
73
- end
68
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mapkit'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mapkit}
8
+ s.version = MapKit::VERSION
9
+ s.authors = ["Vincent Landgraf", "Paul Trippett"]
10
+ s.email = ["vilandgr@googlemail.com"]
11
+ s.description = %q{
12
+ MapKit is an set of helpers to assist building tiles for
13
+ the google maps web client using rmagick
14
+ }
15
+ s.summary = 'MapKit helps rendering tiles for google maps'
16
+ s.homepage = 'http://github.com/threez/mapkit'
17
+ s.files = `git ls-files`.split($/)
18
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency('rake')
23
+ s.add_development_dependency('rspec')
24
+ s.add_dependency('httparty', ">= 0.5.2")
25
+ s.add_dependency('rmagick', ">= 2.13.3")
26
+ end
@@ -0,0 +1,154 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe MapKit::Point do
4
+ it "should save and restore lat/lng" do
5
+ point = MapKit::Point.new(45, 45)
6
+ point.lat.should == 45
7
+ point.lng.should == 45
8
+ point.lat = 10
9
+ point.lng = 15
10
+ point.lat.should == 10
11
+ point.lng.should == 15
12
+ end
13
+
14
+ it "should be able to check if it is in a bounding box" do
15
+ point0 = MapKit::Point.new(45, 45)
16
+ point1 = MapKit::Point.new(60, 45)
17
+ point2 = MapKit::Point.new(60, 60)
18
+ box = MapKit::BoundingBox.new(40, 40, 50, 50)
19
+ point0.in?(box).should == true
20
+ point1.in?(box).should == false
21
+ point2.in?(box).should == false
22
+ end
23
+
24
+ it "should be able to calc relative positions based on the bounding box" do
25
+ point = MapKit::Point.new(45, 45)
26
+ box = MapKit::BoundingBox.new(50.0, 40.0, 40.0, 50.0)
27
+ point.pixel(box).should == [4, 5]
28
+ point = MapKit::Point.new(-45, -45)
29
+ box = MapKit::BoundingBox.new(-40.0, -50.0, -50.0, -40.0)
30
+ point.pixel(box).should == [4, 5]
31
+ point = MapKit::Point.new(0, 0)
32
+ box = MapKit::BoundingBox.new(10.0, -10.0, -10.0, 10.0)
33
+ point.pixel(box).should == [7, 7]
34
+ point = MapKit::Point.new(-20, 0)
35
+ box = MapKit::BoundingBox.new(-10.0, -10.0, -30.0, 10.0)
36
+ point.pixel(box).should == [7, 8]
37
+ end
38
+ end
39
+
40
+ describe MapKit::BoundingBox do
41
+ it "should initialize correctly" do
42
+ box = MapKit::BoundingBox.new(1, 2, 3, 4)
43
+ box.coords.should == [1, 2, 3, 4]
44
+ box.top.should == 1
45
+ box.left.should == 2
46
+ box.bottom.should == 3
47
+ box.right.should == 4
48
+ end
49
+
50
+ it "should calculate the span" do
51
+ box = MapKit::BoundingBox.new(3.0, 0, 0, 3.0)
52
+ box.sspn.should == [1.5, 1.5]
53
+ end
54
+
55
+ it "should calculate the releative center position" do
56
+ box = MapKit::BoundingBox.new(2, 0, 0, 2)
57
+ box.center.should == [1, 1]
58
+ box = MapKit::BoundingBox.new(15, 5, 5, 15)
59
+ box.center.should == [10, 10]
60
+ end
61
+
62
+ it "should grow the box by percent correctly" do
63
+ box = MapKit::BoundingBox.new(4.0, 2.0, 2.0, 4.0)
64
+ box.grow!(100)
65
+ box.coords.should == [5.0, 1.0, 1.0, 5.0]
66
+ new_box = box.grow(100)
67
+ new_box.coords.should == [7.0, -1.0, -1.0, 7.0]
68
+ box.coords.should == [5.0, 1.0, 1.0, 5.0]
69
+ end
70
+ end
71
+
72
+ class Float
73
+ def round(precition)
74
+ precition = 10.0 ** (precition)
75
+ (self * precition).floor / precition
76
+ end
77
+ end
78
+
79
+ describe MapKit do
80
+ it "should calculate the zoom levels" do
81
+ MapKit.resolution(0).round(4).should == 156543.0339.round(4)
82
+ MapKit.resolution(1).round(4).should == 78271.5169.round(4)
83
+ MapKit.resolution(2).round(4).should == 39135.7584.round(4)
84
+ MapKit.resolution(3).round(4).should == 19567.8792.round(4)
85
+ MapKit.resolution(4).round(4).should == 9783.9396.round(4)
86
+ MapKit.resolution(5).round(4).should == 4891.9698.round(4)
87
+ MapKit.resolution(6).round(4).should == 2445.9849.round(4)
88
+ MapKit.resolution(7).round(4).should == 1222.9924.round(4)
89
+ MapKit.resolution(8).round(4).should == 611.4962.round(4)
90
+ MapKit.resolution(9).round(4).should == 305.7481.round(4)
91
+ MapKit.resolution(10).round(4).should == 152.8740.round(4)
92
+ MapKit.resolution(11).round(4).should == 76.4370.round(4)
93
+ MapKit.resolution(12).round(4).should == 38.2185.round(4)
94
+ MapKit.resolution(13).round(4).should == 19.1092.round(4)
95
+ MapKit.resolution(14).round(4).should == 9.5546.round(4)
96
+ MapKit.resolution(15).round(4).should == 4.7773.round(4)
97
+ MapKit.resolution(16).round(4).should == 2.3886.round(4)
98
+ MapKit.resolution(17).round(4).should == 1.1943.round(4)
99
+ MapKit.resolution(18).round(4).should == 0.5972.round(4)
100
+ MapKit.resolution(19).round(4).should == 0.2986.round(4)
101
+ MapKit.resolution(20).round(4).should == 0.1493.round(4)
102
+ MapKit.resolution(21).round(4).should == 0.0746.round(4)
103
+ end
104
+
105
+ it "should calculate the map size" do
106
+ MapKit.map_size(0).should == [256, 256]
107
+ MapKit.map_size(10).should == [4 ** 9, 4 ** 9]
108
+ MapKit.map_size(20).should == [4 ** 14, 4 ** 14]
109
+ end
110
+
111
+ it "should calculate the tile xy to pixel xy and vice versa" do
112
+ MapKit.pixel2tile(1024, 1024).should == [4, 4]
113
+ MapKit.pixel2tile(0, 0).should == [0, 0]
114
+ MapKit.tile2pixel(4, 4).should == [1024, 1024]
115
+ MapKit.tile2pixel(0, 0).should == [0, 0]
116
+ end
117
+
118
+ it "should clip correctly as defined by boundings" do
119
+ MapKit.clip(45, 40, 50).should == 45
120
+ MapKit.clip(45, 45, 50).should == 45
121
+ MapKit.clip(45, 50, 55).should == 50
122
+ MapKit.clip(45, 30, 40).should == 40
123
+ MapKit.clip(45, 40, 45).should == 45
124
+ end
125
+
126
+ it "should calculate the shift correctly" do
127
+ lat, lng = MapKit.shift_latlng(47.99997, 8.00002, 20, 20, 14)
128
+ lat.round(5).should == 47.99882
129
+ lng.round(5).should == 8.00173
130
+ end
131
+
132
+ it "should calc pixel to lat/lng and vice versa" do
133
+ px, py = MapKit.latlng2pixel(47.99997, 8.00002, 14)
134
+ px.should == 2_190_359
135
+ py.should == 1_458_001
136
+ lat, lng = MapKit.pixel2latlng(px, py, 14)
137
+ lat.round(5).should == 47.99997
138
+ lng.round(5).should == 8.00002
139
+ end
140
+
141
+ it "should return bounding boxes for tile coordinates" do
142
+ bb = MapKit.bounding_box(0, 0, 0)
143
+ bb.top.round(8).should == MapKit::MAX_LATITUDE
144
+ bb.left.round(8).should == MapKit::MIN_LONGITUDE
145
+ bb.bottom.round(8).should == -84.92832093
146
+ bb.right.round(8).should == 178.59375
147
+
148
+ bb = MapKit.bounding_box(1024, 1024, 14)
149
+ bb.top.round(8).should == 82.67628497
150
+ bb.left.round(8).should == -157.5
151
+ bb.bottom.round(8).should == 82.67348347
152
+ bb.right.round(8).should == -157.47802735
153
+ end
154
+ end
@@ -0,0 +1,24 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ $:.unshift(File.expand_path("../lib", __FILE__))
8
+ require 'mapkit'
9
+
10
+ def travis?
11
+ ENV['TRAVIS'] == 'true'
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = 'random'
24
+ end
metadata CHANGED
@@ -1,101 +1,127 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mapkit
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Vincent Landgraf
8
+ - Paul Trippett
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2010-02-11 00:00:00 +01:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2014-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
16
43
  name: httparty
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
21
46
  - - ">="
22
- - !ruby/object:Gem::Version
47
+ - !ruby/object:Gem::Version
23
48
  version: 0.5.2
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: gd2
27
49
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
31
53
  - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.1.1
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: rake
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
54
+ - !ruby/object:Gem::Version
55
+ version: 0.5.2
56
+ - !ruby/object:Gem::Dependency
57
+ name: rmagick
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
41
60
  - - ">="
42
- - !ruby/object:Gem::Version
43
- version: "0"
44
- version:
45
- - !ruby/object:Gem::Dependency
46
- name: rspec
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
61
+ - !ruby/object:Gem::Version
62
+ version: 2.13.3
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
51
67
  - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
55
- description: |-
56
- MapKit is an set of helpers to assist building tiles for
57
- the google maps web client
58
- email:
59
- - vincent.landgraf@inovex.de
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.3
70
+ description: "\n\t\tMapKit is an set of helpers to assist building tiles for\n\t\tthe
71
+ google maps web client using rmagick\n\t"
72
+ email:
73
+ - vilandgr@googlemail.com
60
74
  executables: []
61
-
62
75
  extensions: []
63
-
64
76
  extra_rdoc_files: []
65
-
66
- files:
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-gemset"
81
+ - ".ruby-version"
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE
85
+ - Rakefile
86
+ - Readme.markdown
87
+ - example/database.sql
88
+ - example/db.rb
89
+ - example/images/empty.png
90
+ - example/images/gas.png
91
+ - example/public/appication.js
92
+ - example/public/images/gradient.jpg
93
+ - example/public/jquery.js
94
+ - example/start.rb
95
+ - example/views/index.erb
67
96
  - lib/google_local.rb
68
97
  - lib/mapkit.rb
69
98
  - lib/tilekit.rb
70
- - LICENSE
71
- - README.markdown
72
- has_rdoc: true
99
+ - mapkit.gemspec
100
+ - spec/mapkit_spec.rb
101
+ - spec/spec_helper.rb
73
102
  homepage: http://github.com/threez/mapkit
74
103
  licenses: []
75
-
104
+ metadata: {}
76
105
  post_install_message:
77
106
  rdoc_options: []
78
-
79
- require_paths:
107
+ require_paths:
80
108
  - lib
81
- required_ruby_version: !ruby/object:Gem::Requirement
82
- requirements:
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
83
111
  - - ">="
84
- - !ruby/object:Gem::Version
85
- version: "0"
86
- version:
87
- required_rubygems_version: !ruby/object:Gem::Requirement
88
- requirements:
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
89
116
  - - ">="
90
- - !ruby/object:Gem::Version
91
- version: 1.3.5
92
- version:
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
93
119
  requirements: []
94
-
95
120
  rubyforge_project:
96
- rubygems_version: 1.3.5
121
+ rubygems_version: 2.2.2
97
122
  signing_key:
98
- specification_version: 3
123
+ specification_version: 4
99
124
  summary: MapKit helps rendering tiles for google maps
100
- test_files: []
101
-
125
+ test_files:
126
+ - spec/mapkit_spec.rb
127
+ - spec/spec_helper.rb