efremidze / Cluster

Easy Map Annotation Clustering 📍
MIT License
1.28k stars 121 forks source link

on .reload method call map view region changed. #50

Closed Premal-Khetani closed 7 years ago

Premal-Khetani commented 7 years ago

Hi, It's great lib and i would like to thank you for making it easier.

Here i am facing one issue regarding the selecting annotation. When i select annotation the map is changed it's region. you can see in the below gif.

There are two issues

1) as you can see thay the zoom level of the map is so that both end (left and right) pin is cut. i tried a lot but when ever i reload the cluster it always gives me this result. You can see it in the GIF after stopped progressview.

2) when i tap on diff diff annotations i select the annotation and reload cluster method is called from regionDidChangeAnimated as we need to show that annotation. but this time the map is getting don and down the annotations are changing positions on map and the map moves :(.

Please help me.

Thank you test123

efremidze commented 7 years ago

Hi, both of these issues are not related to the library but issues with maps in general. We can add additional options to the library. 1) Move clusters outside region closer to visible region. 2) Selecting the annotation calls mapView:didSelectView: and if the selected annotation is part of a cluster, set visible region to the cluster instead of the annotation.

I can add a fix to didSelectView quickly. The annotations off screen are a bit more complicated.

Premal-Khetani commented 7 years ago

Thanks for the Quick Reply. Can you please fix it so i can implement it? It would be great for me.

Thanks :)

Premal-Khetani commented 7 years ago

For the showing all pins in visible region i did the bellow code.

let annotationPoint = MKMapPointForCoordinate(annotation.coordinate)
                let pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0)
                if MKMapRectIsNull(zoomRect) {
                    zoomRect = pointRect
                } else {
                    zoomRect = MKMapRectUnion(zoomRect, pointRect)
                }
mapView.setVisibleMapRect(zoomRect, edgePadding: UIEdgeInsetsMake(20, 20, 20, 20), animated: false)

And it works fine to show pins in visible Rect.

Thank you.