map-kit-wrapper 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,11 +29,8 @@ class FooViewController < UIViewController
29
29
  map = MapView.new
30
30
  map.frame = self.view.frame
31
31
  map.delegate = self
32
- region = CoordinateRegion.new([56, 10.6], [3.1, 3.1])
33
- map.region = region
34
- # Alternatively use set_region
35
- # map.set_region(region, :animated => true)
36
- map.showsUserLocation = true
32
+ map.region = CoordinateRegion.new([56, 10.6], [3.1, 3.1])
33
+ map.shows_user_location = true
37
34
  view.addSubview(map)
38
35
  end
39
36
 
@@ -150,7 +147,7 @@ Methods on `LocationCoordinate`
150
147
  => [10, 15]
151
148
  >> lc.to_h
152
149
  => {:latitude => 10, :longitude => 15}
153
- >> lc.sdk
150
+ >> lc.api
154
151
  => CLLocationCoordinate2D
155
152
  ```
156
153
 
@@ -187,7 +184,7 @@ Methods on `CoordinateSpan`
187
184
  => [1, 2]
188
185
  >> cs.to_h
189
186
  => {:latitude_delta => 1, :longitude_delta => 2}
190
- >> cs.sdk
187
+ >> cs.api
191
188
  => MKCoordinateSpan
192
189
  ```
193
190
 
@@ -215,7 +212,7 @@ Methods on `CoordinateRegion`
215
212
  => CoordinateSpan([3.1, 5.1])
216
213
  >> cs.to_h
217
214
  => {:center => {:latitude => 56, :longitude => 10.6}, :span => {:latitude_delta => 3.1, :longitude_delta => 5.1}}
218
- >> cs.sdk
215
+ >> cs.api
219
216
  => MKCoordinateRegion
220
217
  ```
221
218
 
@@ -244,7 +241,7 @@ Methods on `MapPoint`
244
241
  => [50, 45]
245
242
  >> mp.to_h
246
243
  => {:x => 50, :y => 45}
247
- >> mp.sdk
244
+ >> mp.api
248
245
  => MKMapPoint
249
246
  ```
250
247
 
@@ -273,7 +270,7 @@ Methods on `MapSize`
273
270
  => [50, 45]
274
271
  >> ms.to_h
275
272
  => {:width => 50, :height => 45}
276
- >> ms.sdk
273
+ >> ms.api
277
274
  => MKMapSize
278
275
  ```
279
276
 
@@ -302,7 +299,7 @@ Methods on `MapRect`
302
299
  => MapSize([10, 12])
303
300
  >> mr.to_h
304
301
  => {:origin => {:x => 2, :y => 3}, :size => {:width => 10, :height => 12}}
305
- >> mr.sdk
302
+ >> mr.api
306
303
  => MKMapRect
307
304
  ```
308
305
 
@@ -1,19 +1,34 @@
1
+ ##
2
+ # Wrappers for Core Location
3
+ #
1
4
  module CoreLocation
5
+
2
6
  ##
3
7
  # Wrappers for the Core Location Data Types
4
8
  # http://developer.apple.com/library/mac/#documentation/CoreLocation/Reference/CoreLocationDataTypesRef/Reference/reference.html
5
9
  module DataTypes
10
+
6
11
  ##
7
12
  # Ruby wrapper for CLLocationCoordinate2D
8
13
  class LocationCoordinate
14
+
15
+ ##
16
+ # Attribute reader
17
+ #
9
18
  attr_reader :latitude, :longitude
10
19
 
11
20
  ##
12
- # LocationCoordinate.new(1,2)
13
- # LocationCoordinate.new([1,2])
14
- # LocationCoordinate.new({:latitude => 1, :longitude => 2})
15
- # LocationCoordinate.new(LocationCoordinate)
16
- # LocationCoordinate.new(CLLocationCoordinate2D)
21
+ # Initializer for LocationCoordinate
22
+ #
23
+ # * *Args* :
24
+ # The initializer takes a variety of arguments
25
+ #
26
+ # LocationCoordinate.new(1,2)
27
+ # LocationCoordinate.new([1,2])
28
+ # LocationCoordinate.new({:latitude => 1, :longitude => 2})
29
+ # LocationCoordinate.new(LocationCoordinate)
30
+ # LocationCoordinate.new(CLLocationCoordinate2D)
31
+ #
17
32
  def initialize(*args)
18
33
  args.flatten!
19
34
  self.latitude, self.longitude =
@@ -31,26 +46,58 @@ module CoreLocation
31
46
  end
32
47
  end
33
48
 
34
- def sdk
49
+ ##
50
+ # Returns the wrapped iOS CLLocationCoordinate2D object
51
+ def api
35
52
  CLLocationCoordinate2DMake(@latitude, @longitude)
36
53
  end
37
54
 
55
+ ##
56
+ # Setter for latitude
57
+ #
58
+ # * *Args* :
59
+ # - +latitude+ -> Int or Float
60
+ #
38
61
  def latitude=(latitude)
39
62
  @latitude = latitude.to_f
40
63
  end
41
64
 
65
+ ##
66
+ # Setter for longitude
67
+ #
68
+ # * *Args* :
69
+ # - +longitude+ -> Int or Float
70
+ #
42
71
  def longitude=(longitude)
43
72
  @longitude = longitude.to_f
44
73
  end
45
74
 
75
+ ##
76
+ # Get self as an Array
77
+ #
78
+ # * *Returns* :
79
+ # - <tt>[latitude, longitude]</tt>
80
+ #
46
81
  def to_a
47
82
  [@latitude, @longitude]
48
83
  end
49
84
 
85
+ ##
86
+ # Get self as a Hash
87
+ #
88
+ # * *Returns* :
89
+ # - <tt>{:latitude => latitude, :longitude => longitude}</tt>
90
+ #
50
91
  def to_h
51
92
  {:latitude => @latitude, :longitude => @longitude}
52
93
  end
53
94
 
95
+ ##
96
+ # Get self as a String
97
+ #
98
+ # * *Returns* :
99
+ # - <tt>"{:latitude => latitude, :longitude => longitude}"</tt>
100
+ #
54
101
  def to_s
55
102
  to_h.to_s
56
103
  end
@@ -1,20 +1,35 @@
1
1
  #= require core_location_data_types
2
2
 
3
+ ##
4
+ # Wrappers for MapKit
5
+ #
3
6
  module MapKit
7
+
4
8
  ##
5
9
  # Wrappers for the Map Kit Data Types
6
10
  # http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MapKitDataTypesReference/Reference/reference.html
7
11
  module DataTypes
12
+
8
13
  ##
9
14
  # Wrapper for MKCoordinateSpan
10
15
  class CoordinateSpan
16
+
17
+ ##
18
+ # Attribute reader
19
+ #
11
20
  attr_reader :latitude_delta, :longitude_delta
21
+
12
22
  ##
13
- # CoordinateSpan.new(1,2)
14
- # CoordinateSpan.new([1,2])
15
- # CoordinateSpan.new({:latitude_delta => 1, :longitude_delta => 2})
16
- # CoordinateSpan.new(CoordinateSpan)
17
- # CoordinateSpan.new(MKCoordinateSpan)
23
+ # Initializer for CoordinateSpan
24
+ #
25
+ # * *Args* :
26
+ # The initializer takes a variety of arguments
27
+ #
28
+ # CoordinateSpan.new(1,2)
29
+ # CoordinateSpan.new([1,2])
30
+ # CoordinateSpan.new({:latitude_delta => 1, :longitude_delta => 2})
31
+ # CoordinateSpan.new(CoordinateSpan)
32
+ # CoordinateSpan.new(MKCoordinateSpan)
18
33
  def initialize(*args)
19
34
  args.flatten!
20
35
  self.latitude_delta, self.longitude_delta =
@@ -34,42 +49,91 @@ module MapKit
34
49
  end
35
50
  end
36
51
 
37
- def sdk
52
+ ##
53
+ # Returns the wrapped iOS MKCoordinateSpan object
54
+ #
55
+ # * *Returns* :
56
+ # - A MKCoordinateSpan representation of self
57
+ #
58
+ def api
38
59
  MKCoordinateSpanMake(@latitude_delta, @longitude_delta)
39
60
  end
40
61
 
62
+ ##
63
+ # Setter for latitude_delta
64
+ #
65
+ # * *Args* :
66
+ # - +delta+ -> Int or Float
67
+ #
41
68
  def latitude_delta=(delta)
42
69
  @latitude_delta = delta.to_f
43
70
  end
44
71
 
72
+ ##
73
+ # Setter for longitude_delta
74
+ #
75
+ # * *Args* :
76
+ # - +delta+ -> Int or Float
77
+ #
45
78
  def longitude_delta=(delta)
46
79
  @longitude_delta = delta.to_f
47
80
  end
48
81
 
82
+ ##
83
+ # Get self as an Array
84
+ #
85
+ # * *Returns* :
86
+ # - <tt>[latitude_delta, longitude_delta]</tt>
87
+ #
49
88
  def to_a
50
89
  [@latitude_delta, @longitude_delta]
51
90
  end
52
91
 
92
+ ##
93
+ # Get self as a Hash
94
+ #
95
+ # * *Returns* :
96
+ # - <tt>{:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}</tt>
97
+ #
53
98
  def to_h
54
99
  {:latitude_delta => @latitude_delta, :longitude_delta => @longitude_delta}
55
100
  end
56
101
 
102
+ ##
103
+ # Get self as a String
104
+ #
105
+ # * *Returns* :
106
+ # - <tt>"{:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}"</tt>
107
+ #
57
108
  def to_s
58
109
  to_h.to_s
59
110
  end
60
111
  end
112
+
61
113
  ##
62
114
  # Wrapper for MKCoordinateRegion
63
115
  class CoordinateRegion
64
116
  include CoreLocation::DataTypes
