Hello all,
I am developing an iOS app which retrieves tiles from a 3-rd party tile server to overlay on Apple Maps using MapKit. My project uses SwfitUI.
What is the best way to switch seamlessly between different overlays without having a long blink/ loading between two panels on a map. My initial instinct is to cache the map, but I have not been able to get this to work correctly. Any help is greatly appreciated.
Here is my current code which renders the map view:
If you need anything else, let me know!
I am developing an iOS app which retrieves tiles from a 3-rd party tile server to overlay on Apple Maps using MapKit. My project uses SwfitUI.
What is the best way to switch seamlessly between different overlays without having a long blink/ loading between two panels on a map. My initial instinct is to cache the map, but I have not been able to get this to work correctly. Any help is greatly appreciated.
Here is my current code which renders the map view:
Code Block swift struct RadarMapView: UIViewRepresentable { var mapStyle: MKMapType var overlay: MKTileOverlay class Coordinator: NSObject, MKMapViewDelegate { var parent: RadarMapView init(_ parent: RadarMapView) { self.parent = parent } func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { let renderer = MKTileOverlayRenderer(overlay: overlay) return renderer } } func makeCoordinator() -> Coordinator { Coordinator(self) } func makeUIView(context: Context) -> MKMapView { return MKMapView() } func updateUIView(_ mapView: MKMapView, context: Context) { // var template = "https://tile.openstreetmap.org/{z}/{x}/{y}.png" //1600626600 mapView.mapType = self.mapStyle mapView.delegate = context.coordinator let overlays = mapView.overlays mapView.addOverlay(overlay) for overlay in overlays { // remove all MKPolyline-Overlays if overlay is MKTileOverlay { mapView.removeOverlay(overlay) } } } }
If you need anything else, let me know!