Using MKTileOverlay and MKPolyLine lose tiles at zoom.

If I have a mapview with a tileoverlay and polyline, the view works until I zoom in close. When zoomed in, the tiles under the polyline don't render, but other tiles not under the polyline do. Xcode 7.3.1 targeting ios 9.3.


Below is the minimal test case I have come up with to show this. Any ideas how to debug further? If I remove the polyline overlay, zoom works perfectly fine for all tiles.


class MyController: UIViewController, MKMapViewDelegate {
    @IBOutlet weak var mapView: MKMapView!
    var overlay:MKTileOverlay = MKTileOverlay(URLTemplate: "https://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer/tile/{z}/{y}/{x}.jpg");

    override func viewDidLoad() {
        mapView.delegate = self
        mapView.showsUserLocation = true;
        overlay.maximumZ = 15;
        overlay.minimumZ = 12;
        overlay.canReplaceMapContent = true
        mapView.addOverlay(overlay);

        var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]()

        points.append(CLLocationCoordinate2D(latitude: 40.7608, longitude: -111.8910));
        points.append(CLLocationCoordinate2D(latitude: 40.8894, longitude: -111.8808));

        var polyline = MKPolyline(coordinates: &points, count: points.count)
        mapView.addOverlay(polyline)
        let region = MKCoordinateRegion(center: points[0], span: MKCoordinateSpan(latitudeDelta:  0.05, longitudeDelta:  0.05))
        mapView.setRegion(region, animated: false)
    }


    func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
        if overlay is MKPolyline {
            var polylineRenderer = MKPolylineRenderer(overlay: overlay)
            polylineRenderer.strokeColor = UIColor.blueColor()
            polylineRenderer.lineWidth = 5
            return polylineRenderer
        } else if (overlay is MKTileOverlay) {
            let renderr = MKTileOverlayRenderer(overlay: overlay)
            return renderr
        }

        return nil
    }

}

Replies

Did you find any solution for this?? I'm facing a similar issue.

I've added an overlay layer in MKMapView, and I'm loading custom tiles from a URL in the loadTile(at path:) method. everything works fine, and I received success responses in every case(initial view or on zoom) and the custom overlay rendered correctly.

However, I encountered an issue after adding the line mapView.setRegion(region, animated: true) to set the initial map region. After doing this, I receive a 400 error in response of loading overlay in loadTile(at path:) when zooming on the map, and the custom tiles fail to load.

Is there something wrong with the setRegion method, or could there be another reason for this issue?