117
+
118
+ ##
119
+ # Attribute reader
120
+ #
65
121
  attr_reader :center, :span
122
+
66
123
  ##
67
- # CoordinateRegion.new(CoordinateRegion)
68
- # CoordinateRegion.new(MKCoordinateRegion)
69
- # CoordinateRegion.new([56, 10.6], [3.1, 3.1])
70
- # CoordinateRegion.new({:center => {:latitude => 56, :longitude => 10.6}, :span => {:latitude_delta => 3.1, :longitude_delta => 3.1}}
71
- # CoordinateRegion.new(LocationCoordinate, CoordinateSpan)
72
- # CoordinateRegion.new(CLLocationCoordinate2D, MKCoordinateSpan)
124
+ # Initializer for CoordinateRegion
125
+ #
126
+ # * *Args* :
127
+ # The initializer takes a variety of arguments
128
+ #
129
+ # CoordinateRegion.new(CoordinateRegion)
130
+ # CoordinateRegion.new(MKCoordinateRegion)
131
+ # CoordinateRegion.new([56, 10.6], [3.1, 3.1])
132
+ # CoordinateRegion.new({:center => {:latitude => 56, :longitude => 10.6},
133
+ # :span => {:latitude_delta => 3.1, :longitude_delta => 3.1}}
134
+ # CoordinateRegion.new(LocationCoordinate, CoordinateSpan)
135
+ # CoordinateRegion.new(CLLocationCoordinate2D, MKCoordinateSpan)
136
+ #
73
137
  def initialize(*args)
74
138
  self.center, self.span =
75
139
  case args.size
@@ -86,35 +150,76 @@ module MapKit
86
150
  end
87
151
  end
88
152
 
89
- def sdk
90
- MKCoordinateRegionMake(@center.sdk, @span.sdk)
153
+ ##
154
+ # Returns the wrapped iOS MKCoordinateRegion object
155
+ #
156
+ # * *Returns* :
157
+ # - A MKCoordinateRegion representation of self
158
+ #
159
+ def api
160
+ MKCoordinateRegionMake(@center.api, @span.api)
91
161
  end
92
162
 
163
+ ##
164
+ # Assigns a CoreLocation::DataTypes::LocationCoordinate to center.
165
+ #
166
+ # * *Args* :
167
+ # - +center+ -> accepts a variety of argument types. See docs for the CoreLocation::DataTypes::LocationCoordinate initializer
168
+ #
93
169
  def center=(center)
94
170
  @center = LocationCoordinate.new(center)
95
171
  end
96
172
 
173
+ ##
174
+ # Assigns a MapKit::DataTypes::CoordinateSpan to span
175
+ #
176
+ # * *Args* :
177
+ # - +span+ -> accepts a variety of argument types. See docs for the MapKit::DataTypes::CoordinateSpan initializer
178
+ #
97
179
  def span=(span)
98
180
  @span = CoordinateSpan.new(span)
99
181
  end
100
182
 
183
+ ##
184
+ # Get self as a Hash
185
+ #
186
+ # * *Returns* :
187
+ # - <tt>{:center => {:latitude => latitude, :longitude => longitude}, :span => {:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}}</tt>
188
+ #
101
189
  def to_h
102
190
  {:center => @center.to_h, :span => @span.to_h}
103
191
  end
104
192
 
193
+ ##
194
+ # Get self as a String
195
+ #
196
+ # * *Returns* :
197
+ # - <tt>"{:center => {:latitude => latitude, :longitude => longitude}, :span => {:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}}"</tt>
198
+ #
105
199
  def to_s
106
200
  to_h.to_s
107
201
  end
108
202
  end
203
+
109
204
  ##
110
205
  # Wrapper for MKMapPoint
111
206
  class MapPoint
207
+
208
+ ##
209
+ # Attribute reader
210
+ #
112
211
  attr_reader :x, :y
212
+
113
213
  ##
114
- # MapPoint.new(50,45)
115
- # MapPoint.new([50,45])
116
- # MapPoint.new({:x => 50, :y => 45})
117
- # MapPoint.new(MKMapPoint)
214
+ # Initializer for MapPoint
215
+ #
216
+ # * *Args* :
217
+ # The initializer takes a variety of arguments
218
+ #
219
+ # MapPoint.new(50,45)
220
+ # MapPoint.new([50,45])
221
+ # MapPoint.new({:x => 50, :y => 45})
222
+ # MapPoint.new(MKMapPoint)
118
223
  def initialize(*args)
119
224
  args.flatten!
120
225
  self.x, self.y =
@@ -132,40 +237,88 @@ module MapKit
132
237
  end
133
238
  end
134
239
 
135
- def sdk
240
+ ##
241
+ # Returns the wrapped iOS MKMapPoint object
242
+ #
243
+ # * *Returns* :
244
+ # - A MKMapPoint representation of self
245
+ #
246
+ def api
136
247
  MKMapPointMake(@x, @y)
137
248
  end
138
249
 
250
+ ##
251
+ # Setter for x
252
+ #
253
+ # * *Args* :
254
+ # - +x+ -> Int or Float
255
+ #
139
256
  def x=(x)
140
257
  @x = x.to_f
141
258
  end
142
259
 
260
+ ##
261
+ # Setter for y
262
+ #
263
+ # * *Args* :
264
+ # - +y+ -> Int or Float
265
+ #
143
266
  def y=(y)
144
267
  @y = y.to_f
145
268
  end
146
269
 
270
+ ##
271
+ # Get self as an Array
272
+ #
273
+ # * *Returns* :
274
+ # - <tt>[x, y]</tt>
275
+ #
147
276
  def to_a
148
277
  [@x, @y]
149
278
  end
150
279
 
280
+ ##
281
+ # Get self as a Hash
282
+ #
283
+ # * *Returns* :
284
+ # - <tt>{:x => x, :y => y}</tt>
285
+ #
151
286
  def to_h
152
287
  {:x => @x, :y => @y}
153
288
  end
154
289
 
290
+ ##
291
+ # Get self as a String
292
+ #
293
+ # * *Returns* :
294
+ # - <tt>"{:x => x, :y => y}"</tt>
295
+ #
155
296
  def to_s
156
297
  to_h.to_s
157
298
  end
158
299
  end
300
+
159
301
  ##
160
302
  # Wrapper for MKMapSize
161
303
  class MapSize
304
+
305
+ ##
306
+ # Attribute reader
307
+ #
162
308
  attr_reader :width, :height
309
+
163
310
  ##
164
- # MapSize.new(10,12)
165
- # MapSize.new([10,12])
166
- # MapSize.new({:width => 10, :height => 12})
167
- # MapSize.new(MKMapSize)
168
- # MapSize.new(MapSize)
311
+ # Initializer for MapSize
312
+ #
313
+ # * *Args* :
314
+ # The initializer takes a variety of arguments
315
+ #
316
+ # MapSize.new(10,12)
317
+ # MapSize.new([10,12])
318
+ # MapSize.new({:width => 10, :height => 12})
319
+ # MapSize.new(MKMapSize)
320
+ # MapSize.new(MapSize)
321
+ #
169
322
  def initialize(*args)
170
323
  args.flatten!
171
324
  self.width, self.height =
@@ -183,42 +336,90 @@ module MapKit
183
336
  end
184
337
  end
185
338
 
186
- def sdk
339
+ ##
340
+ # Returns the wrapped iOS MKMapSize object
341
+ #
342
+ # * *Returns* :
343
+ # - A MKMapSize representation of self
344
+ #
345
+ def api
187
346
  MKMapSizeMake(@width, @height)
188
347
  end
189
348
 
349
+ ##
350
+ # Setter for width
351
+ #
352
+ # * *Args* :
353
+ # - +width+ -> Int or Float
354
+ #
190
355
  def width=(width)
191
356
  @width = width.to_f
192
357
  end
193
358
 
359
+ ##
360
+ # Setter for height
361
+ #
362
+ # * *Args* :
363
+ # - +height+ -> Int or Float
364
+ #
194
365
  def height=(height)
195
366
  @height = height.to_f
196
367
  end
197
368
 
369
+ ##
370
+ # Get self as an Array
371
+ #
372
+ # * *Returns* :
373
+ # - <tt>[@width, @height]</tt>
374
+ #
198
375
  def to_a
199
376
  [@width, @height]
200
377
  end
201
378
 
379
+ ##
380
+ # Get self as a Hash
381
+ #
382
+ # * *Returns* :
383
+ # - <tt>{:width => width, :height => height}</tt>
384
+ #
202
385
  def to_h
203
386
  {:width => @width, :height => @height}
204
387
  end
205
388
 
389
+ ##
390
+ # Get self as a String
391
+ #
392
+ # * *Returns* :
393
+ # - <tt>"{:width => width, :height => height}"</tt>
394
+ #
206
395
  def to_s
207
396
  to_h.to_s
208
397
  end
209
398
  end
399
+
210
400
  ##
211
401
  # Wrapper for MKMapRect
212
402
  class MapRect
403
+
404
+ ##
405
+ # Attribute reader
406
+ #
213
407
  attr_reader :origin, :size
408
+
214
409
  ##
215
- # MapRect.new(x, y, width, height)
216
- # MapRect.new([x, y], [width, height])
217
- # MapRect.new({:origin => {:x => 5.0, :y => 8.0}, :size => {:width => 6.0, :height => 9.0}})
218
- # MapRect.new(MapPoint, MapSize)
219
- # MapRect.new(MKMapPoint, MKMapSize)
220
- # MapRect.new(MapRect)
221
- # MapRect.new(MKMapRect)
410
+ # Initializer for MapRect
411
+ #
412
+ # * *Args* :
413
+ # The initializer takes a variety of arguments
414
+ #
415
+ # MapRect.new(x, y, width, height)
416
+ # MapRect.new([x, y], [width, height])
417
+ # MapRect.new({:origin => {:x => 5.0, :y => 8.0}, :size => {:width => 6.0, :height => 9.0}})
418
+ # MapRect.new(MapPoint, MapSize)
419
+ # MapRect.new(MKMapPoint, MKMapSize)
420
+ # MapRect.new(MapRect)
421
+ # MapRect.new(MKMapRect)
422
+ #
222
423
  def initialize(*args)
223
424
  self.origin, self.size =
224
425
  case args.size
@@ -237,22 +438,52 @@ module MapKit
237
438
  end
238
439
  end
239
440
 
240
- def sdk
441
+ ##
442
+ # Returns the wrapped iOS MKMapRect object
443
+ #
444
+ # * *Returns* :
445
+ # - A MKMapRect representation of self
446
+ #
447
+ def api
241
448
  MKMapRectMake(@origin.x, @origin.y, @size.width, @size.height)
242
449
  end
243
450
 
451
+ ##
452
+ # Assigns a MapKit::DataTypes::MapPoint to center.
453
+ #
454
+ # * *Args* :
455
+ # - +origin+ -> accepts a variety of argument types. See docs for the MapKit::DataTypes::MapPoint initializer
456
+ #
244
457
  def origin=(origin)
245
458
  @origin = MapPoint.new(origin)
246
459
  end
247
460
 
461
+ ##
462
+ # Assigns a MapKit::DataTypes::MapSize to center.
463
+ #
464
+ # * *Args* :
465
+ # - +size+ -> accepts a variety of argument types. See docs for the MapKit::DataTypes::MapSize initializer
466
+ #
248
467
  def size=(size)
249
468
  @size = MapSize.new(size)
250
469
  end
251
470
 
471
+ ##
472
+ # Get self as a Hash
473
+ #
474
+ # * *Returns* :
475
+ # - <tt>{:origin => {:x => x, :y => y}, :size => {:width => width, :height => height}}</tt>
476
+ #
252
477
  def to_h
253
478
  {:origin => @origin.to_h, :size => @size.to_h}
254
479
  end
255
480
 
481
+ ##
482
+ # Get self as a String
483
+ #
484
+ # * *Returns* :
485
+ # - <tt>"{:origin => {:x => x, :y => y}, :size => {:width => width, :height => height}}"</tt>
486
+ #
256
487
  def to_s
257
488
  to_h.to_s
258
489
  end
@@ -1,5 +1,22 @@
1
+ ##
2
+ # Wrappers for MapKit
3
+ #
1
4
  module MapKit
5
+
6
+ ##
7
+ # Class for dealing with MKMapView map type constants
8
+ #
2
9
  class MapType
10
+
11
+ ##
12
+ # Convert from MKMapView to MapView
13
+ #
14
+ # * *Args* :
15
+ # - +map_type+ -> Map type as MKMapView constant
16
+ #
17
+ # * *Returns* :
18
+ # - map type as symbol
19
+ #
3
20
  def self.mkmap_to_rmap(map_type)
4
21
  case map_type
5
22
  when MKMapTypeStandard
@@ -13,6 +30,15 @@ module MapKit
13
30
  end
14
31
  end
15
32
 
33
+ ##
34
+ # Convert from MapView to MKMapView
35
+ #
36
+ # * *Args* :
37
+ # - +map_type+ -> Map type as symbol
38
+ #
39
+ # * *Returns* :
40
+ # - Map type as MKMapView constant
41
+ #
16
42
  def self.rmap_to_mkmap(map_type)
17
43
  case map_type
18
44
  when :standard
@@ -13,78 +13,132 @@ module MapKit
13
13
  include MapKit::DataTypes
14
14
  include MapKit::ZoomLevel
15
15
 
16
+ ##
17
+ # Initializer for MapView
18
+ #
16
19
  def initialize
17
20
  self.alloc.init
18
21
  end
19
22
 
20
23
  ##
21
- # Show if zoom is enabled
24
+ # Is zoom enabled
25
+ #
26
+ # * *Returns* :
27
+ # - Bool
28
+ #
22
29
  def zoom_enabled?
23
30
  self.isZoomEnabled
24
31
  end
25
32
 
26
33
  ##
27
34
  # Set zoom on/off
35
+ #
36
+ # * *Args* :
37
+ # - +enabled+ -> Bool
38
+ #
28
39
  def zoom_enabled=(enabled)
29
40
  self.setZoomEnabled(enabled)
30
41
  end
31
42
 
32
43
  ##
33
- # Show if scroll is enbaled
44
+ # Is scroll enbabled?
45
+ #
46
+ # * *Returns* :
47
+ # - Bool
48
+ #
34
49
  def scroll_enabled?
35
50
  self.isScrollEnabled
36
51
  end
37
52
 
38
53
  ##
39
54
  # Set scroll on/off
55
+ #
56
+ # * *Args* :
57
+ # - +enabled+ -> Bool
58
+ #
40
59
  def scroll_enabled=(enabled)
41
60
  self.setScrollEnabled(enabled)
42
61
  end
43
62
 
44
63
  ##
45
- # Show if the users location is on the map
64
+ # Is the users location shown on the map
65
+ #
66
+ # * *Returns* :
67
+ # - Bool
68
+ #
46
69
  def shows_user_location?
47
70
  self.showsUserLocation
48
71
  end
49
72
 
50
73
  ##
51
74
  # Set visible user location on/off
75
+ #
76
+ # * *Args* :
77
+ # - +enabled+ -> Bool
78
+ #
52
79
  def shows_user_location=(enabled)
53
80
  self.showsUserLocation = enabled
54
81
  end
55
82
 
56
83
  ##
57
- # Show if the users has been located yet
84
+ # Has the user been located yet?
85
+ #
86
+ # * *Returns* :
87
+ # - Bool
88
+ #
58
89
  def user_located?
59
90
  self.shows_user_location? && self.userLocation.location ? true : false
60
91
  end
61
92
 
62
93
  ##
63
- # Show the users coordinates
64
- # defaults to nil if the functionality is turned off
65
- # or the location has not yet been found
94
+ # Show the users coordinates. Defaults to nil if the functionality is turned off or the location has not yet been found
95
+ #
96
+ # * *Returns* :
97
+ # - LocationCoordinate
98
+ #
66
99
  def user_coordinates
67
100
  self.user_located? ? LocationCoordinate.new(self.userLocation.location.coordinate) : nil
68
101
  end
69
102
 
70
103
  ##
71
- # Get the maps region
72
- def get_region
73
- CoordinateRegion.new(self.region.center, self.region.span)
104
+ # Set the maps region
105
+ #
106
+ # * *Args* :
107
+ # region = CoordinateRegion.new([56, 10.6], [3.1, 3.1])
108
+ # region = {:region => CoordinateRegion.new([56, 10.6], [3.1, 3.1]), :animated => false}
109
+ #
110
+ def region=(args)
111
+ case args
112
+ when Hash
113
+ self.setRegion(CoordinateRegion.new(args[:region]).api, animated: args[:animated])
114
+ else
115
+ self.setRegion(CoordinateRegion.new(args).api, animated: false)
116
+ end
74
117
  end
75
118
 
76
119
  ##
77
- # Set the maps region
78
- def region=(*args)
79
- self.set_region(CoordinateRegion.new(args.first), false)
120
+ # Deprecated
121
+ #
122
+ def set_region
123
+ raise 'set_region has been deprecated. Please review the docs on region=()'
80
124
  end
81
125
 
82
126
  ##
83
- # Set the maps region including animation
84
- def set_region(coordinate_region, *args)
85
- opts = {:animated => false}
86
- opts.merge!(args.first) if args.first
87
- self.setRegion(coordinate_region.sdk, animated: opts[:animated])
127
+ # Trick to override methods on the iOS APi and to get super on those methods
128
+ #
129
+ module OverriddenMethods
130
+ include MapKit::DataTypes
131
+ ##
132
+ # Get the maps region
133
+ #
134
+ # * *Returns* :
135
+ # - CoordinateRegion
136
+ #
137
+ def region
138
+ CoordinateRegion.new(super)
139
+ end
88
140
  end
141
+
142
+ include OverriddenMethods
89
143
  end
90
144
  end
@@ -1,6 +1,15 @@
1
+ ##
2
+ # Dummy class used for tests
3
+ #
1
4
  class TestSuiteDelegate
5
+ ##
6
+ # Attribute accessor
7
+ #
2
8
  attr_accessor :window
3
9
 
10
+ ##
11
+ # Init App
12
+ #
4
13
  def application(application, didFinishLaunchingWithOptions: launchOptions)
5
14
  @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
6
15
  @window.rootViewController = UIViewController.alloc.init
@@ -1,3 +1,7 @@
1
1
  module MapKit
2
- VERSION = '0.0.4'
2
+
3
+ ##
4
+ # Current gem version
5
+ #
6
+ VERSION = '0.0.5'
3
7
  end
@@ -1,21 +1,51 @@
1
1
  module MapKit
2
+
2
3
  ##
3
4
  # Ruby adaption of http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
5
+ #
4
6
  # More here http://troybrant.net/blog/2010/01/mkmapview-and-zoom-levels-a-visual-guide/
7
+ #
5
8
  module ZoomLevel
6
9
  include Math
10
+
11
+ ##
12
+ # Total map width in pixels
13
+ #
7
14
  MERCATOR_OFFSET = 268435456.0
15
+
16
+ ##
17
+ # Map radius in pixels
18
+ #
8
19
  MERCATOR_RADIUS = MERCATOR_OFFSET / PI
9
20
 
10
21
  ##
11
22
  # Map conversion methods
23
+ #
12
24
  module ClassMethods
13
25
  include Math
14
26
 
27
+ ##
28
+ # Convert longitude to pixel space x
29
+ #
30
+ # * *Args* :
31
+ # - +longitude+ -> Int or Float
32
+ #
33
+ # * *Returns* :
34
+ # - Pixel space x as Int
35
+ #
15
36
  def longitude_to_pixel_space_x(longitude)
