Created
September 8, 2011 18:31
-
-
Save pmark/1204201 to your computer and use it in GitHub Desktop.
How to scale a 3DAR point view with distance from user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code belongs in a custom point/marker view class. | |
// | |
// Calculate this view's size scale based on distance from user's current location. | |
// | |
- (CGFloat) rangeScale | |
{ | |
CGFloat scale = 1.0; | |
if (self.poi) | |
{ | |
CGFloat poiDistance = [self.poi distanceInMetersFromCurrentLocation]; | |
CGFloat minRange = 0.0; | |
CGFloat maxRange = 10000.0; | |
CGFloat minScaleFactor = 0.1; | |
if (poiDistance > maxRange || poiDistance < minRange) | |
{ | |
scale = minScaleFactor; | |
} | |
else | |
{ | |
CGFloat scaleFactor = 1.0; | |
CGFloat rangeU = (poiDistance - minRange) / (maxRange - minRange); | |
scale = scaleFactor * (1.0 - ((1.0 - minScaleFactor) * rangeU)); | |
} | |
} | |
return scale; | |
} | |
// | |
// A point view's pointTransform is automatically applied for each visible point. | |
// | |
- (CGAffineTransform) pointTransform | |
{ | |
CGFloat scale = [self rangeScale]; | |
return CGAffineTransformMakeScale(scale, scale); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment