Posts

Post not yet marked as solved
0 Replies
815 Views
Hi I need Help I do control Apple Map I want overlay image on map I use MKOverlayRenderer and this function override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in context: CGContext) and then success overlay but map zoom level 2.0 over than image broken if not use CGContext.rotate then image are not broken but use rotate then image are broken class IndoorInfoOverlay: NSObject, MKOverlay { let coordinate: CLLocationCoordinate2D let boundingMapRect: MKMapRect init(indoorInfo: IndoorInfo) { boundingMapRect = indoorInfo.overlayBoundingMapRect coordinate = indoorInfo.midCoordinate } } class IndoorInfoOverlayView: MKOverlayRenderer { var overlayImage: UIImage var parent: IndoorMapView init(overlay: MKOverlay, overlayImage: UIImage,_ parent: IndoorMapView) { self.overlayImage = overlayImage self.parent = parent super.init(overlay: overlay) } override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in context: CGContext) { guard let imageReference = overlayImage.cgImage else { return } let bearing = degreesToRadians(360 - (Double(self.parent.floorData!.FLOOR_BEARING) ?? 0)) let rect = self.rect(for: overlay.boundingMapRect) context.scaleBy(x: 1.0, y: -1.0) context.translateBy(x: 0.0, y: -rect.size.height) if self.parent.floorData != nil { context.rotate(by: bearing) } context.draw(imageReference, in: rect, byTiling: false) } private func degreesToRadians(_ x:Double) -> Double { return (Double.pi * x / 180.0) } }````
Posted Last updated
.