16
37
  (MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * PI / 180.0).round
17
38
  end
18
39
 
40
+ ##
41
+ # Convert latitude to pixel space y
42
+ #
43
+ # * *Args* :
44
+ # - +latitude+ -> Int or Float
45
+ #
46
+ # * *Returns* :
47
+ # - Pixel space y as Int
48
+ #
19
49
  def latitude_to_pixel_space_y(latitude)
20
50
  if latitude == 90.0
21
51
  0
@@ -26,14 +56,43 @@ module MapKit
26
56
  end
27
57
  end
28
58
 
59
+ ##
60
+ # Convert pixel space x to longitude
61
+ #
62
+ # * *Args* :
63
+ # - +pixel_x+ -> Int
64
+ #
65
+ # * *Returns* :
66
+ # - Longitude as float
67
+ #
29
68
  def pixel_space_x_to_longitude(pixel_x)
30
69
  ((pixel_x.round - MERCATOR_OFFSET) / MERCATOR_RADIUS) * 180.0 / PI
31
70
  end
32
71
 
72
+ ##
73
+ # Convert pixel space y to latitude
74
+ #
75
+ # * *Args* :
76
+ # - +pixel_y+ -> Int
77
+ #
78
+ # * *Returns* :
79
+ # - Latitude as float
80
+ #
33
81
  def pixel_space_y_to_latitude(pixel_y)
34
82
  (PI / 2.0 - 2.0 * atan(exp((pixel_y.round - MERCATOR_OFFSET) / MERCATOR_RADIUS))) * 180.0 / PI
35
83
  end
36
84
 
85
+ ##
86
+ # Get the coordiante span for the given zoom level
87
+ #
88
+ # * *Args* :
89
+ # - +map_view+ -> A MKMapView
90
+ # - +center_coordinates+ -> Coordinates as MKMapPoint
91
+ # - +zoom_level+ -> Zoom level as Int
92
+ #
93
+ # * *Returns* :
94
+ # - Span as MKCoordinateSpan
95
+ #
37
96
  def coordinate_span_with_map_view(map_view, center_coordinate, zoom_level)
38
97
  # convert center coordiate to pixel space
39
98
  center_pixel_x = self.longitude_to_pixel_space_x(center_coordinate.longitude)
@@ -67,8 +126,18 @@ module MapKit
67
126
  end
68
127
 
69
128
  ##
70
- # KMapView cannot display tiles that cross the pole
129
+ # Get the coordiante region for the given zoom level
130
+ #
71
131
  # This would involve wrapping the map from top to bottom, something that a Mercator projection just cannot do.
132
+ #
133
+ # * *Args* :
134
+ # - +map_view+ -> A MKMapView
135
+ # - +center_coordinates+ -> Coordinates as MKMapPoint
136
+ # - +zoom_level+ -> Zoom level as Int
137
+ #
138
+ # * *Returns* :
139
+ # - Region as MKCoordinateRegion
140
+ #
72
141
  def coordinate_region_with_map_view(map_view, center_coordinate, zoom_level)
73
142
 
74
143
  # clamp lat/long values to appropriate ranges
@@ -125,12 +194,21 @@ module MapKit
125
194
  end
126
195
  end
127
196
 
197
+ ##
198
+ # Include class methods
199
+ #
128
200
  def self.included(base)
129
201
  base.extend(ClassMethods)
130
202
  end
131
203
 
132
- # Public methods
133
-
204
+ ##
205
+ # Set the views center coordinates with a given zoom level
206
+ #
207
+ # * *Args* :
208
+ # - +center_coordinate+ -> A MKMapPoint
209
+ # - +zoom_level+ -> Zoom level as Int
210
+ # - +animated+ -> bool
211
+ #
134
212
  def set_center_coordinates(center_coordinate, zoom_level, animated = false)
135
213
  # clamp large numbers to 18
136
214
  zoom_level = [zoom_level, 18].min
@@ -143,17 +221,28 @@ module MapKit
143
221
  self.setRegion(region, animated: animated)
144
222
  end
145
223
 
224
+ ##
225
+ # Set the views latitude and longitude with a given zoom level
226
+ #
227
+ # * *Args* :
228
+ # - +latitude+ -> Float
229
+ # - +longitude+ -> Float
230
+ # - +zoom_level+ -> Zoom level as Int
231
+ # - +animated+ -> bool
232
+ #
146
233
  def set_map_lat_lon(latitude, longitude, zoom_level, animated = false)
147
234
  coordinates = CLLocationCoordinate2DMake(latitude, longitude)
148
- self.set_center_coordinates(coordinates, zoom_level, animated)
235
+ set_center_coordinates(coordinates, zoom_level, animated)
149
236
  end
150
237
 
151
238
  ##
152
239
  # Get the current zoom level
153
-
240
+ #
241
+ # * *Returns* :
242
+ # - Zoom level as a Float
243
+ #
154
244
  def zoom_level
155
- region = self.region
156
-
245
+ region = self.region.api
157
246
  center_pixel_x = self.class.longitude_to_pixel_space_x(region.center.longitude)
158
247
  top_left_pixel_x = self.class.longitude_to_pixel_space_x(region.center.longitude - region.span.longitudeDelta / 2)
159
248
 
@@ -167,9 +256,13 @@ module MapKit
167
256
 
168
257
  ##
169
258
  # Set the current zoom level
170
-
259
+ #
260
+ # * *Args* :
261
+ # - +zoom_level+ -> Int or Float
262
+ # - +animated+ -> Bool
263
+ #
171
264
  def set_zoom_level(zoom_level, animated = false)
172
- self.set_center_coordinates(self.region.center, zoom_level, animated)
265
+ set_center_coordinates(self.region.api.center, zoom_level, animated)
173
266
  end
174
267
 
175
268
  end
@@ -54,7 +54,7 @@ describe 'LocationCoordinate' do
54
54
 
55
55
  it 'should contain a CLLocationCoordinate2D' do
56
56
  @array.each do |lc|
57
- lc.sdk.is_a?(CLLocationCoordinate2D).should.equal true
57
+ lc.api.is_a?(CLLocationCoordinate2D).should.equal true
58
58
  end
59
59
  end
60
60
  end
@@ -35,7 +35,7 @@ describe 'MapKitDataTypes' do
35
35
 
36
36
  it 'should contain a MKCoordinateSpan' do
37
37
  @array.each do |o|
38
- o.sdk.is_a?(MKCoordinateSpan).should.equal true
38
+ o.api.is_a?(MKCoordinateSpan).should.equal true
39
39
  end
40
40
  end
41
41
  end
@@ -78,7 +78,7 @@ describe 'MapKitDataTypes' do
78
78
 
79
79
  it 'should contain a MKCoordinateRegion' do
80
80
  @array.each do |o|
81
- o.sdk.is_a?(MKCoordinateRegion).should.equal true
81
+ o.api.is_a?(MKCoordinateRegion).should.equal true
82
82
  end
83
83
  end
84
84
  end
@@ -118,7 +118,7 @@ describe 'MapKitDataTypes' do
118
118
 
119
119
  it 'should contain a MKMapPoint' do
120
120
  @array.each do |o|
121
- o.sdk.is_a?(MKMapPoint).should.equal true
121
+ o.api.is_a?(MKMapPoint).should.equal true
122
122
  end
123
123
  end
124
124
  end
@@ -158,7 +158,7 @@ describe 'MapKitDataTypes' do
158
158
 
159
159
  it 'should contain a MKMapSize' do
160
160
  @array.each do |o|
161
- o.sdk.is_a?(MKMapSize).should.equal true
161
+ o.api.is_a?(MKMapSize).should.equal true
162
162
  end
163
163
  end
164
164
  end
@@ -173,7 +173,7 @@ describe 'MapKitDataTypes' do
173
173
  o_4 = MapKit::DataTypes::MapRect.new(MKMapPointMake(5, 8), MKMapSizeMake(6, 9))
174
174
  o_5 = MapKit::DataTypes::MapRect.new({:origin => {:x => 5.0, :y => 8.0}, :size => {:width => 6.0, :height => 9.0}})
175
175
  o_6 = MapKit::DataTypes::MapRect.new(o_5)
176
- o_7 = MapKit::DataTypes::MapRect.new(o_5.sdk)
176
+ o_7 = MapKit::DataTypes::MapRect.new(o_5.api)
177
177
  @array = [o_1, o_2, o_3, o_4, o_5, o_6, o_7]
178
178
  end
179
179
 
@@ -201,7 +201,7 @@ describe 'MapKitDataTypes' do
201
201
 
202
202
  it 'should contain a MKMapRect' do
203
203
  @array.each do |o|
204
- o.sdk.is_a?(MKMapRect).should.equal true
204
+ o.api.is_a?(MKMapRect).should.equal true
205
205
  end
206
206
  end
207
207
  end
@@ -64,17 +64,17 @@ describe 'MapView' do
64
64
  # region
65
65
 
66
66
  it 'should show get_region' do
67
- @map.get_region.should.satisfy { |object| object.is_a? MapKit::DataTypes::CoordinateRegion }
67
+ @map.region.should.satisfy { |object| object.is_a? MapKit::DataTypes::CoordinateRegion }
68
68
  end
69
69
 
70
70
  it 'should set region=' do
71
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 }
72
+ @map.region.should.satisfy { |object| object.is_a? MapKit::DataTypes::CoordinateRegion }
73
73
  end
74
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 }
75
+ it 'should set region = (coordinate_region, *args)' do
76
+ @map.region = {:region => MapKit::CoordinateRegion.new([56, 10.6], [3.1, 3.1]), :animated => false}
77
+ @map.region.should.satisfy { |object| object.is_a? MapKit::DataTypes::CoordinateRegion }
78
78
  end
79
79
 
80
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: map-kit-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-24 00:00:00.000000000 Z
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: codependency