lib/ProMotion/map/map_screen_module.rb in ProMotion-map-0.1.0 vs lib/ProMotion/map/map_screen_module.rb in ProMotion-map-0.2.0
- old
+ new
@@ -1,14 +1,12 @@
module ProMotion
module MapScreenModule
attr_accessor :mapview
def screen_setup
- check_mapkit_included
self.mapview ||= add MKMapView.new, {
frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height),
- resize: [ :width, :height ],
delegate: self
}
check_annotation_data
@promotion_annotation_data = []
@@ -18,14 +16,10 @@
def view_will_appear(animated)
super
update_annotation_data
end
- def check_mapkit_included
- PM.logger.error "You must add MapKit and CoreLocation to your project's frameworks in the Rakefile." unless defined?(CLLocationCoordinate2D)
- end
-
def check_annotation_data
PM.logger.error "Missing #annotation_data method in MapScreen #{self.class.to_s}." unless self.respond_to?(:annotation_data)
end
def update_annotation_data
@@ -117,28 +111,34 @@
self.mapview.removeAnnotation(a)
end
@promotion_annotation_data = []
end
- def mapView(mapView, viewForAnnotation:annotation)
+ def annotation_view(map_view, annotation)
return if annotation.is_a? MKUserLocation
identifier = annotation.annotation_params[:identifier]
- if view = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
+ if view = map_view.dequeueReusableAnnotationViewWithIdentifier(identifier)
view.annotation = annotation
else
- #Set the pin properties
+ # Set the pin properties
if annotation.annotation_params[:image]
view = MKAnnotationView.alloc.initWithAnnotation(annotation, reuseIdentifier:identifier)
- view.image = annotation.annotation_params[:image]
else
view = MKPinAnnotationView.alloc.initWithAnnotation(annotation, reuseIdentifier:identifier)
- view.animatesDrop = annotation.annotation_params[:animates_drop]
- view.pinColor = annotation.annotation_params[:pin_color]
end
- view.canShowCallout = annotation.annotation_params[:show_callout]
end
+ view.image = annotation.annotation_params[:image] if view.respond_to?("image=") && annotation.annotation_params[:image]
+ view.animatesDrop = annotation.annotation_params[:animates_drop] if view.respond_to?("animatesDrop=")
+ view.pinColor = annotation.annotation_params[:pin_color] if view.respond_to?("pinColor=")
+ view.canShowCallout = annotation.annotation_params[:show_callout] if view.respond_to?("canShowCallout=")
+ if annotation.annotation_params[:left_accessory]
+ view.leftCalloutAccessoryView = annotation.annotation_params[:left_accessory]
+ end
+ if annotation.annotation_params[:right_accessory]
+ view.rightCalloutAccessoryView = annotation.annotation_params[:right_accessory]
+ end
view
end
def set_start_position(params={})
params[:latitude] ||= 37.331789
@@ -173,11 +173,11 @@
topLeft.latitude = [topLeft.latitude, a.coordinate.latitude].max
bottomRight.longitude = [bottomRight.longitude, a.coordinate.longitude].max
bottomRight.latitude = [bottomRight.latitude, a.coordinate.latitude].min
end
- #Find the bounds of all the pins and set the mapView
+ #Find the bounds of all the pins and set the map_view
coord = CLLocationCoordinate2D.new(
topLeft.latitude - (topLeft.latitude - bottomRight.latitude) * 0.5,
topLeft.longitude + (bottomRight.longitude - topLeft.longitude) * 0.5
)
@@ -216,10 +216,14 @@
return geocoder.geocodeAddressString(args[:address].to_s, completionHandler: callback) unless args[:region]
return geocoder.geocodeAddressString(args[:address].to_s, inRegion:args[:region].to_s, completionHandler: callback) if args[:region]
end
########## Cocoa touch methods #################
- def mapView(mapView, didUpdateUserLocation:userLocation)
+ def mapView(map_view, viewForAnnotation:annotation)
+ annotation_view(map_view, annotation)
+ end
+
+ 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