lib/ProMotion/map/map_screen_module.rb in ProMotion-map-0.4.0 vs lib/ProMotion/map/map_screen_module.rb in ProMotion-map-0.4.1

- old
+ new

@@ -1,14 +1,12 @@ module ProMotion module MapScreenModule - attr_accessor :mapview def screen_setup - self.mapview ||= add MKMapView.new, { - frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height), - delegate: self - } + self.view = nil + self.view = MKMapView.alloc.initWithFrame(self.view.bounds) + self.view.delegate = self check_annotation_data @promotion_annotation_data = [] set_up_start_position end @@ -26,24 +24,25 @@ clear_annotations add_annotations annotation_data end def map - self.mapview + self.view end + alias_method :mapview, :map def center - self.mapview.centerCoordinate + self.view.centerCoordinate end def center=(params={}) PM.logger.error "Missing #:latitude property in call to #center=." unless params[:latitude] PM.logger.error "Missing #:longitude property in call to #center=." unless params[:longitude] params[:animated] ||= true # Set the new region - self.mapview.setCenterCoordinate( + self.view.setCenterCoordinate( CLLocationCoordinate2D.new(params[:latitude], params[:longitude]), animated:params[:animated] ) end @@ -54,19 +53,19 @@ def hide_user_location set_show_user_location false end def set_show_user_location(show) - self.mapview.showsUserLocation = show + self.view.showsUserLocation = show end def showing_user_location? - self.mapview.showsUserLocation + self.view.showsUserLocation end def user_location - self.mapview.userLocation.location.nil? ? nil : self.mapview.userLocation.location.coordinate + self.view.userLocation.location.nil? ? nil : self.view.userLocation.location.coordinate end def zoom_to_user(radius = 0.05, animated=true) show_user_location unless showing_user_location? set_region(MKCoordinateRegionMake(user_location, [radius, radius]), animated) @@ -75,42 +74,42 @@ def annotations @promotion_annotation_data end def select_annotation(annotation, animated=true) - self.mapview.selectAnnotation(annotation, animated:animated) + self.view.selectAnnotation(annotation, animated:animated) end def select_annotation_at(annotation_index, animated=true) select_annotation(annotations[annotation_index], animated:animated) end def selected_annotations - self.mapview.selectedAnnotations + self.view.selectedAnnotations end def deselect_annotations(animated=false) unless selected_annotations.nil? selected_annotations.each do |annotation| - self.mapview.deselectAnnotation(annotation, animated:animated) + self.view.deselectAnnotation(annotation, animated:animated) end end end def add_annotation(annotation) @promotion_annotation_data << MapScreenAnnotation.new(annotation) - self.mapview.addAnnotation @promotion_annotation_data.last + self.view.addAnnotation @promotion_annotation_data.last end def add_annotations(annotations) @promotion_annotation_data = Array(annotations).map{|a| MapScreenAnnotation.new(a)} - self.mapview.addAnnotations @promotion_annotation_data + self.view.addAnnotations @promotion_annotation_data end def clear_annotations @promotion_annotation_data.each do |a| - self.mapview.removeAnnotation(a) + self.view.removeAnnotation(a) end @promotion_annotation_data = [] end def annotation_view(map_view, annotation) @@ -198,17 +197,17 @@ ((topLeft.latitude - bottomRight.latitude) * 1.075).abs, ((bottomRight.longitude - topLeft.longitude) * 1.075).abs ) region = MKCoordinateRegionMake(coord, span) - fits = self.mapview.regionThatFits(region); + fits = self.view.regionThatFits(region); set_region(fits, animated:animated) end def set_region(region, animated=true) - self.mapview.setRegion(region, animated:animated) + self.view.setRegion(region, animated:animated) end def region(params) return nil unless params.is_a? Hash @@ -237,9 +236,29 @@ def mapView(map_view, didUpdateUserLocation:userLocation) if self.respond_to?(:on_user_location) on_user_location(userLocation) else PM.logger.info "You're tracking the user's location but have not implemented the #on_user_location(location) method in MapScreen #{self.class.to_s}." + end + end + + ########## Cocoa touch Ruby counterparts ################# + + def type + map.mapType + end + + def type=(type) + map.mapType = type + end + + %w(zoom scroll pitch rotate).each do |meth| + define_method("#{meth}_enabled?") do + map.send("is#{meth.capitalize}Enabled") + end + + define_method("#{meth}_enabled=") do |argument| + map.send("#{meth}Enabled=", argument) end end module MapClassMethods def start_position(params={})