Hi, I'm making the map app to insert a custom MKOverlay. I specified the image in Asset catalog as an image of MKOVerlay. However, the overlay image in the map was reversed vertically as shown in the blow figure.
https://share.icloud.com/photos/0ofoyXKRlJnN_1phqRP79WBrw
I confirmed that the instance of UIImage to be rendered in a map had been created by specifying a correct asset name. The following is a part of the class inherits MKOverlayRenderer. I cannot understand the rotation of the image. Please teach me the reason for this phenomenon.
init(overlay: MKOVerlayWindIcon){
pOverlay = overlay
super.init(overlay: pOverlay)
if let tmpImg = GenerateImage(data: pOverlay.data){
pImageToRender = tmpImg
}else{
os_log(.error, "Failed to generage icon image")
}
}
override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in context: CGContext) {
let rectToRender : CGRect = calcCGRect(for: zoomScale)
if let imageToReder = pImageToRender?.cgImage{
context.draw(imageToReder, in: rectToRender)
}else{
os_log("Invalid image was passed", log: OSLog.default, type: .debug)
}
}
func GenerateImage(data :WindData) -> UIImage?{
let assetName = "WI_337.5"
return UIImage.init(named: assetName)
}
CoreGraphics uses a different coordinate system, so what I meant if you verified the orientation of the image with respect to the coordinate system. Please see the Quartz 2D programming guide for background on these coordinate systems.
With respect to your overlay, a common way to adjust for this is to briefly adjust the graphics context coordinate system:
context?.translateBy(x: 0, y: rect.height)
context?.scaleBy(x: 1.0, y: -1.0)
context?.draw(imageToReder, in: rect)