我看不到添加的注释它出什么问题了?

问题描述

我不知道为什么不显示标记

我正在使用MapBox 6.0.0版

annotationView类

// Create a subclass of MgluserLocationAnnotationView.
class CustomUserLocationAnnotationView: MGLAnnotationView {
    var imageView: UIImageView!
    
    init(user: User) {
        super.init(reuseIdentifier: user.userId)
        print(">:> identifier : \(user.userId)")
        
        self.imageView = UIImageView(frame: CGRect(x: -10,y: -10,width: 30,height: 30))
        self.imageView.layer.cornerRadius = imageView.frame.height / 2
        self.imageView.clipsToBounds = true
        self.imageView.image = UIImage(named: user.userProfileThumbnail ?? "profile")
        self.addSubview(self.imageView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
}

}

注释覆盖方法

func mapView(_ mapView: MGLMapView,viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
    guard annotation is MGLPointAnnotation,let wrapTitle = annotation.title,let title = wrapTitle else {
        return nil
    }
    
    if let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: title) {
        print(">:> \(title)")
        return annotationView
    } else {
        let view = CustomUserLocationAnnotationView(user: self.allUser[title]!)
        self.annotationViews.append(view)
        return view
    }
}

添加注释

private func reloadAnnotationView() {
    var pointAnnotations = [MGLPointAnnotation]()
    
    for user in allUser {
        let point = MGLPointAnnotation()
        point.coordinate = user.value.userLocation
        point.title = user.value.userId
        pointAnnotations.append(point)
    }
    
    print(">:> add annotation size \(pointAnnotations.count)")
    
    self.mapView?.addAnnotations(pointAnnotations)
}

我该如何解决问题? 看起来您的帖子大部分是代码;请添加更多详细信息。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)