Skip to content

Instantly share code, notes, and snippets.

@incanus
Created June 24, 2011 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incanus/1045095 to your computer and use it in GitHub Desktop.
Save incanus/1045095 to your computer and use it in GitHub Desktop.
constrained override for -[RMMapContents moveBy:] in route-me
- (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