这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions lib/ProMotion/map/map_screen_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ def center=(params={})
)
end

def show_user_location
set_show_user_location true
end

def hide_user_location
set_show_user_location false
end

def set_show_user_location(show)
self.mapview.showsUserLocation = show
end

def showing_user_location?
self.mapview.showsUserLocation
end

def user_location
self.mapview.userLocation.location.nil? ? nil : self.mapview.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)
end

def annotations
@promotion_annotation_data
end
Expand Down Expand Up @@ -95,6 +120,8 @@ def clear_annotations
end

def mapView(mapView, viewForAnnotation:annotation)
return if annotation.is_a? MKUserLocation

identifier = annotation.annotation_params[:identifier]
if view = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
view.annotation = annotation
Expand Down Expand Up @@ -122,7 +149,7 @@ def set_start_position(params={})

initialLocation = CLLocationCoordinate2D.new(params[:latitude], params[:longitude])
region = MKCoordinateRegionMakeWithDistance(initialLocation, params[:radius] * meters_per_mile, params[:radius] * meters_per_mile)
self.mapview.setRegion(region, animated:false)
set_region(region, animated:false)
end

def set_up_start_position
Expand Down Expand Up @@ -163,7 +190,7 @@ def zoom_to_fit_annotations(animated=true)
region = MKCoordinateRegionMake(coord, span)
fits = self.mapview.regionThatFits(region);

self.mapview.setRegion(fits, animated:animated)
set_region(fits, animated:animated)
end

def set_region(region, animated=true)
Expand All @@ -190,6 +217,15 @@ def look_up_address(args={}, &callback)
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)
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

module MapClassMethods
def start_position(params={})
@start_position_params = params
Expand Down
8 changes: 8 additions & 0 deletions spec/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,12 @@
@map.annotations.count.should == 0
end

it "should return false when user location is not being shown" do
@map.showing_user_location?.should == false
end

it "should return nil for user location when not being shown" do
@map.user_location.should == nil
end

end