Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
- {
- if annotation is MKUserLocation
- {
- return nil
- }
- let annotationIdentifier = "AnnotationIdentifier"
- var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
- if annotationView == nil {
- annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
- annotationView!.canShowCallout = false
- annotationView!.rightCalloutAccessoryView = UIButton.init(type: UIButtonType.infoLight)
- }
- else {
- annotationView!.annotation = annotation
- annotationView!.canShowCallout = false
- }
- if isRequestSelected == true {
- let pinImage = UIImage(named: "bluePin")
- annotationView!.image = pinImage
- }
- else
- {
- let pinImage = UIImage(named: "bluePin")
- annotationView!.image = pinImage
- }
- if let pointAnnotation = annotationView?.annotation as? CustomMKPointAnnotation {
- if pointAnnotation.isMyProfile {
- let pinImage = UIImage(named: "my_location_pin")
- annotationView!.image = pinImage
- return annotationView
- }
- if pointAnnotation.tag == 100 {
- let pinImage = UIImage(named: "map_marker")
- annotationView!.image = pinImage
- }
- }
- annotationView!.canShowCallout = false
- annotationView?.addTapGestureRecognizer(action: {
- if self.selectedAnnotationView != nil {
- for subview in self.selectedAnnotationView!.subviews
- {
- subview.removeFromSuperview()
- }
- }
- let views = Bundle.main.loadNibNamed("CustomCalloutView", owner: nil, options: nil)
- let calloutView = views?[0] as! CustomCalloutView
- calloutView.center = CGPoint(x: annotationView!.bounds.size.width / 2, y: -calloutView.bounds.size.height*0.52)
- self.selectedUserID = (annotationView?.annotation as? CustomMKPointAnnotation)?.userID ?? ""
- calloutView.nameLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.title
- calloutView.nameLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.title
- calloutView.skillLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.subtitle
- calloutView.ratingView.rating = (annotationView?.annotation as? CustomMKPointAnnotation)?.ratings ?? 0.0
- calloutView.ratingView.text = "(" + "((annotationView?.annotation as? CustomMKPointAnnotation)!.totalReviews)" + ")"
- calloutView.bussinessLabel.text = (annotationView?.annotation as? CustomMKPointAnnotation)?.bussinessName
- calloutView.profileImageView.sd_setImage(with: URL(string: (annotationView?.annotation as? CustomMKPointAnnotation)?.profileImage ?? ""), placeholderImage: UIImage(named: "defaultProfile"))
- annotationView!.addSubview(calloutView)
- mapView.setCenter((annotationView!.annotation?.coordinate)!, animated: true)
- self.selectedAnnotationView = annotationView
- })
- return annotationView
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement