I have tiles stored locally on device and I'm loading them with the following code
override func url(forTilePath path: MKTileOverlayPath) -> URL {
let tilePath = Bundle.main.url(
forResource: "\(path.y)",
withExtension: "png",
subdirectory: "tiles/\(path.z)/\(path.x)",
localization: nil)
if let tile = tilePath {
return tile
} else {
return Bundle.main.url(
forResource: "empty",
withExtension: "png",
subdirectory: "tiles",
localization: nil)!
}
}
I create a MKTileOverlayRenderer in my viewModel
let overlay = TileOverlay()
overlay.canReplaceMapContent = true
overlay.minimumZ = 13
overlay.maximumZ = 16
tileRenderer = MKTileOverlayRenderer(tileOverlay: overlay)
And add that overlay in viewDidLoad of my ViewController to the mapView
mapView.addOverlay(viewModel.tileRenderer.overlay, level: .aboveLabels)
This calls my delegate method rendererFor overlay:
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
return viewModel.tileRenderer
}
I only have a small sample of tiles, 17MB, however there is a lag when zooming in and out and even sometimes on initial load of the overlay. I've even restricted the mapView boundary with MKMapView.CameraBoundary and zoom with MKMapView.CameraZoomRange.
How can I prevent this lag?
I'm using a Simulator: iPhone11, iOS 13.5