I have a MKMapView working with a MKTileOverlay showing tiles from a local database. It's working fine.
Then I used MKDirections to get direction between two coordinates and draw the route like that :
MKRoute *route = response.routes.lastObject;
MKPolyline *polyline = route.polyline;
// Draw path on overlay
[self.mapView insertOverlay:polyline aboveOverlay:self.tileOverlay];
But when I zoom to see the line, it appears without the tile background (normaly loaded from MKTileOverlay (stored into self.tileOverlay)). I joined an image to see better.
I also made this code to render overlays :
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
else if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolylineRenderer *lineView = [[MKPolylineRenderer alloc] initWithOverlay:overlay];
lineView.strokeColor = [UIColor greenColor];
lineView.lineWidth = 3;
return lineView;
}
return nil;
}
It's like the "tile" that render the line hide the tile loaded from the MKTileOverlay. How can I :
- specify that I the MKPolyline overlay must be transparent ?
- reload the background tile ?
Screeshot :
See the tile with line has no background anymore http://sigmanet.ch/tmp/screen.png
After days of work, here is my own solution.
Extend
MKPolylineRendererand add a reference to theMKTileOverlayRenderer. Let's call this new classMCPolylineRenderer.In this class, override this two methods :
Now, in the
mapView:renderedForOverlaymethod, replacewith
Also, you need to be sure that the
loadTileAtPath:result:method doesn't result a tile when there is nothing to render (like a "tile not found" image).This code will have effect that when there is no background tile to render, the path won't be draw neither.