map-kit-wrapper 0.0.1

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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ build
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in map_kit_wrapper.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kasper Weibel Nielsen-Refs
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ MapKitWrapper
2
+ =============
3
+
4
+ This is a MapKit wrapper for RubyMotion. It's purpose is to make make dealing with MapKit less painfull
5
+
6
+ It is still work in progress, but right now there are wrappers for the Map Kit Data Types and the Core Location Data Types. Those will save you a lot of typing.
7
+
8
+ ## Installation
9
+ ```ruby
10
+ gem install map-kit-wrapper
11
+ ```
12
+
13
+ ## Setup
14
+
15
+ Edit the `Rakefile` of your RubyMotion project and add the following require line.
16
+
17
+ ```ruby
18
+ require 'map-kit-wrapper'
19
+ ```
20
+
21
+ ## Example
22
+ ```ruby
23
+
24
+ def loadView
25
+ self.view = UIView.alloc.initWithFrame(tabBarController.view.bounds)
26
+ map = MapView.new
27
+ map.frame = self.view.frame
28
+ map.delegate = self
29
+ region = CoordinateRegion.new([56, 10.6], [3.1, 3.1])
30
+ map.region = region
31
+ # Alternatively use set_region
32
+ # map.set_region(region, :animated => true)
33
+ map.showsUserLocation = true
34
+ self.view.addSubview(map)
35
+ end
36
+ ```
37
+ Check if the users location has been found
38
+ ```ruby
39
+ @map.user_located?
40
+ ```
41
+ Get the users coordinates
42
+ ```ruby
43
+ @map.user_coordinates
44
+ ```
45
+
@@ -0,0 +1,14 @@
1
+ $:.unshift("/Library/RubyMotion/lib")
2
+ require 'motion/project'
3
+ require 'bundler/gem_tasks'
4
+ Bundler.setup
5
+ Bundler.require
6
+ require 'bubble-wrap/test'
7
+
8
+ Motion::Project::App.setup do |app|
9
+ # Use `rake config' to see complete project settings.
10
+ app.name = 'MapKitWrapper'
11
+ app.files = Dir.glob(File.join(app.project_dir, 'motion/**/*.rb'))
12
+ app.files_dependencies 'motion/map_view.rb' => 'motion/zoom_level.rb'
13
+ app.frameworks += ['CoreLocation', 'MapKit']
14
+ end
@@ -0,0 +1 @@
1
+ require 'map_kit_wrapper/version' unless defined?(MapKit::VERSION)
@@ -0,0 +1,3 @@
1
+ module MapKit
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/map_kit_wrapper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kasper Weibel Nielsen-Refs"]
6
+ gem.email = ["weibel@gmail.com"]
7
+ gem.summary = %q{This is a MapKit wrapper for RubyMotion. It's
8
+ purpose is to make make dealing with MapKit less painfull}
9
+ gem.homepage = "https://github.com/weibel/MapKitWrapper"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "map-kit-wrapper"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MapKit::VERSION
17
+
18
+ gem.add_dependency 'bubble-wrap'
19
+ gem.add_development_dependency 'rake'
20
+ end
@@ -0,0 +1,35 @@
1
+ module CoreLocation
2
+ # Wrappers for the Core Location Data Types
3
+ # http://developer.apple.com/library/mac/#documentation/CoreLocation/Reference/CoreLocationDataTypesRef/Reference/reference.html
4
+ module DataTypes
5
+
6
+ # Ruby wrapper for CLLocationCoordinate2D
7
+ class LocationCoordinate
8
+ attr_reader :sdk
9
+
10
+ # LocationCoordinate.new(1,2)
11
+ # LocationCoordinate.new([1,2])
12
+ # CoordinateSpan.new(CLLocationCoordinate2D)
13
+ def initialize(*args)
14
+ args.flatten!
15
+ if args.first.is_a?(CLLocationCoordinate2D)
16
+ @sdk = args.first
17
+ else
18
+ @sdk = CLLocationCoordinate2DMake(args[0], args[1])
19
+ end
20
+ end
21
+
22
+ def latitude
23
+ @sdk.latitude
24
+ end
25
+
26
+ def longitude
27
+ @sdk.longitude
28
+ end
29
+
30
+ def to_array
31
+ [latitude, longitude]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,162 @@
1
+ module MapKit
2
+ # Wrappers for the Map Kit Data Types
3
+ # http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MapKitDataTypesReference/Reference/reference.html
4
+ module DataTypes
5
+
6
+ # Wrapper for MKCoordinateSpan
7
+ class CoordinateSpan
8
+ attr_reader :sdk
9
+
10
+ # CoordinateSpan.new(1,2)
11
+ # CoordinateSpan.new([1,2])
12
+ # CoordinateSpan.new(MKCoordinateSpan)
13
+ def initialize(*args)
14
+ args.flatten!
15
+ if args.first.is_a?(MKCoordinateSpan)
16
+ @sdk = args.first
17
+ else
18
+ @sdk = MKCoordinateSpanMake(args[0], args[1])
19
+ end
20
+ end
21
+
22
+ def latitude_delta
23
+ @sdk.latitudeDelta
24
+ end
25
+
26
+ def longitude_delta
27
+ @sdk.longitudeDelta
28
+ end
29
+
30
+ def to_array
31
+ [latitude_delta, longitude_delta]
32
+ end
33
+ end
34
+
35
+ # Wrapper for MKCoordinateRegion
36
+ class CoordinateRegion
37
+ include CoreLocation::DataTypes
38
+ attr_reader :sdk
39
+
40
+ # CoordinateRegion.new(CoordinateRegion)
41
+ # CoordinateRegion.new(MKCoordinateRegion)
42
+ # CoordinateRegion.new([56, 10.6], [3.1, 3.1])
43
+ # CoordinateRegion.new(LocationCoordinate, CoordinateSpan)
44
+ # CoordinateRegion.new(CLLocationCoordinate2D, MKCoordinateSpan)
45
+ def initialize(*args)
46
+ if args.size == 1
47
+ if args[0].is_a?(CoordinateRegion)
48
+ center, span = args[0].center.sdk, args[0].span.sdk
49
+ else
50
+ center, span = args[0].center, args[0].span
51
+ end
52
+ else
53
+ center = args[0].is_a?(LocationCoordinate) ? args[0].sdk : args[0]
54
+ span = args[1].is_a?(CoordinateSpan) ? args[1].sdk : args[1]
55
+ end
56
+ @sdk = MKCoordinateRegionMake(center, span)
57
+ end
58
+
59
+ def center
60
+ LocationCoordinate.new(@sdk.center)
61
+ end
62
+
63
+ def span
64
+ CoordinateSpan.new(@sdk.span)
65
+ end
66
+
67
+ def to_hash
68
+ {:center => center.to_array, :span => span.to_array}
69
+ end
70
+ end
71
+
72
+ # Wrapper for MKMapPoint
73
+ class MapPoint
74
+ attr_reader :sdk
75
+
76
+ # MapPoint.new(50,45)
77
+ # MapPoint.new([50,45])
78
+ # MapPoint.new(MKMapPoint)
79
+ def initialize(*args)
80
+ args.flatten!
81
+ if args.first.is_a?(MKMapPoint)
82
+ @sdk = args.first
83
+ else
84
+ @sdk = MKMapPointMake(args[0], args[1])
85
+ end
86
+ end
87
+
88
+ def x
89
+ @sdk.x
90
+ end
91
+
92
+ def y
93
+ @sdk.y
94
+ end
95
+
96
+ def to_array
97
+ [x, y]
98
+ end
99
+ end
100
+
101
+ # Wrapper for MKMapSize
102
+ class MapSize
103
+ attr_reader :sdk
104
+
105
+ # MapSize.new(10,12)
106
+ # MapSize.new([10,12])
107
+ # MapSize.new(MKMapSize)
108
+ def initialize(*args)
109
+ args.flatten!
110
+ if args.first.is_a?(MKMapSize)
111
+ @sdk = args.first
112
+ else
113
+ @sdk = MKMapSizeMake(args[0], args[1])
114
+ end
115
+ end
116
+
117
+ def width
118
+ @sdk.width
119
+ end
120
+
121
+ def height
122
+ @sdk.height
123
+ end
124
+
125
+ def to_array
126
+ [width, height]
127
+ end
128
+ end
129
+
130
+ # Wrapper for MKMapRect
131
+ class MapRect
132
+ attr_reader :sdk
133
+
134
+ # MapRect.new(x, y, width, height)
135
+ # MapRect.new([x, y], [width, height])
136
+ # MapRect.new(MapPoint, MapSize)
137
+ # MapRect.new(MKMapPoint, MKMapSize)
138
+ def initialize(*args)
139
+ args.flatten!
140
+ if args.size == 2
141
+ origin = args[0].is_a?(MapPoint) ? args[0] : MapPoint.new(args[0])
142
+ size = args[1].is_a?(MapSize) ? args[1] : MapSize.new(args[1])
143
+ @sdk = MKMapRectMake(origin.sdk.x, origin.sdk.y, size.sdk.width, size.sdk.height)
144
+ elsif args.size == 4
145
+ @sdk = MKMapRectMake(args[0], args[1], args[2], args[3])
146
+ end
147
+ end
148
+
149
+ def origin
150
+ MapPoint.new(@sdk.origin)
151
+ end
152
+
153
+ def size
154
+ MapSize.new(@sdk.size)
155
+ end
156
+
157
+ def to_hash
158
+ {:origin => origin.to_array, :size => size.to_array}
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,25 @@
1
+ module MapKit
2
+ class MapType
3
+ def self.mkmap_to_rmap(map_type)
4
+ case map_type
5
+ when MKMapTypeStandard
6
+ :standard
7
+ when MKMapTypeSatellite
8
+ :satellite
9
+ when MKMapTypeHybrid
10
+ :hybrid
11
+ end
12
+ end
13
+
14
+ def self.rmap_to_mkmap(map_type)
15
+ case map_type
16
+ when :standard
17
+ MKMapTypeStandard
18
+ when :satellite
19
+ MKMapTypeSatellite
20
+ when :hybrid
21
+ MKMapTypeHybrid
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,69 @@
1
+ module MapKit
2
+ include CoreLocation::DataTypes
3
+ include MapKit::DataTypes
4
+
5
+ # Wrapper for MKMapView
6
+ class MapView < MKMapView
7
+ include CoreLocation::DataTypes
8
+ include MapKit::DataTypes
9
+ include MapKit::ZoomLevel
10
+
11
+ def initialize
12
+ self.alloc.init
13
+ end
14
+
15
+ # zoom methods
16
+
17
+ def zoom_enabled?
18
+ self.isZoomEnabled
19
+ end
20
+
21
+ def zoom_enabled=(enabled)
22
+ self.setZoomEnabled(enabled)
23
+ end
24
+
25
+ # scroll methods
26
+
27
+ def scroll_enabled?
28
+ self.isScrollEnabled
29
+ end
30
+
31
+ def scroll_enabled=(enabled)
32
+ self.setScrollEnabled(enabled)
33
+ end
34
+
35
+ # user location methods
36
+
37
+ def shows_user_location?
38
+ self.showsUserLocation
39
+ end
40
+
41
+ def shows_user_location=(enabled)
42
+ self.showsUserLocation = enabled
43
+ end
44
+
45
+ def user_located?
46
+ self.shows_user_location? && self.userLocation.location ? true : false
47
+ end
48
+
49
+ def user_coordinates
50
+ self.user_located? ? LocationCoordinate.new(self.userLocation.location.coordinate) : nil
51
+ end
52
+
53
+ # region methods
54
+
55
+ def get_region
56
+ CoordinateRegion.new(self.region.center, self.region.span)
57
+ end
58
+
59
+ def region=(*args)
60
+ self.set_region(CoordinateRegion.new(args.first), false)
61
+ end
62
+
63
+ def set_region(coordinate_region, *args)
64
+ opts = {:animated => false}
65
+ opts.merge!(args.first) if args.first
66
+ self.setRegion(coordinate_region.sdk, animated:opts[:animated])
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,9 @@
1
+ class TestSuiteDelegate
2
+ attr_accessor :window
3
+
4
+ def application(application, didFinishLaunchingWithOptions: launchOptions)
5
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
6
+ @window.rootViewController = UIViewController.alloc.init
7
+ true
8
+ end
9
+ end
@@ -0,0 +1,162 @@
1
+ module MapKit
2
+ # Ruby conversion of http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
3
+ module ZoomLevel
4
+ include Math
5
+ MERCATOR_OFFSET = 268435456.0
6
+ MERCATOR_RADIUS = 85445659.44705395
7
+
8
+ module ClassMethods
9
+ include Math
10
+ # Map conversion methods
11
+
12
+ def longitude_to_pixel_space_x(longitude)
13
+ (MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * PI / 180.0).round
14
+ end
15
+
16
+ def latitude_to_pixel_space_y(latitude)
17
+ if latitude == 90.0
18
+ 0
19
+ elsif latitude == -90.0
20
+ MERCATOR_OFFSET * 2
21
+ else
22
+ (MERCATOR_OFFSET - MERCATOR_RADIUS * log((1 + sin(latitude * PI / 180.0)) / (1 - sin(latitude * PI / 180.0))) / 2.0).round
23
+ end
24
+ end
25
+
26
+ def pixel_space_x_to_longitude(pixel_x)
27
+ ((pixel_x.round - MERCATOR_OFFSET) / MERCATOR_RADIUS) * 180.0 / PI
28
+ end
29
+
30
+ def pixel_space_y_to_latitude(pixel_y)
31
+ (PI / 2.0 - 2.0 * atan(exp((pixel_y.round - MERCATOR_OFFSET) / MERCATOR_RADIUS))) * 180.0 / PI
32
+ end
33
+
34
+ def coordinate_span_with_map_view(map_view, center_coordinate, zoom_level)
35
+ # convert center coordiate to pixel space
36
+ center_pixel_x = self.longitude_to_pixel_space_x(center_coordinate.longitude)
37
+ center_pixel_y = self.latitude_to_pixel_space_y(center_coordinate.latitude)
38
+
39
+ # determine the scale value from the zoom level
40
+ zoom_exponent = 20 - zoom_level
41
+ zoom_scale = 2 ** zoom_exponent
42
+
43
+ # scale the map’s size in pixel space
44
+ map_size_in_pixels = map_view.bounds.size
45
+ scaled_map_width = map_size_in_pixels.width * zoom_scale
46
+ scaled_map_height = map_size_in_pixels.height * zoom_scale
47
+
48
+ # figure out the position of the top-left pixel
49
+ top_left_pixel_x = center_pixel_x - (scaled_map_width / 2)
50
+ top_left_pixel_y = center_pixel_y - (scaled_map_height / 2)
51
+
52
+ # find delta between left and right longitudes
53
+ min_lng = self.pixel_space_x_to_longitude(top_left_pixel_x)
54
+ max_lng = self.pixel_space_x_to_longitude(top_left_pixel_x + scaled_map_width)
55
+ longitude_delta = max_lng - min_lng
56
+
57
+ # find delta between top and bottom latitudes
58
+ min_lat = self.pixel_space_y_to_latitude(top_left_pixel_y)
59
+ max_lat = self.pixel_space_y_to_latitude(top_left_pixel_y + scaled_map_height)
60
+ latitude_delta = -1 * (max_lat - min_lat)
61
+
62
+ # create and return the lat/lng span
63
+ MKCoordinateSpanMake(latitude_delta, longitude_delta)
64
+ end
65
+
66
+ # KMapView cannot display tiles that cross the pole
67
+ # This would involve wrapping the map from top to bottom, something that a Mercator projection just cannot do.
68
+ def coordinate_region_with_map_view(map_view, center_coordinate, zoom_level)
69
+
70
+ # clamp lat/long values to appropriate ranges
71
+ center_coordinate.latitude = [[-90.0, center_coordinate.latitude].max, 90.0].min
72
+ center_coordinate.longitude = center_coordinate.longitude % 180.0
73
+
74
+ # convert center coordiate to pixel space
75
+ center_pixel_x = self.longitude_to_pixel_space_x(center_coordinate.longitude)
76
+ center_pixel_y = self.latitude_to_pixel_space_y(center_coordinate.latitude)
77
+
78
+ # determine the scale value from the zoom level
79
+ zoom_exponent = 20 - zoom_level
80
+ zoom_scale = 2 ** zoom_exponent
81
+
82
+ # scale the map’s size in pixel space
83
+ map_size_in_pixels = map_view.bounds.size
84
+ scaled_map_width = map_size_in_pixels.width * zoom_scale
85
+ scaled_map_height = map_size_in_pixels.height * zoom_scale
86
+
87
+ # figure out the position of the left pixel
88
+ top_left_pixel_x = center_pixel_x - (scaled_map_width / 2)
89
+
90
+ # find delta between left and right longitudes
91
+ min_lng = self.pixel_space_x_to_longitude(top_left_pixel_x)
92
+ max_lng = self.pixel_space_x_to_longitude(top_left_pixel_x + scaled_map_width)
93
+ longitude_delta = max_lng - min_lng
94
+
95
+ # if we’re at a pole then calculate the distance from the pole towards the equator
96
+ # as MKMapView doesn’t like drawing boxes over the poles
97
+ top_pixel_y = center_pixel_y - (scaled_map_height / 2)
98
+ bottom_pixel_y = center_pixel_y + (scaled_map_height / 2)
99
+ adjusted_center_point = false
100
+ if top_pixel_y > MERCATOR_OFFSET * 2
101
+ top_pixel_y = center_pixel_y - scaled_map_height
102
+ bottom_pixel_y = MERCATOR_OFFSET * 2
103
+ adjusted_center_point = true
104
+ end
105
+
106
+ # find delta between top and bottom latitudes
107
+ min_lat = self.pixel_space_y_to_latitude(top_pixel_y)
108
+ max_lat = self.pixel_space_y_to_latitude(bottom_pixel_y)
109
+ latitude_delta = -1 * (max_lat - min_lat)
110
+
111
+ # create and return the lat/lng span
112
+ span = MKCoordinateSpanMake(latitude_delta, longitude_delta)
113
+ region = MKCoordinateRegionMake(center_coordinate, span)
114
+ # once again, MKMapView doesn’t like drawing boxes over the poles
115
+ # so adjust the center coordinate to the center of the resulting region
116
+ if adjusted_center_point
117
+ region.center.latitude = self.pixel_space_y_to_latitude((bottom_pixel_y + top_pixel_y) / 2.0)
118
+ end
119
+
120
+ region
121
+ end
122
+ end
123
+
124
+ def self.included(base)
125
+ base.extend(ClassMethods)
126
+ end
127
+
128
+ # Public methods
129
+
130
+ def set_center_coordinates(center_coordinate, zoom_level, animated)
131
+ # clamp large numbers to 28
132
+ zoom_level = [zoom_level, 28].min
133
+
134
+ # use the zoom level to compute the region
135
+ span = self.class.coordinate_span_with_map_view(self, center_coordinate, zoom_level)
136
+ region = MKCoordinateRegionMake(center_coordinate, span)
137
+
138
+ # set the region like normal
139
+ self.setRegion(region, animated: animated)
140
+ end
141
+
142
+ def set_map_lat_lon(latitude, longitude, zoom_level, animated)
143
+ coordinates = CLLocationCoordinate2DMake(latitude, longitude)
144
+ self.set_center_coordinates(coordinates, zoom_level, animated)
145
+ end
146
+
147
+ def zoom_level
148
+ region = self.region
149
+
150
+ center_pixel_x = self.class.longitude_to_pixel_space_x(region.center.longitude)
151
+ top_left_pixel_x = self.class.longitude_to_pixel_space_x(region.center.longitude - region.span.longitudeDelta / 2)
152
+
153
+ scaled_map_width = (center_pixel_x - top_left_pixel_x) * 2
154
+ map_size_in_pixels = self.bounds.size
155
+ zoom_scale = scaled_map_width / map_size_in_pixels.width
156
+ zoom_exponent = log(zoom_scale) / log(2)
157
+ zoom_level = 20 - zoom_exponent
158
+ zoom_level
159
+ end
160
+
161
+ end
162
+ end
@@ -0,0 +1,32 @@
1
+ describe 'LocationCoordinate' do
2
+ before do
3
+ lc_1 = CoreLocation::DataTypes::LocationCoordinate.new(5, 8)
4
+ lc_2 = CoreLocation::DataTypes::LocationCoordinate.new([5, 8])
5
+ lc_3 = CoreLocation::DataTypes::LocationCoordinate.new(CLLocationCoordinate2DMake(5, 8))
6
+ @array = [lc_1, lc_2, lc_3]
7
+ end
8
+
9
+ it 'should return the latitude' do
10
+ @array.each do |lc|
11
+ lc.latitude.should.equal 5
12
+ end
13
+ end
14
+
15
+ it 'should return the longitude' do
16
+ @array.each do |lc|
17
+ lc.longitude.should.equal 8
18
+ end
19
+ end
20
+
21
+ it 'should return an array' do
22
+ @array.each do |lc|
23
+ lc.to_array.should.equal [5, 8]
24
+ end
25
+ end
26
+
27
+ it 'should contain a CLLocationCoordinate2D' do
28
+ @array.each do |lc|
29
+ lc.sdk.is_a?(CLLocationCoordinate2D).should.equal true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,182 @@
1
+ describe 'MapKitDataTypes' do
2
+ describe 'CoordinateSpan' do
3
+ before do
4
+ o_1 = MapKit::DataTypes::CoordinateSpan.new(5, 8)
5
+ o_2 = MapKit::DataTypes::CoordinateSpan.new([5, 8])
6
+ o_3 = MapKit::DataTypes::CoordinateSpan.new(MKCoordinateSpanMake(5, 8))
7
+ @array = [o_1, o_2, o_3]
8
+ end
9
+
10
+ it 'should return the latitude delta' do
11
+ @array.each do |o|
12
+ o.latitude_delta.should.equal 5
13
+ end
14
+ end
15
+
16
+ it 'should return the longitude delta' do
17
+ @array.each do |o|
18
+ o.longitude_delta.should.equal 8
19
+ end
20
+ end
21
+
22
+ it 'should return an array' do
23
+ @array.each do |o|
24
+ o.to_array.should.equal [5, 8]
25
+ end
26
+ end
27
+
28
+ it 'should contain a MKCoordinateSpan' do
29
+ @array.each do |o|
30
+ o.sdk.is_a?(MKCoordinateSpan).should.equal true
31
+ end
32
+ end
33
+ end
34
+
35
+ describe 'CoordinateRegion' do
36
+ before do
37
+ lc = CoreLocation::DataTypes::LocationCoordinate.new(5, 8)
38
+ cs = MapKit::DataTypes::CoordinateSpan.new(6, 9)
39
+ mkcr = MKCoordinateRegionMake(CLLocationCoordinate2DMake(5, 8), MKCoordinateSpanMake(6, 9))
40
+ o_1 = MapKit::DataTypes::CoordinateRegion.new([5, 8], [6, 9])
41
+ o_2 = MapKit::DataTypes::CoordinateRegion.new(lc, cs)
42
+ o_3 = MapKit::DataTypes::CoordinateRegion.new(CLLocationCoordinate2DMake(5, 8), MKCoordinateSpanMake(6, 9))
43
+ o_4 = MapKit::DataTypes::CoordinateRegion.new(mkcr)
44
+ o_5 = MapKit::DataTypes::CoordinateRegion.new(o_1)
45
+ @array = [o_1, o_2, o_3, o_4, o_5]
46
+ end
47
+
48
+ it 'should return the center' do
49
+ @array.each do |o|
50
+ o.center.is_a?(CoreLocation::DataTypes::LocationCoordinate).should.equal true
51
+ o.center.latitude.should.equal 5
52
+ o.center.longitude.should.equal 8
53
+ end
54
+ end
55
+
56
+ it 'should return the span' do
57
+ @array.each do |o|
58
+ o.span.is_a?(MapKit::DataTypes::CoordinateSpan).should.equal true
59
+ o.span.latitude_delta.should.equal 6
60
+ o.span.longitude_delta.should.equal 9
61
+ end
62
+ end
63
+
64
+ it 'should return a hash' do
65
+ @array.each do |o|
66
+ o.to_hash.should.equal({:center => [5, 8], :span => [6, 9]})
67
+ end
68
+ end
69
+
70
+ it 'should contain a MKCoordinateRegion' do
71
+ @array.each do |o|
72
+ o.sdk.is_a?(MKCoordinateRegion).should.equal true
73
+ end
74
+ end
75
+ end
76
+
77
+ describe 'MapPoint' do
78
+ before do
79
+ o_1 = MapKit::DataTypes::MapPoint.new(5, 8)
80
+ o_2 = MapKit::DataTypes::MapPoint.new([5, 8])
81
+ o_3 = MapKit::DataTypes::MapPoint.new(MKMapPointMake(5, 8))
82
+ @array = [o_1, o_2, o_3]
83
+ end
84
+
85
+ it 'should return the x' do
86
+ @array.each do |o|
87
+ o.x.should.equal 5
88
+ end
89
+ end
90
+
91
+ it 'should return the y' do
92
+ @array.each do |o|
93
+ o.y.should.equal 8
94
+ end
95
+ end
96
+
97
+ it 'should return an array' do
98
+ @array.each do |o|
99
+ o.to_array.should.equal [5, 8]
100
+ end
101
+ end
102
+
103
+ it 'should contain a MKMapPoint' do
104
+ @array.each do |o|
105
+ o.sdk.is_a?(MKMapPoint).should.equal true
106
+ end
107
+ end
108
+ end
109
+
110
+ describe 'MapSize' do
111
+ before do
112
+ o_1 = MapKit::DataTypes::MapSize.new(5, 8)
113
+ o_2 = MapKit::DataTypes::MapSize.new([5, 8])
114
+ o_3 = MapKit::DataTypes::MapSize.new(MKMapSizeMake(5, 8))
115
+ @array = [o_1, o_2, o_3]
116
+ end
117
+
118
+ it 'should return the width' do
119
+ @array.each do |o|
120
+ o.width.should.equal 5
121
+ end
122
+ end
123
+
124
+ it 'should return the height' do
125
+ @array.each do |o|
126
+ o.height.should.equal 8
127
+ end
128
+ end
129
+
130
+ it 'should return an array' do
131
+ @array.each do |o|
132
+ o.to_array.should.equal [5, 8]
133
+ end
134
+ end
135
+
136
+ it 'should contain a MKMapSize' do
137
+ @array.each do |o|
138
+ o.sdk.is_a?(MKMapSize).should.equal true
139
+ end
140
+ end
141
+ end
142
+
143
+ describe 'MapRect' do
144
+ before do
145
+ mp = MapKit::DataTypes::MapPoint.new(5, 8)
146
+ ms = MapKit::DataTypes::MapSize.new(6, 9)
147
+ o_1 = MapKit::DataTypes::MapRect.new(5, 8, 6, 9)
148
+ o_2 = MapKit::DataTypes::MapRect.new([5, 8], [6, 9])
149
+ o_3 = MapKit::DataTypes::MapRect.new(mp, ms)
150
+ o_4 = MapKit::DataTypes::MapRect.new(MKMapPointMake(5, 8), MKMapSizeMake(6, 9))
151
+ @array = [o_1, o_2, o_3, o_4]
152
+ end
153
+
154
+ it 'should return the origin' do
155
+ @array.each do |o|
156
+ o.origin.is_a?(MapKit::DataTypes::MapPoint).should.equal true
157
+ o.origin.x.should.equal 5
158
+ o.origin.y.should.equal 8
159
+ end
160
+ end
161
+
162
+ it 'should return the size' do
163
+ @array.each do |o|
164
+ o.size.is_a?(MapKit::DataTypes::MapSize).should.equal true
165
+ o.size.width.should.equal 6
166
+ o.size.height.should.equal 9
167
+ end
168
+ end
169
+
170
+ it 'should return a hash' do
171
+ @array.each do |o|
172
+ o.to_hash.should.equal({:origin => [5, 8], :size => [6, 9]})
173
+ end
174
+ end
175
+
176
+ it 'should contain a MKMapRect' do
177
+ @array.each do |o|
178
+ o.sdk.is_a?(MKMapRect).should.equal true
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,80 @@
1
+ describe 'MapView' do
2
+ before do
3
+ @map = MapKit::MapView.new
4
+ @map.delegate = self
5
+ @map.frame = UIScreen.mainScreen.bounds
6
+ @map.region = MapKit::CoordinateRegion.new([56, 10.6], [3.1, 3.1])
7
+ @map.zoom_enabled = false
8
+ @map.scroll_enabled = false
9
+ end
10
+
11
+ it 'should initialize' do
12
+ @map.should.satisfy { |object| object.is_a? MapKit::MapView }
13
+ end
14
+
15
+ # zoom
16
+
17
+ it 'should show zoom_enabled?' do
18
+ @map.zoom_enabled?.should.equal false
19
+ end
20
+
21
+ it 'should set zoom_enabled' do
22
+ @map.zoom_enabled = true
23
+ @map.zoom_enabled?.should.equal true
24
+ end
25
+
26
+ # scroll
27
+
28
+ it 'should show scroll_enabled?' do
29
+ @map.scroll_enabled?.should.equal false
30
+ end
31
+
32
+ it 'should show zoom_enabled' do
33
+ @map.scroll_enabled = true
34
+ @map.scroll_enabled?.should.equal true
35
+ end
36
+
37
+ # user location
38
+
39
+ it 'should show shows_user_location?' do
40
+ @map.shows_user_location?.should.equal false
41
+ end
42
+
43
+ it 'should set shows_user_location' do
44
+ @map.shows_user_location = true
45
+ @map.shows_user_location?.should == true
46
+ end
47
+
48
+ it 'should show user_located?' do
49
+ @map.user_located?.should.equal false
50
+ @map.shows_user_location = true
51
+ #wait 10 do
52
+ # @map.user_located?.should.equal true
53
+ #end
54
+ end
55
+
56
+ it 'should show user_coordinates' do
57
+ @map.user_coordinates.should.equal nil
58
+ @map.shows_user_location = true
59
+ #wait 10 do
60
+ # @map.user_coordinates.latitude.should.equal 56
61
+ #end
62
+ end
63
+
64
+ # region
65
+
66
+ it 'should show get_region' do
67
+ @map.get_region.should.satisfy { |object| object.is_a? MapKit::DataTypes::CoordinateRegion }
68
+ end
69
+
70
+ it 'should set region=' do
71
+ @map.region = MapKit::CoordinateRegion.new([56, 10.6], [3.1, 3.1])
72
+ @map.get_region.should.satisfy { |object| object.is_a? MapKit::DataTypes::CoordinateRegion }
73
+ end
74
+
75
+ it 'should set_region(coordinate_region, *args)' do
76
+ @map.set_region(MapKit::CoordinateRegion.new([56, 10.6], [3.1, 3.1]), false)
77
+ @map.get_region.should.satisfy { |object| object.is_a? MapKit::DataTypes::CoordinateRegion }
78
+ end
79
+
80
+ end
@@ -0,0 +1,71 @@
1
+ describe 'ZoomLevel' do
2
+ before do
3
+ @map = MapKit::MapView.new
4
+ @map.delegate = self
5
+ @map.frame = UIScreen.mainScreen.bounds
6
+ @map.region = MapKit::CoordinateRegion.new([56, 10.6], [3.1, 3.1])
7
+ end
8
+
9
+ it 'should return longitude_to_pixel_space_x' do
10
+ MapKit::MapView.longitude_to_pixel_space_x(30).should.equal 313174656
11
+ end
12
+
13
+ it 'should return latitude_to_pixel_space_y' do
14
+ MapKit::MapView.latitude_to_pixel_space_y(90).should.equal 0
15
+ MapKit::MapView.latitude_to_pixel_space_y(-90).should.equal 536870912
16
+ MapKit::MapView.latitude_to_pixel_space_y(0).should.equal 268435456
17
+ end
18
+
19
+ it 'should return pixel_space_x_to_longitude' do
20
+ MapKit::MapView.pixel_space_x_to_longitude(313174656).should.equal 29.999984741210 # 30
21
+ end
22
+
23
+ it 'should return pixel_space_y_to_latitude' do
24
+ MapKit::MapView.pixel_space_y_to_latitude(0).should.equal 85.0511169433594 # 90
25
+ MapKit::MapView.pixel_space_y_to_latitude(536870912).should.equal -85.0511169433594 # -90
26
+ MapKit::MapView.pixel_space_y_to_latitude(268435456).should.equal 0
27
+ end
28
+
29
+ it 'should return coordinate_span_with_map_view' do
30
+ span = MapKit::MapView.coordinate_span_with_map_view(@map, CLLocationCoordinate2DMake(56, 10), 2)
31
+ span.latitudeDelta.should.equal 48.452224731445
32
+ span.longitudeDelta.should.equal 56.25
33
+ end
34
+
35
+ it 'should return set_center_coordinates' do
36
+ @map.set_center_coordinates(CLLocationCoordinate2DMake(56, 10), 2, false)
37
+ center = CoreLocation::DataTypes::LocationCoordinate.new(@map.region.center)
38
+ span = MapKit::DataTypes::CoordinateSpan.new(@map.region.span)
39
+ span.latitude_delta.should.equal 48.4812927246094
40
+ span.longitude_delta.should.equal 56.25
41
+ center.latitude.should.equal 55.9737854003906
42
+ center.longitude.should.equal 10.01953125
43
+ end
44
+
45
+ it 'should return set_map_lat_lon' do
46
+ @map.set_map_lat_lon(56, 10, 2, false)
47
+ center = CoreLocation::DataTypes::LocationCoordinate.new(@map.region.center)
48
+ span = MapKit::DataTypes::CoordinateSpan.new(@map.region.span)
49
+ span.latitude_delta.should.equal 48.4812927246094
50
+ span.longitude_delta.should.equal 56.25
51
+ center.latitude.should.equal 55.9737854003906
52
+ center.longitude.should.equal 10.01953125
53
+ end
54
+
55
+ it 'should return coordinate_region_with_map_view' do
56
+ view = MKMapView.alloc.init
57
+ view.frame = @map.frame
58
+ center = CLLocationCoordinate2DMake(56, 10)
59
+ region = MapKit::MapView.coordinate_region_with_map_view(view, center, 2)
60
+ center = CoreLocation::DataTypes::LocationCoordinate.new(region.center)
61
+ span = MapKit::DataTypes::CoordinateSpan.new(region.span)
62
+ span.latitude_delta.should.equal 48.4522247314453
63
+ span.longitude_delta.should.equal 56.25
64
+ center.latitude.should.equal 56.0
65
+ center.longitude.should.equal 10.0
66
+ end
67
+
68
+ it 'should have a zoom_level' do
69
+ @map.zoom_level.should.equal 5.00000381469727
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: map-kit-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Kasper Weibel Nielsen-Refs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bubble-wrap
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description:
49
+ email:
50
+ - weibel@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - lib/map_kit_wrapper.rb
64
+ - lib/map_kit_wrapper/version.rb
65
+ - map_kit_wrapper.gemspec
66
+ - motion/core_location_data_types.rb
67
+ - motion/map_kit_data_types.rb
68
+ - motion/map_type.rb
69
+ - motion/map_view.rb
70
+ - motion/test_suite_delegate.rb
71
+ - motion/zoom_level.rb
72
+ - spec/core_location_data_types_spec.rb
73
+ - spec/map_kit_data_types_spec.rb
74
+ - spec/map_view_spec.rb
75
+ - spec/zoom_level_spec.rb
76
+ homepage: https://github.com/weibel/MapKitWrapper
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.24
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: This is a MapKit wrapper for RubyMotion. It's purpose is to make make dealing with MapKit less painfull
109
+ test_files:
110
+ - spec/core_location_data_types_spec.rb
111
+ - spec/map_kit_data_types_spec.rb
112
+ - spec/map_view_spec.rb
113
+ - spec/zoom_level_spec.rb