iOS Mapbox图钉(注释)图像以错误的分辨率显示为像素化:(

时间:2018-06-01 15:44:37

标签: ios annotations uiimage mapbox

我无法找到以高分辨率在地图上获取自定义图片图像的方法。 (我说的是MapBox iOS SDK)。

通常,当UIImage大小等于* .png大小时,这可能发生在Xcode中。我已经尝试准备3x scaled * .png文件并调整我的UIImage对象的大小,但仍然在屏幕上获得低分辨率图像。有什么想法吗?

Mapbox SDK for iOS版本4.0.2

当我以前使用标准库MapKit时,相同的图像工作正常(以高分辨率显示)。

enter image description here

解!!!

我能够在以下问题后解决问题:

  1. 将MapBox sdk更新为 v 4.6
  2. x3 大小准备我的自定义图片图片,并使用UIImage的 scale 选项。您应该按以下方式定义自定义图钉图像:
  3. MapBox iOS ImageFor注释方法的完整示例代码是:

    func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
    
        var reuseIdentifier = annotation.title!
    
        // For better performance, always try to reuse existing annotations.
        var annotationImage = mapView.dequeueReusableAnnotationImage(withIdentifier: reuseIdentifier! )
    
        let img = UIImage(named:"pinCustom.png") {
        let scaledUpImage = UIImage(cgImage: img.cgImage!, scale: 3.0, orientation: .up)
        annotationImage = MGLAnnotationImage(image: scaledUpImage, reuseIdentifier: reuseIdentifier! )
    
        return annotationImage
    }
    

0 个答案:

没有答案