Authored by Justin R. Miller

basic iOS 7 tint response for user location tracking (dot/halo/accuracy)

... ... @@ -98,6 +98,8 @@
@property (nonatomic, retain) CLHeading *heading;
@property (nonatomic, assign) BOOL hasCustomLayer;
- (void)updateTintColor;
@end
#pragma mark -
... ... @@ -2474,6 +2476,24 @@
_showLogoBug = showLogoBug;
}
- (void)tintColorDidChange
{
// update user dot
//
[self.userLocation updateTintColor];
// update user halo
//
UIImage *haloImage = [self tintedTrackingDotHaloImage];
_userHaloTrackingView.image = haloImage;
[(RMMarker *)_trackingHaloAnnotation.layer replaceUIImage:haloImage];
// update accuracy circle
//
((RMCircle *)_accuracyCircleAnnotation.layer).lineColor = self.tintColor;
((RMCircle *)_accuracyCircleAnnotation.layer).fillColor = [self.tintColor colorWithAlphaComponent:0.15];
}
#pragma mark -
#pragma mark LatLng/Pixel translation functions
... ... @@ -3167,7 +3187,7 @@
self.userLocation.layer.hidden = YES;
_userHaloTrackingView = [[UIImageView alloc] initWithImage:[RMMapView resourceImageNamed:@"TrackingDotHalo.png"]];
_userHaloTrackingView = [[UIImageView alloc] initWithImage:[self tintedTrackingDotHaloImage]];
_userHaloTrackingView.center = CGPointMake(round([self bounds].size.width / 2),
round([self bounds].size.height / 2));
... ... @@ -3298,8 +3318,8 @@
_accuracyCircleAnnotation.layer.zPosition = -MAXFLOAT;
_accuracyCircleAnnotation.isUserLocationAnnotation = YES;
((RMCircle *)_accuracyCircleAnnotation.layer).lineColor = [UIColor colorWithRed:0.378 green:0.552 blue:0.827 alpha:0.7];
((RMCircle *)_accuracyCircleAnnotation.layer).fillColor = [UIColor colorWithRed:0.378 green:0.552 blue:0.827 alpha:0.15];
((RMCircle *)_accuracyCircleAnnotation.layer).lineColor = self.tintColor;
((RMCircle *)_accuracyCircleAnnotation.layer).fillColor = [self.tintColor colorWithAlphaComponent:0.15];
((RMCircle *)_accuracyCircleAnnotation.layer).lineWidthInPixels = 2.0;
... ... @@ -3345,7 +3365,7 @@
// create image marker
//
_trackingHaloAnnotation.layer = [[RMMarker alloc] initWithUIImage:[RMMapView resourceImageNamed:@"TrackingDotHalo.png"]];
_trackingHaloAnnotation.layer = [[RMMarker alloc] initWithUIImage:[self tintedTrackingDotHaloImage]];
_trackingHaloAnnotation.layer.zPosition = -MAXFLOAT + 1;
_trackingHaloAnnotation.isUserLocationAnnotation = YES;
... ... @@ -3526,6 +3546,58 @@
self.userTrackingMode = RMUserTrackingModeFollow;
}
- (UIImage *)tintedTrackingDotHaloImage
{
UIImage *templateImage = [RMMapView resourceImageNamed:@"TrackingDotHalo.png"];
CGRect rect = CGRectMake(0, 0, templateImage.size.width * templateImage.scale, templateImage.size.height * templateImage.scale);
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *image = [CIImage imageWithCGImage:templateImage.CGImage];
CIImage *result = nil;
CIFilter *whitePointAdjust = [CIFilter filterWithName:@"CIWhitePointAdjust"];
CIFilter *maximumComponent = [CIFilter filterWithName:@"CIMaximumComponent"];
CIFilter *maskToAlpha = [CIFilter filterWithName:@"CIMaskToAlpha"];
[maskToAlpha setValue:image forKey:kCIInputImageKey];
result = [maskToAlpha valueForKey:kCIOutputImageKey];
[whitePointAdjust setValue:result forKey:kCIInputImageKey];
[whitePointAdjust setValue:[CIColor colorWithCGColor:self.tintColor.CGColor] forKey:kCIInputColorKey];
result = [whitePointAdjust valueForKey:kCIOutputImageKey];
CGImageRef haloImage = [context createCGImage:result fromRect:result.extent];
[whitePointAdjust setValue:image forKey:kCIInputImageKey];
[whitePointAdjust setValue:[CIColor colorWithRed:1 green:0 blue:0] forKey:kCIInputColorKey];
result = [whitePointAdjust valueForKey:kCIOutputImageKey];
[maximumComponent setValue:result forKey:kCIInputImageKey];
result = [maximumComponent valueForKey:kCIOutputImageKey];
[maskToAlpha setValue:result forKey:kCIInputImageKey];
result = [maskToAlpha valueForKey:kCIOutputImageKey];
CGImageRef ringImage = [context createCGImage:result fromRect:result.extent];
rect = CGRectMake(0, 0, rect.size.width / templateImage.scale, rect.size.height / templateImage.scale);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextDrawImage(c, rect, haloImage);
CGContextDrawImage(c, rect, ringImage);
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return finalImage;
}
#pragma mark -
#pragma mark Attribution
... ...
... ... @@ -70,7 +70,12 @@
self.hasCustomLayer = YES;
if ( ! super.layer)
super.layer = [[RMMarker alloc] initWithUIImage:[RMMapView resourceImageNamed:@"TrackingDot.png"]];
{
if (RMPreVersion7)
super.layer = [[RMMarker alloc] initWithUIImage:[RMMapView resourceImageNamed:@"TrackingDot.png"]];
else
[self updateTintColor];
}
super.layer.zPosition = -MAXFLOAT + 2;
}
... ... @@ -83,6 +88,32 @@
return (self.mapView.userTrackingMode != RMUserTrackingModeNone);
}
- (void)updateTintColor
{
if ( ! self.hasCustomLayer)
{
CGRect rect = CGRectMake(0, 0, 24, 24);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [[UIScreen mainScreen] scale]);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShadow(context, CGSizeMake(0, 0), 2);
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextFillEllipseInRect(context, rect);
CGContextSetShadowWithColor(context, CGSizeZero, 0, nil);
CGContextSetFillColorWithColor(context, [self.mapView.tintColor CGColor]);
CGContextFillEllipseInRect(context, CGRectMake(rect.size.width / 6, rect.size.height / 6, rect.size.width * 2/3, rect.size.height * 2/3));
super.layer = [[RMMarker alloc] initWithUIImage:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
}
}
- (void)setLocation:(CLLocation *)newLocation
{
if ([newLocation distanceFromLocation:_location] && newLocation.coordinate.latitude != 0 && newLocation.coordinate.longitude != 0)
... ...

11.8 KB | W: | H:

9.07 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin

26.4 KB | W: | H:

31.4 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -114,6 +114,7 @@
DD5FA1EC15E2B020004EB6C5 /* RMLoadingTileView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD5FA1EA15E2B020004EB6C5 /* RMLoadingTileView.m */; };
DD7C7E38164C894F0021CCA5 /* RMStaticMapView.h in Headers */ = {isa = PBXBuildFile; fileRef = DD7C7E36164C894F0021CCA5 /* RMStaticMapView.h */; settings = {ATTRIBUTES = (Public, ); }; };
DD7C7E39164C894F0021CCA5 /* RMStaticMapView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7C7E37164C894F0021CCA5 /* RMStaticMapView.m */; };
DD7ED619179DC1780022E1E1 /* CoreImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD7ED618179DC1780022E1E1 /* CoreImage.framework */; };
DD8CDB4A14E0507100B73EB9 /* RMMapQuestOSMSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DD8CDB4814E0507100B73EB9 /* RMMapQuestOSMSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD8CDB4B14E0507100B73EB9 /* RMMapQuestOSMSource.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8CDB4914E0507100B73EB9 /* RMMapQuestOSMSource.m */; };
DD8FD7541559E4A40044D96F /* RMUserLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = DD8FD7521559E4A40044D96F /* RMUserLocation.h */; settings = {ATTRIBUTES = (Public, ); }; };
... ... @@ -286,6 +287,7 @@
DD6A83751644A20C0097F31F /* MapBox.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapBox.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
DD7C7E36164C894F0021CCA5 /* RMStaticMapView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMStaticMapView.h; sourceTree = "<group>"; };
DD7C7E37164C894F0021CCA5 /* RMStaticMapView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMStaticMapView.m; sourceTree = "<group>"; };
DD7ED618179DC1780022E1E1 /* CoreImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreImage.framework; path = System/Library/Frameworks/CoreImage.framework; sourceTree = SDKROOT; };
DD8CDB4814E0507100B73EB9 /* RMMapQuestOSMSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMapQuestOSMSource.h; sourceTree = "<group>"; };
DD8CDB4914E0507100B73EB9 /* RMMapQuestOSMSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMapQuestOSMSource.m; sourceTree = "<group>"; };
DD8FD7521559E4A40044D96F /* RMUserLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMUserLocation.h; sourceTree = "<group>"; };
... ... @@ -343,6 +345,7 @@
files = (
B8C974500E8A19B2007D16AD /* CoreFoundation.framework in Frameworks */,
B8C974510E8A19B2007D16AD /* CoreGraphics.framework in Frameworks */,
DD7ED619179DC1780022E1E1 /* CoreImage.framework in Frameworks */,
B8C974520E8A19B2007D16AD /* CoreLocation.framework in Frameworks */,
B8C974530E8A19B2007D16AD /* UIKit.framework in Frameworks */,
B8C974540E8A19B2007D16AD /* QuartzCore.framework in Frameworks */,
... ... @@ -424,6 +427,7 @@
children = (
B83E65590E80E7EB001663B6 /* CoreFoundation.framework */,
288765A40DF7441C002DB57D /* CoreGraphics.framework */,
DD7ED618179DC1780022E1E1 /* CoreImage.framework */,
B83E65630E80E81C001663B6 /* CoreLocation.framework */,
1D30AB110D05D00D00671497 /* Foundation.framework */,
B83E65680E80E830001663B6 /* QuartzCore.framework */,
... ...