Reputation: 43
My app uses the NOAA RNC Chart Tile Service as an overlay for my MKMapView. When downloading each chart QuiltedTileSet, I am able to retrieve the tile set's maximum zoom level (e.g. maximumZ = 21)
func setupTileRenderer() {
template = "https://tileservice.charts.noaa.gov/tiles/50000_1/{z}/{x}/{y}.png"
let overlay = MKTileOverlay(urlTemplate: template)
print("overlay template max zoom is : \(String(describing: overlay.maximumZ))")
overlay.canReplaceMapContent = true
mapView.addOverlay(overlay, level: .aboveRoads)
tileRenderer = MKTileOverlayRenderer(tileOverlay: overlay)
}
Understandably, when the user tries to zoom in beyond the maximumZ level, the charts will not render.
I want to programmatically restrict the user from zooming in past the maximumZ, and have implemented an approximation using a minimum distance CameraZoomRange of 3500 (based on trial and error):
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let zoomRange = MKMapView.CameraZoomRange(minCenterCoordinateDistance: 3500)
mapView.setCameraZoomRange(zoomRange, animated: true)
return tileRenderer
}
Since not all tileSets have the same maximumZ, I would like to know if there is a way to interpolate the CameraZoomRange from the maximumZ that is provided by the tileSet?
And, since not all tiles in NOAA's quiltedTileSets actually have the same maximum zoom as the original x y location requested, the z is often less than 21. How do I check for the maximumZ as the user pans, and how would I modify the CameraZoomRange minimum distance to accommodate this new value?
All of the older solutions I have been able to find use MKCoordinateSpan to calculate the maximumZ, and do not use iOS13's CameraZoomRange (e.g. Is there way to limit MKMapView maximum zoom level?)
Upvotes: 2
Views: 386