Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
  2. {
  3. if annotation is MKUserLocation
  4. {
  5. return nil
  6. }
  7.  
  8.  
  9. let annotationIdentifier = "AnnotationIdentifier"
  10. var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
  11.  
  12. if annotationView == nil {
  13. annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
  14. annotationView!.canShowCallout = false
  15. annotationView!.rightCalloutAccessoryView = UIButton.init(type: UIButtonType.infoLight)
  16. }
  17. else {
  18. annotationView!.annotation = annotation
  19. annotationView!.canShowCallout = false
  20. }
  21.  
  22. if isRequestSelected == true {
  23.  
  24. let pinImage = UIImage(named: "bluePin")
  25. annotationView!.image = pinImage
  26. }
  27. else
  28. {
  29. let pinImage = UIImage(named: "bluePin")
  30. annotationView!.image = pinImage
  31. }
  32.  
  33. if let pointAnnotation = annotationView?.annotation as? CustomMKPointAnnotation {
  34.  
  35.  
  36. if pointAnnotation.isMyProfile {
  37. let pinImage = UIImage(named: "my_location_pin")
  38. annotationView!.image = pinImage
  39. return annotationView
  40. }
  41.  
  42.  
  43. if pointAnnotation.tag == 100 {
  44. let pinImage = UIImage(named: "map_marker")
  45. annotationView!.image = pinImage
  46. }
  47. }
  48.  
  49. annotationView!.canShowCallout = false
  50. annotationView?.addTapGestureRecognizer(action: {
  51. if self.selectedAnnotationView != nil {
  52. for subview in self.selectedAnnotationView!.subviews
  53. {
  54. subview.removeFromSuperview()
  55. }
  56. }
  57. let views = Bundle.main.loadNibNamed("CustomCalloutView", owner: nil, options: nil)
  58. let calloutView = views?[0] as! CustomCalloutView
  59. calloutView.center = CGPoint(x: annotationView!.bounds.size.width / 2, y: -calloutView.bounds.size.height*0.52)
  60.  
  61. self.selectedUserID = (annotationView?.annotation as? CustomMKPointAnnotation)?.userID ?? ""
  62.  
  63. calloutView.nameLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.title
  64.  
  65. calloutView.nameLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.title
  66. calloutView.skillLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.subtitle
  67. calloutView.ratingView.rating = (annotationView?.annotation as? CustomMKPointAnnotation)?.ratings ?? 0.0
  68. calloutView.ratingView.text = "(" + "((annotationView?.annotation as? CustomMKPointAnnotation)!.totalReviews)" + ")"
  69. calloutView.bussinessLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.bussinessName
  70. calloutView.profileImageView.sd_setImage(with: URL(string: (annotationView?.annotation as? CustomMKPointAnnotation)?.profileImage ?? ""), placeholderImage: UIImage(named: "defaultProfile"))
  71. annotationView!.addSubview(calloutView)
  72. mapView.setCenter((annotationView!.annotation?.coordinate)!, animated: true)
  73. self.selectedAnnotationView = annotationView
  74. })
  75. return annotationView
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement