【问题标题】:Add an image to a custom MGLAnnotationView in MapBox将图像添加到 MapBox 中的自定义 MGLAnnotationView
【发布时间】:2020-01-31 01:23:36
【问题描述】:

我想将图像添加到 MGLAnnotationView。我使用 Assets.xcassets 文件夹中的图像没有问题,但是当我尝试从图像数组中添加时,我似乎无法弄清楚。

我尝试将“withIdentifier”设置为图像的名称,但没有成功

如果有人可以帮助我,那就太好了!

这是我的代码:

//图像数组

var images: [UIImage] = []

//创建注释图像的函数:

func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
    let annotationImage: MGLAnnotationImage

    let annotationImage = mapView.dequeueReusableAnnotationImage(withIdentifier: "camera")

    annotationImage = annotationImage ?? MGLAnnotationImage(image: UIImage(named: "camera")!, reuseIdentifier: "camera")

    return annotationImage
}

【问题讨论】:

    标签: ios swift xcode mapbox


    【解决方案1】:

    我已经解决了这个问题:

    相当简单的解决方案

    let img = images[0]
    
    annotationImage = annotationImage ?? MGLAnnotationImage(image: img, reuseIdentifier: names[0])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 2012-10-01
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多