MapViewPlus icon indicating copy to clipboard operation
MapViewPlus copied to clipboard

How to stop showing CalloutView on annotation selection?

Open hemangshah opened this issue 6 years ago • 4 comments

I have a scenario for which I don't want to show a CalloutView to be displayed when an annotation will get selected. Instead, I want MapViewPlus to let me know that an annotation has been tapped and I will then show a custom popup on self.view. Is it possible with MapViewPlus?

P.S. I understand that this is not the actual behavior of a MapView itself, however for someways is this will be possible it will be more easy for us to display a map with MapViewPlus while customizing the UI as per our need.

hemangshah avatar Mar 14 '18 09:03 hemangshah

You can do this by hacking things. I will add this to 0.2.0 milestone but currently you can achieve it like below:

1) Define an EmptyView:

class EmptyView: UIView, CalloutViewPlus {
  func configureCallout(_ viewModel: CalloutViewModel) { }
}

2) Return this EmptyView from delegate method when you don't want to show callout view:

func mapView(_ mapView: MapViewPlus, calloutViewFor annotationView: AnnotationViewPlus) -> CalloutViewPlus{

  // calloutCanBeShown is any method to decide if you want to show it or not
  guard calloutCanBeShown() else { return EmptyView() }

  return YourCalloutViewInstance

3) Hide the anchor view like in #2 when you won't show the callout view. So, both callout view and anchor view will be hidden.

@hemangshah

okhanokbay avatar Mar 14 '18 10:03 okhanokbay

Wow! Thanks, @okhanokbay, you're amazing. I believe this should work for me. I will wait for 0.2.0 for all the major changes requires for me. 👍

hemangshah avatar Mar 14 '18 10:03 hemangshah

@okhanokbay, here, how I will get to know that which annotation has been tapped and how to update my view with the correct data?

hemangshah avatar Mar 14 '18 10:03 hemangshah

Fair point. You will be able to do this in 0.2.0. As in the MKMapView, allowing a user to opt-out of showing a callout view for a specific annotation must be included in MapViewPlus. As of MapViewPlus adding a 'plus' by passing the view model to the callout view that conforms to CalloutViewPlus protocol, it also must provide a way to pass this view model to the user's custom view class that doesn't conform to this protocol.

TL;DR -> Please wait for 0.2.0 :) @hemangshah

okhanokbay avatar Mar 16 '18 01:03 okhanokbay