Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. func mapView(_ map: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
  2.  
  3. if (annotation is MKUserLocation) {
  4.  
  5. return nil
  6. }
  7.  
  8. let identifier = "pinAnnotation"
  9.  
  10.  
  11. // In particular I am not sure what the code below does
  12.  
  13. if let pin = annotation as? ColorPointAnnotation {
  14.  
  15.  
  16. if let view = map.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKPinAnnotationView {
  17. view.annotation = annotation
  18. view.pinTintColor = pin.color ?? .purple
  19.  
  20. return view
  21.  
  22. } else {
  23.  
  24. let view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
  25. view.isEnabled = true
  26.  
  27. view.canShowCallout = true
  28.  
  29. view.pinTintColor = pin.color ?? .purple
  30.  
  31. let btn = UIButton(type: .detailDisclosure)
  32. view.rightCalloutAccessoryView = btn
  33.  
  34.  
  35. if view.pinTintColor == .red || view.pinTintColor == .green {
  36. let button = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
  37. button.setBackgroundImage(UIImage(named: "car"), for: .normal)
  38. button.addTarget(self, action: #selector(MapVC.getDirections), for: .touchUpInside)
  39. view.leftCalloutAccessoryView = button
  40. } else {
  41. let button = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
  42. button.setBackgroundImage(UIImage(named: "other"), for: .normal)
  43. button.addTarget(self, action: #selector(MapVC.other), for: .touchUpInside)
  44. view.leftCalloutAccessoryView = button
  45. }
  46.  
  47. return view
  48. }
  49. }
  50.  
  51. if let annotationView = map.dequeueReusableAnnotationView(withIdentifier: identifier) {
  52. annotationView.annotation = annotation
  53. return annotationView
  54. } else {
  55. let annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier: identifier)
  56. annotationView.isEnabled = true
  57. annotationView.canShowCallout = true
  58.  
  59. let btn = UIButton(type: .detailDisclosure)
  60. annotationView.rightCalloutAccessoryView = btn
  61.  
  62. if annotationView.pinTintColor == .red || annotationView.pinTintColor == .green {
  63.  
  64. let smallSquare = CGSize(width: 120, height: 120)
  65. let button = UIButton(frame: CGRect(origin: CGPoint(x: 0,y :0), size: smallSquare))
  66. button.setBackgroundImage(UIImage(named: "car"), for: .normal)
  67. button.addTarget(self, action: #selector(MapVC.getDirections), for: .touchUpInside)
  68. annotationView.leftCalloutAccessoryView = button
  69. } else {
  70. let button = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
  71. button.setBackgroundImage(UIImage(named: "other"), for: .normal)
  72. button.addTarget(self, action: #selector(MapVC.other), for: .touchUpInside)
  73. annotationView.leftCalloutAccessoryView = button
  74. }
  75.  
  76. return annotationView
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement