Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add animated tracking halo

  • Loading branch information...
commit c33c7a524fa5835442313e4d6f3e9ad6b0ad9c3a 1 parent 366ca7e
@incanus incanus authored
View
4 MapBox Me.xcodeproj/project.pbxproj
@@ -13,6 +13,7 @@
DD005CF61524F065006B9481 /* TrackingDot.png in Resources */ = {isa = PBXBuildFile; fileRef = DD005CF41524F065006B9481 /* TrackingDot.png */; };
DD005D1B1524F0F2006B9481 /* routeme.plist in Resources */ = {isa = PBXBuildFile; fileRef = DD005D1A1524F0F2006B9481 /* routeme.plist */; };
DD005D211524F386006B9481 /* Entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = DD005D201524F386006B9481 /* Entitlements.plist */; };
+ DD5960A1152676BE0086568C /* TrackingDotHalo.png in Resources */ = {isa = PBXBuildFile; fileRef = DD5960A0152676BE0086568C /* TrackingDotHalo.png */; };
DDD0B7A61524D4E400EBC267 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDD0B7A51524D4E400EBC267 /* UIKit.framework */; };
DDD0B7A81524D4E400EBC267 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDD0B7A71524D4E400EBC267 /* Foundation.framework */; };
DDD0B7AA1524D4E400EBC267 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDD0B7A91524D4E400EBC267 /* CoreGraphics.framework */; };
@@ -58,6 +59,7 @@
DD005CF41524F065006B9481 /* TrackingDot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TrackingDot.png; sourceTree = "<group>"; };
DD005D1A1524F0F2006B9481 /* routeme.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = routeme.plist; sourceTree = "<group>"; };
DD005D201524F386006B9481 /* Entitlements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Entitlements.plist; sourceTree = SOURCE_ROOT; };
+ DD5960A0152676BE0086568C /* TrackingDotHalo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TrackingDotHalo.png; sourceTree = "<group>"; };
DDD0B7A11524D4E400EBC267 /* MapBox Me.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "MapBox Me.app"; sourceTree = BUILT_PRODUCTS_DIR; };
DDD0B7A51524D4E400EBC267 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
DDD0B7A71524D4E400EBC267 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -148,6 +150,7 @@
DDD0B7B31524D4E400EBC267 /* MapBox Me-Prefix.pch */,
DD005CF41524F065006B9481 /* TrackingDot.png */,
DD005CF31524F065006B9481 /* TrackingDot@2x.png */,
+ DD5960A0152676BE0086568C /* TrackingDotHalo.png */,
DD005CDD1524EDB1006B9481 /* icon.png */,
DD005CDC1524EDB1006B9481 /* icon@2x.png */,
DD005D1A1524F0F2006B9481 /* routeme.plist */,
@@ -258,6 +261,7 @@
DD005CF61524F065006B9481 /* TrackingDot.png in Resources */,
DD005D1B1524F0F2006B9481 /* routeme.plist in Resources */,
DD005D211524F386006B9481 /* Entitlements.plist in Resources */,
+ DD5960A1152676BE0086568C /* TrackingDotHalo.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
63 MapBox Me/MBMViewController.m
@@ -18,6 +18,7 @@ @interface MBMViewController ()
@property (nonatomic, strong) IBOutlet RMMapView *mapView;
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) RMAnnotation *accuracyCircle;
+@property (nonatomic, strong) RMAnnotation *trackingHalo;
@property (nonatomic, strong) RMAnnotation *userLocation;
@property (nonatomic, assign) BOOL updating;
@@ -30,6 +31,7 @@ @implementation MBMViewController
@synthesize mapView;
@synthesize locationManager;
@synthesize accuracyCircle;
+@synthesize trackingHalo;
@synthesize userLocation;
@synthesize updating;
@@ -102,6 +104,8 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLoca
[self.mapView zoomWithLatitudeLongitudeBoundsSouthWest:southWest northEast:northEast animated:YES];
+ // accuracy circle: visible when homing in
+ //
if ( ! self.accuracyCircle)
{
self.accuracyCircle = [RMAnnotation annotationWithMapView:self.mapView coordinate:manager.location.coordinate andTitle:nil];
@@ -111,6 +115,23 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLoca
self.accuracyCircle.coordinate = manager.location.coordinate;
+ [self.mapView.delegate mapView:self.mapView layerForAnnotation:self.accuracyCircle].hidden = (manager.location.horizontalAccuracy <= 10);
+
+ // tracking halo: visible after homing in
+ //
+ if ( ! self.trackingHalo)
+ {
+ self.trackingHalo = [RMAnnotation annotationWithMapView:self.mapView coordinate:manager.location.coordinate andTitle:nil];
+
+ [self.mapView addAnnotation:self.trackingHalo];
+ }
+
+ self.trackingHalo.coordinate = manager.location.coordinate;
+
+ [self.mapView.delegate mapView:self.mapView layerForAnnotation:self.trackingHalo].hidden = (manager.location.horizontalAccuracy > 10);
+
+ // user location: always visible
+ //
if ( ! self.userLocation)
{
self.userLocation = [RMAnnotation annotationWithMapView:self.mapView coordinate:manager.location.coordinate andTitle:nil];
@@ -140,15 +161,51 @@ - (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)
{
RMCircle *circle = [[RMCircle alloc] initWithView:self.mapView radiusInMeters:self.locationManager.location.horizontalAccuracy];
- circle.lineColor = [UIColor colorWithRed:0 green:0 blue:1.0 alpha:0.25];
- circle.fillColor = [UIColor colorWithRed:0 green:0 blue:1.0 alpha:0.1];
+ circle.lineColor = [UIColor colorWithRed:0.378 green:0.552 blue:0.827 alpha:0.7];
+ circle.fillColor = [UIColor colorWithRed:0.378 green:0.552 blue:0.827 alpha:0.15];
- circle.lineWidthInPixels = 1.0;
+ circle.lineWidthInPixels = 2.0;
// TODO: add throbber animation
return circle;
}
+ else if ([annotation isEqual:self.trackingHalo])
+ {
+ RMMarker *halo = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDotHalo.png"]];
+
+ CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
+
+ boundsAnimation.duration = 2.0;
+
+ boundsAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
+
+ boundsAnimation.repeatCount = MAXFLOAT;
+
+ boundsAnimation.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, halo.bounds.size.width * 0.2, halo.bounds.size.height * 0.2)];
+ boundsAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, halo.bounds.size.width * 1.1, halo.bounds.size.height * 1.1)];
+
+ boundsAnimation.removedOnCompletion = NO;
+
+ [halo addAnimation:boundsAnimation forKey:@"animateBounds"];
+
+ CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
+
+ opacityAnimation.duration = 2.0;
+
+ opacityAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
+
+ opacityAnimation.repeatCount = MAXFLOAT;
+
+ opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0];
+ opacityAnimation.toValue = [NSNumber numberWithFloat:0.0];
+
+ opacityAnimation.removedOnCompletion = NO;
+
+ [halo addAnimation:opacityAnimation forKey:@"animateOpacity"];
+
+ return halo;
+ }
else if ([annotation isEqual:self.userLocation])
{
return [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDot.png"]];
View
BIN  MapBox Me/TrackingDotHalo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.