Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:13:57+00:00 2026-06-12T20:13:57+00:00

I’m having an issue with both a custom MKOverlayView and standard MKPolygonView being clipped

  • 0

I’m having an issue with both a custom MKOverlayView and standard MKPolygonView being clipped at certain zoom levels when there are multiple overlays added to a map.

The overlay of Algeria at two double tap zoom level.

The overlay of Algeria at three double tap zoom level. Note the clipping.

A few observations:

  • This occurs regardless of whether or not I use a custom MKOverlayView or return an MKPolygonView with the same polygons.
  • If I only draw one overlay, this problem does not occur.
  • This does not occur for all overlays – only some.

As far as code goes: this adds the overlay to an NSMutableArray (borderOverlays), which is then accessed elsewhere to load the overlay for a specific country ID. minX/minY/maxX/maxY are latitude/longitude values; polygon is a path constructed from an ESRI shapefile.

CLLocationCoordinate2D mbrMin = CLLocationCoordinate2DMake(minY, minX);
CLLocationCoordinate2D mbrMax = CLLocationCoordinate2DMake(maxY, maxX);
MKMapPoint minPoint = MKMapPointForCoordinate(mbrMin);
MKMapPoint maxPoint = MKMapPointForCoordinate(mbrMax);
MKMapSize size = MKMapSizeMake(maxPoint.x - minPoint.x, maxPoint.y - minPoint.y);
MKMapRect rect = MKMapRectMake(minPoint.x, minPoint.y, size.width, size.height);

if ( spans180 ) {
    rect = MKMapRectMake(minPoint.x, minPoint.y, MKMapSizeWorld.width * 2, size.height);
}

CustomMKOverlay* overlay = [[CustomMKOverlay alloc] initWithPolygon:polygon withBoundingMapRect:rect];
[borderOverlays addObject:overlay];

The overlay is added to the map via:

[mapView addOverlay:overlay];

viewForOverlay:

- (MKOverlayView *)mapView:(MKMapView*)aMapView viewForOverlay:(id<MKOverlay>)overlay
{
    if ( [overlay isKindOfClass:[CustomMKOverlay class]] ) {
        /* Note: the behaviour if this chunk is not commented is the exact same as below. 
        CustomMKOverlayView* overlayView = [[[CustomMKOverlayView alloc] initWithOverlay:overlay withMapView:aMapView] autorelease];
        [borderViews addObject:overlayView];
        return overlayView; */

        MKPolygonView* view = [[[MKPolygonView alloc] initWithPolygon:((CustomMKOverlay*)overlay).polygon] autorelease];
        view.fillColor = [((CustomMKOverlay*)overlay).colour colorWithAlphaComponent:0.5f];
        view.lineWidth = 5.0f;
        view.strokeColor = [UIColor blackColor];
        [borderViews addObject:view];
        return view;
    }
}

When MKPolygonView is used, there is no drawing code (the example shown). For completion’s sake, though, here’s my custom drawing code, and the same issue occurs. The outlines normally draw – this is actually debugging drawing, which draws a rect around the boundingMapRect of the overlay and fills it without mucking around with the outlines.

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{    
    CustomMKOverlay* overlay = (CustomMKOverlay*)self.overlay;

    CGRect clipRect = [self rectForMapRect:overlay.boundingMapRect];
    CGContextAddRect(context, clipRect);
    CGContextClip(context);

    UIColor* colour = [UIColor redColor];
    colour = [colour colorWithAlphaComponent:0.5f];
    CGContextSetFillColorWithColor(context, [colour CGColor]);
    CGRect fillRect = [self rectForMapRect:overlay.boundingMapRect];
    CGContextFillRect(context, fillRect);
}

Suffice to say, I’m a bit stumped at this point – it’s almost as if the zoomed tiled that’s being loaded draws over the overlay. I’ve poured over various examples regarding TileMap and HazardMap, but as I am not loading my own map tiles, they’re not very helpful.

I’m probably missing something painfully obvious. Any help would be appreciated. I’m happy to provide more code/context if necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:13:58+00:00Added an answer on June 12, 2026 at 8:13 pm

    It would appear that the culprit is:

    CLLocationCoordinate2D mbrMin = CLLocationCoordinate2DMake(minY, minX);
    CLLocationCoordinate2D mbrMax = CLLocationCoordinate2DMake(maxY, maxX);
    

    Bounding rectangles for MKOverlays apparently need to be based on the northwest/southeast coordinates of the bounding region, and not southwest/northeast (which is the format the ESRI shapefile stores its bounding coordinates in). Changing the offending code to:

    CLLocationCoordinate2D mbrMin = CLLocationCoordinate2DMake(maxY, minX);
    CLLocationCoordinate2D mbrMax = CLLocationCoordinate2DMake(minY, maxX);
    

    Appears to resolve all issues with zooming and strange outline anomalies. I hope this helps anyone who comes across this problem in the future (and I’d like to hear about it if it doesn’t, since this solution works a treat for me).

    Also: if anyone can point to any documentation that states this, I’d like to see it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I know there's a lot of other questions out there that deal with this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am writing an app with both english and french support. The app requests
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.