ribl / fbannotationclusteringswift Goto Github PK
View Code? Open in Web Editor NEWSwift translation of FB Annotation Clustering, which clusters pins on the map for iOS.
License: MIT License
Swift translation of FB Annotation Clustering, which clusters pins on the map for iOS.
License: MIT License
Hi,
Does anybody know how to set minimum amount of pins which being clustered.
In other words, sometimes, i have cluster with only 2 pins in it, how to change a code in the way which will make a cluster with min 5 pins inside. Thanks everyone in advance.
How can I have an annotation exception? Like, a search pin annotation representation between places annotations. Currently, they all become a cluster, I want just the places to become a cluster. Adding the Search Pin Annotation to the mapView directly is not working(not appearing).
How do I specify the distance needed for annotations to merge into a cluster? For example, I have an annotation in Chicago and a cluster annotation of two in Texas. When I zoom out completely, they both merge and create a cluster of three over Texas. However, I don't want annotations at that distance to merge. Any Ideas?
Because of the ClusteringManager's delegate, the ViewController that contains the map with the clustering view cannot get freed from the the memory. Easy solution: set the delegate to nil once You no longer want to use the clusteringManager. I'd recommend to have this added to the usage steps.
Hi
My app every time the user scrolls the map gets lats,longs from my server and add new annotations to the map, so my question is can I use this library with dynamic annotations? I thought that I can somehow empty clusteringManager.
Thanks in advance.
Please help me out in resolving these two issues.
Hi,
When I use our lib, cluster displays a wrong number because it counts subclusters as one annotation instead of a cluster.
For instance, when I have a cluster A indicating "2" ans one annotation B, when unzooming, the annotations well disappears (I commented the lines indicated in #42) but the new cluster C still indicates 2. I tried with more clusters and annotations ant it seems that it counts each cluster for 1 annotation. So in my case, when my cluster A and the annotation B are grouped in cluster C, C displays 2 instead of 3.
Any tips to fix this ?
Thanks.
If I have annotations at the same map coordinates and I expand the map at maximum zoom level, those annotations remain into a FBAnnotationCluster and are not visible as single annotations.
Is there a way to allow displaying single annotations at maximum zoom level? @chenr2
hi
I am using this for clustering the locations, it works great, But i want to set the set location on loading the map. But it tends to full zoom out cluster view. i want how to set the initial location to current location and then i want to show the cluster only on zoom out and the zoom in.
Hi, first of all, I love your work.
I want to know if there's a way not to decluster when they are really close to each other(coordinate-wise). I'm thinking of manipulating the zoom scale somehow but i'm not sure how to go about it. Any clues would be really really appreciated. Thanks!
Edit: it was a bug in my own code. This issue can be removed.
I have found that if I try to repopulate my map, it doesnt erase the pins that are already there. Is there a clear() function or something of the sort that just wipes the map and starts over?
In its current implementation, setting the FBClusteringManager delegate to a class that references the FBClusteringManager class (e.g., clusteringManager.delegate = self
in the ViewController that displays the map) causes a retain cycle. Setting the delegate to a weak var and the delegate protocol to a class-protocol fixes the issue.
Is there an expected date at which this will be coded in Swift 3?
Hi,
i want to remove all the annotation from my mapView and then according to filter add a new ones.
"arrOfPinsOnMap.removeAll()"
Will hide them, but soon as i move with map they will show again because of "displayAnnotations"
is there a way to achieve what i want?
Is there anyway to have the pins and clusters display when the map loads? It looks like the map is empty until the users pans/zooms, then they appear.
Hi, we had to finally update to Xcode 8.1 from 7.3.1 which now we are facing a big pain in dealing with the pods we are using and the fact that some of them are not updated for the proper syntax.
Here is what Im seeing so far..
Any ideas how to get around this.. we prefer to migrate all to 3, and not 2.3 for our project.
Hi, Is there an example with google maps? Is it compatible?
I have a long title in pin. Need to adjust
let mapBoundsWidth = Double(self.mapView.bounds.size.width)
let mapRectWidth:Double = self.mapView.visibleMapRect.size.width
let scale:Double = mapBoundsWidth / mapRectWidth
let annotationArray = self.clusteringManager.clusteredAnnotationsWithinMapRect(self.mapView.visibleMapRect, withZoomScale:scale)
Thanks for respond :-)
I didn't know how to inform you guys other than creating a new issue: i've started to refactor the code of this repo to use it in a project of mine. Along the way i decided to put the refactored version in a new repo instead of creating a fork and a pull request.
So in case anyone is interested, here's my version:
AnnotationClustering
Note: i use only Carthage for package management, so i dropped CocoaPod support.
Hi,
Is there an option to remove the white border of a cluster or change the color of it?
Thx!
In the didSelectAnnotationView method I have this code:
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
mapView.deselectAnnotation(view.annotation, animated: true)
if view.annotation!.isKindOfClass(FBAnnotationCluster) {
print("cluster selected")
} else {
if !(view.annotation is MKUserLocation) {
print("single pin selected")
}
else{
print("MKUSERLOCATION selected")
}
}
}
now the problem is when user zooms out the map and cluster is in the same location as user's default location. Then, when I touch the cluster, instead of seeing "cluster selected" I see "MKUSERLOCATION selected". Is there any way of completely ignoring mkuserlocation selection and select cluster then?
This happens of course when I'm displaying user's location:
mapView.showsUserLocation = true
How can I change image annotation dynamically base on annotation status?
Like.
First start annotation status = 0 = image "A"
After some period of time annotation status = 1 = image "B"
Thank you
Is there a possibility we could transition this to Swift 2?
Thanks for the Swift translation.
Is there any possibility to set a max zoom level for the clustering? If I achieve zoom level 14, I would like to see all annotations without clusters.
My annotations will merge and un-merge as I zoom out creating a kind of glitchy looking display. Ideally, I'd like the annotations that are within a cluster to remain there as the map zooms out. I've messed with several different variable on the FBClusteringManager's "FBZoomScaleToZoomLevel" switch statement with no luck. Below is what I have to display annotations on the map on my viewcontroller:
func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
let array: [MKAnnotation] = self.createAnnotationsForVideos(self.mapVideos)
self.clusteringManager.addAnnotations(array)
let mapBoundsWidth = Double(self.mapView.bounds.size.width)
let mapRectWidth: Double = self.mapView.visibleMapRect.size.width
let scale: Double = mapBoundsWidth / mapRectWidth
let annotationArray = self.clusteringManager.clusteredAnnotationsWithinMapRect(self.mapView.visibleMapRect, withZoomScale: scale)
self.clusteringManager.displayAnnotations(annotationArray, onMapView: self.mapView)
}
I have some trouble using UIgesture recognizer and this project
the pins disappear instantly when I drop them.
when I remove animated on viewdidload, I can drop them but they will disappear when I zoom out or in and the cluster is not doing his job too when i'm doing a UIgesture Recognizer.
What I'm doing wrong ?
The library is set to ios 9. Now she works only for ios9 on? this is due to an error?
Is there a way to get an array of coordinates when a user taps on one of the map view annotations, Cluster or not? I'm trying to figure it out since you don't have it documented.
Thanks again.
I didn't find any methods in clusteringManager to remove all annotations. Is there any ways to do this?
Hi, I found the problem:
I'm trying to map the 3600 points.
In proetsesse job application takes off on error
Functions "FBZoomScaleToZoomLevel"
The text of the error: "fatal error: floating point value can not be converted to Int because it is either infinite or Nan"
Line 169
File "FBClusteringManager.swift".
I noticed that this error is presented not every time, sometimes the point of time will be displayed correctly.
What could be the problem?
Thank you
Whenever I zoom in or out the Clusters recalculate where they should be but there is major flashing going on while they do this. All the annotations flash on and off the screen. This would be a really bad experience for the users. Do you have any suggestions on how to fix this? Thanks!
I need to customize pin's images, so I have to use MKAnnotationView, not MKPinAnnotationView. But MKAnnotationView is always displayed as cluster. Here is my viewForAnnotation method:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isKindOfClass(FBAnnotationCluster) {
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier("pin")
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: "pin")
return clusterView
} else if annotation.isKindOfClass(MKUserLocation) {
return nil
} else {
let anno = annotation as! StatusPin
let pin = mapView.dequeueReusableAnnotationViewWithIdentifier("pin") ?? MKAnnotationView(annotation: anno, reuseIdentifier: "pin")
if let infoView = StatusView.instanceFromNib() as? StatusView {
infoView.status.text = anno.subtitle!
pin.detailCalloutAccessoryView = infoView
}
pin.image = UIImage(named: "pinIcon")
pin.canShowCallout = true
return pin
}
}
Swift types are automatically namespaced by the module that contains them so the FB class prefix is a bit useless. Is it ok if I PR a version with those prefixes removed?
In your example app in mapView(, viewForAnnotation: ) you dequeue your clusterView but then create a new one
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId)
I could be wrong, but pretty sure you shouldn't be reinstanciating after dequeuing it.
Heres how I dequeue your clusterView which seems to be working well:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if let fbAnnotation = annotation as? FBAnnotationCluster {
var reuseId = "Cluster"
var clusterView: FBAnnotationClusterView?
if let dequeuedClusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? FBAnnotationClusterView {
clusterView = dequeuedClusterView
}
if clusterView == nil {
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId)
}
else {
clusterView!.annotation = fbAnnotation
clusterView!.setTheCount(fbAnnotation.annotations.count)
}
return clusterView
}
}
Hi
I'm trying to zoom in when the user taps on a cluster annotation, and now I did that I want to zoom in differently depends on how many annotations does the cluster annotation that I tapped has clustered.
Thanks in advance
Im using your library in an iOS 8.0 project but get and error when trying to move to cocoa pods
My pod file has "platform :ios, '8.0'"
[!] Unable to satisfy the following requirements:
- `FBAnnotationClusteringSwift` required by `Podfile`
Specs satisfying the `FBAnnotationClusteringSwift` dependency were found, but they required a higher minimum deployment target.
Not exactly sure what causes this - maybe you need: s.ios.deployment_target = '8.0'...
I have a project where I use this and I can't use Swift 2.2, and I can't use Swift 3.0. So I need to use 2.3, but this does not have the support for it.
I would appreciate so much if someone could add support for 2.3. I've got it running on 2.3 by commenting out some small changes, but I have no idea if the changes are legit.
Hi,
I have an issue with select detection. It work with clusters and phone location pin but not with simple pins (added in cluster manager but not in cluster). I think I made a mistake, so I tested against you exemple and it fail too :
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView)
{
print("Selected annotation")
}
-> log only for user location pin and clusters
and/or :
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
{
if annotation.isKindOfClass(FBAnnotationCluster)
{
reuseId = "Cluster"
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId, options: nil)
clusterView?.canShowCallout = true
return clusterView
}
else
{
reuseId = "Pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.pinTintColor = UIColor.blueColor()
pinView!.canShowCallout = true
return pinView
}
}
-> show callout only for cluster and user location pin but pins are blue so they've been affected by the code
I'd like to make the cluster have a wider reach so that if say I have a bunch of images on a map at a particular size say 50 CGPoints square I'd like them to group into clusters as opposed to overlapping. currently they overlap for that big of an annotation.
Thanks again
From pod install, i get versions 1.0.1
Which is wrong because in your example you have completely different files.
Hi,
First off all, I love this pod. It works extremely well. I do have a question. What I would like to do, is toggle groups of annotations on and off. So for instance, we have 3 different annotation groups. One group has hotels, the other has stadions, and yet another holds bars. I would like to switch those different groups on and off, without rebuilding the annotations. Is this possible?
How i can set custom image as pin and how can i change default green color?
Annotation count is no updated if a cluster merge with a pin
First thank you @chenr2 for your work. I wouldn't have been able to translate this wonderful library by myself.
Unfortunately I am facing an issue that is somewhat common in the objective-c version: reusing the current cluster. A solution has been posted here infinum/FBAnnotationClustering#2 but I am not able to translate it in swift. Does anyone know how to do it?
Thank you very much.
Hi,
I am using this framework and i loved it. I want to hide the cluster count when did full zoom out. Actually when more than one device in same position , i want to hide cluster count in full zoom out . Is this any way to do that.
I have added all 7 swift files manually and added the FBViewController file. When I run it there is no annotations and no clustering.
Regardless the amount of zoom I apply on the map, the clusters never "explode" into pins. I am using the latest version of FBAnnotationClusteringSwift, and my code pretty much looks like what is in example code.
However, the images bellow show the progression of the clusters as I zoom in on the map, reaching the maximum zoom actually increased the size of the cluster inside the visible region:
What is likely to be this problem? Where I should look into my code to narrow down this problem. For information, I am using the Xcode Simulator to run the app.
Thank you for any suggestion or comment on that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.