如何解决我看不到添加的注释它出什么问题了?
我不知道为什么不显示标记。
我正在使用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 举报,一经查实,本站将立刻删除。