Created
June 24, 2011 16:07
-
-
Save incanus/1045095 to your computer and use it in GitHub Desktop.
constrained override for -[RMMapContents moveBy:] in route-me
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
- (void)moveBy:(CGSize)delta | |
{ | |
// Adjust delta as necessary to constrain latitude, but not longitude. | |
// | |
// This is largely borrowed from -[RMMapView setConstraintsSW:NE:] and -[RMMapView moveBy:] | |
// | |
RMProjectedRect sourceBounds = [self.mercatorToScreenProjection projectedBounds]; | |
RMProjectedSize XYDelta = [self.mercatorToScreenProjection projectScreenSizeToXY:delta]; | |
CGSize sizeRatio = CGSizeMake(((delta.width == 0) ? 0 : XYDelta.width / delta.width), | |
((delta.height == 0) ? 0 : XYDelta.height / delta.height)); | |
RMProjectedRect destinationBounds = sourceBounds; | |
destinationBounds.origin.northing -= XYDelta.height; | |
destinationBounds.origin.easting -= XYDelta.width; | |
BOOL constrained = NO; | |
RMProjectedPoint SWconstraint = [self.projection latLongToPoint:CLLocationCoordinate2DMake(kLowerLatitudeBounds, 0)]; | |
RMProjectedPoint NEconstraint = [self.projection latLongToPoint:CLLocationCoordinate2DMake(kUpperLatitudeBounds, 0)]; | |
if (destinationBounds.origin.northing < SWconstraint.northing) | |
{ | |
destinationBounds.origin.northing = SWconstraint.northing; | |
constrained = YES; | |
} | |
if (destinationBounds.origin.northing + sourceBounds.size.height > NEconstraint.northing) | |
{ | |
destinationBounds.origin.northing = NEconstraint.northing - destinationBounds.size.height; | |
constrained = YES; | |
} | |
if (constrained) | |
{ | |
XYDelta.height = sourceBounds.origin.northing - destinationBounds.origin.northing; | |
XYDelta.width = sourceBounds.origin.easting - destinationBounds.origin.easting; | |
delta = CGSizeMake(((sizeRatio.width == 0) ? 0 : XYDelta.width / sizeRatio.width), | |
((sizeRatio.height == 0) ? 0 : XYDelta.height / sizeRatio.height)); | |
} | |
[super moveBy:delta]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment