Permalink
Browse files

Updated RDoc

  • Loading branch information...
1 parent 9844e45 commit d0efb9481d8b4965f482357763865b74ad44fc71 @weibel committed Aug 22, 2012
View
@@ -94,7 +94,7 @@ Location methods
### MapView zoom level methods
-MapView includes calculations to easily get and set the zoom level as seen on Google Maps
+MapView includes calculations to easily get and set the zoom level as seen on Google Maps.
It's a Ruby adaption of http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
```ruby
View
@@ -7,7 +7,7 @@
base_path = "#{File.dirname(__FILE__)}/map-kit-wrapper"
graph = Codependency::Graph.new("#{base_path}/map_view.rb")
- files = (graph.files + Dir.glob(File.join(File.dirname(__FILE__), 'map-kit-wrapper/*.rb')).map { |file| file }).uniq
+ files = (graph.files + Dir.glob(File.join(File.dirname(__FILE__), 'map-kit-wrapper/*.rb'))).uniq
files.reverse.each do |file|
app.files.unshift(file)
end
@@ -1,12 +1,14 @@
module CoreLocation
+ ##
# Wrappers for the Core Location Data Types
# http://developer.apple.com/library/mac/#documentation/CoreLocation/Reference/CoreLocationDataTypesRef/Reference/reference.html
module DataTypes
-
+ ##
# Ruby wrapper for CLLocationCoordinate2D
class LocationCoordinate
attr_reader :sdk
+ ##
# LocationCoordinate.new(1,2)
# LocationCoordinate.new([1,2])
# LocationCoordinate.new(LocationCoordinate)
@@ -1,14 +1,15 @@
# require core_location_data_types
module MapKit
+ ##
# Wrappers for the Map Kit Data Types
# http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MapKitDataTypesReference/Reference/reference.html
module DataTypes
-
+ ##
# Wrapper for MKCoordinateSpan
class CoordinateSpan
attr_reader :sdk
-
+ ##
# CoordinateSpan.new(1,2)
# CoordinateSpan.new([1,2])
# CoordinateSpan.new(MKCoordinateSpan)
@@ -33,12 +34,12 @@ def to_array
[latitude_delta, longitude_delta]
end
end
-
+ ##
# Wrapper for MKCoordinateRegion
class CoordinateRegion
include CoreLocation::DataTypes
attr_reader :sdk
-
+ ##
# CoordinateRegion.new(CoordinateRegion)
# CoordinateRegion.new(MKCoordinateRegion)
# CoordinateRegion.new([56, 10.6], [3.1, 3.1])
@@ -70,11 +71,11 @@ def to_hash
{:center => center.to_array, :span => span.to_array}
end
end
-
+ ##
# Wrapper for MKMapPoint
class MapPoint
attr_reader :sdk
-
+ ##
# MapPoint.new(50,45)
# MapPoint.new([50,45])
# MapPoint.new(MKMapPoint)
@@ -99,11 +100,11 @@ def to_array
[x, y]
end
end
-
+ ##
# Wrapper for MKMapSize
class MapSize
attr_reader :sdk
-
+ ##
# MapSize.new(10,12)
# MapSize.new([10,12])
# MapSize.new(MKMapSize)
@@ -128,11 +129,11 @@ def to_array
[width, height]
end
end
-
+ ##
# Wrapper for MKMapRect
class MapRect
attr_reader :sdk
-
+ ##
# MapRect.new(x, y, width, height)
# MapRect.new([x, y], [width, height])
# MapRect.new(MapPoint, MapSize)
@@ -8,6 +8,8 @@ def self.mkmap_to_rmap(map_type)
:satellite
when MKMapTypeHybrid
:hybrid
+ else
+ raise "Unknown map type: #{map_type.inspect}"
end
end
@@ -19,6 +21,8 @@ def self.rmap_to_mkmap(map_type)
MKMapTypeSatellite
when :hybrid
MKMapTypeHybrid
+ else
+ raise "Unknown map type: #{map_type.inspect}"
end
end
end
@@ -6,6 +6,7 @@ module MapKit
include CoreLocation::DataTypes
include MapKit::DataTypes
+ ##
# Wrapper for MKMapView
class MapView < MKMapView
include CoreLocation::DataTypes
@@ -16,58 +17,74 @@ def initialize
self.alloc.init
end
- # zoom methods
-
+ ##
+ # Show if zoom is enabled
def zoom_enabled?
self.isZoomEnabled
end
+ ##
+ # Set zoom on/off
def zoom_enabled=(enabled)
self.setZoomEnabled(enabled)
end
- # scroll methods
-
+ ##
+ # Show if scroll is enbaled
def scroll_enabled?
self.isScrollEnabled
end
+ ##
+ # Set scroll on/off
def scroll_enabled=(enabled)
self.setScrollEnabled(enabled)
end
- # user location methods
-
+ ##
+ # Show if the users location is on the map
def shows_user_location?
self.showsUserLocation
end
+ ##
+ # Set visible user location on/off
def shows_user_location=(enabled)
self.showsUserLocation = enabled
end
+ ##
+ # Show if the users has been located yet
def user_located?
self.shows_user_location? && self.userLocation.location ? true : false
end
+ ##
+ # Show the users coordinates
+ # defaults to nil if the functionality is turned off
+ # or the location has not yet been found
def user_coordinates
self.user_located? ? LocationCoordinate.new(self.userLocation.location.coordinate) : nil
end
- # region methods
-
+ ##
+ # Get the maps region
def get_region
CoordinateRegion.new(self.region.center, self.region.span)
end
+ ##
+ # Set the maps region
def region=(*args)
self.set_region(CoordinateRegion.new(args.first), false)
end
+ ##
+ # Set the maps region including animation
def set_region(coordinate_region, *args)
opts = {:animated => false}
opts.merge!(args.first) if args.first
- self.setRegion(coordinate_region.sdk, animated:opts[:animated])
+ self.setRegion(coordinate_region.sdk, animated: opts[:animated])
end
end
end
@@ -1,13 +1,15 @@
module MapKit
- # Ruby conversion of http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
+ ##
+ # Ruby adaption of http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
module ZoomLevel
include Math
MERCATOR_OFFSET = 268435456.0
MERCATOR_RADIUS = 85445659.44705395
+ ##
+ # Map conversion methods
module ClassMethods
include Math
- # Map conversion methods
def longitude_to_pixel_space_x(longitude)
(MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * PI / 180.0).round
@@ -63,6 +65,7 @@ def coordinate_span_with_map_view(map_view, center_coordinate, zoom_level)
MKCoordinateSpanMake(latitude_delta, longitude_delta)
end
+ ##
# KMapView cannot display tiles that cross the pole
# This would involve wrapping the map from top to bottom, something that a Mercator projection just cannot do.
def coordinate_region_with_map_view(map_view, center_coordinate, zoom_level)
@@ -127,9 +130,9 @@ def self.included(base)
# Public methods
- def set_center_coordinates(center_coordinate, zoom_level, animated)
- # clamp large numbers to 28
- zoom_level = [zoom_level, 28].min
+ def set_center_coordinates(center_coordinate, zoom_level, animated = false)
+ # clamp large numbers to 18
+ zoom_level = [zoom_level, 18].min
# use the zoom level to compute the region
span = self.class.coordinate_span_with_map_view(self, center_coordinate, zoom_level)
@@ -139,11 +142,14 @@ def set_center_coordinates(center_coordinate, zoom_level, animated)
self.setRegion(region, animated: animated)
end
- def set_map_lat_lon(latitude, longitude, zoom_level, animated)
+ def set_map_lat_lon(latitude, longitude, zoom_level, animated = false)
coordinates = CLLocationCoordinate2DMake(latitude, longitude)
self.set_center_coordinates(coordinates, zoom_level, animated)
end
+ ##
+ # Get the current zoom level
+
def zoom_level
region = self.region
@@ -158,5 +164,12 @@ def zoom_level
zoom_level
end
+ ##
+ # Set the current zoom level
+
+ def set_zoom_level(zoom_level, animated = false)
+ self.set_center_coordinates(self.region.center, zoom_level, animated)
+ end
+
end
end
@@ -40,6 +40,8 @@
span.longitude_delta.should.equal 56.25
center.latitude.should.equal 55.9737854003906
center.longitude.should.equal 10.01953125
+ @map.set_center_coordinates(CLLocationCoordinate2DMake(0, 0), 50, false)
+ @map.zoom_level.should.equal 18
end
it 'should return set_map_lat_lon' do
@@ -68,4 +70,9 @@
it 'should have a zoom_level' do
@map.zoom_level.should.equal 5.00000381469727
end
+
+ it 'should set a zoom_level' do
+ @map.set_zoom_level(15, false)
+ @map.zoom_level.should.equal 15
+ end
end

0 comments on commit d0efb94

Please sign in to comment.