Comments (19)
It would be great to show them all for example in a circle around the location.
from cluster.
same issue here
from cluster.
thanks for reporting this, ill push a fix
from cluster.
what do u prefer, displaying just one annotation there?
from cluster.
issue is 2 annotation in exact place not showing can't zoom its showing the cluster only
from cluster.
It would be awesome to see something like this in this library: https://stackoverflow.com/questions/44698027/correctly-handle-clustering-when-markers-are-placed-identically-and-overlapping
My question was based on Google maps but I switched to AppleMaps and would like to use this library for clustering and would like to be able to make them appear in the circle like in the stackoverflow question.
from cluster.
Thanks Ill fix asap.
from cluster.
That indeed would be a good solution !
from cluster.
Hello and thanks for the fix. I've updated the pod but now when i zoom the Cluster pin dissapears and there is no other regular pins. Can you point me if you changed anything to the example code ?
from cluster.
I'm not seeing any issues. What device, iOS version, etc?
from cluster.
iPhone SE, iOS 10.3.3, Xcode 8.3.3, Swift 3
With the following custom code of mine.
import UIKit
import MapKit
import Cluster
class EventAnnotation : MKPointAnnotation {
var myEvent:Events?
var myRealmEvent:RealmEventNew?
}
extension CGRect{
init(_ x:CGFloat,_ y:CGFloat,_ width:CGFloat,_ height:CGFloat) {
self.init(x:x,y:y,width:width,height:height)
}
}
class ClusterMapViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var eventCount: UILabel!
let manager = ClusterManager()
lazy var events = [Events]()
var add: Double!
var newLat: Double!
var counter = 0
var tileRenderer: MKTileOverlayRenderer!
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: true)
manager.minimumCountForCluster = 3
manager.shouldRemoveInvisibleAnnotations = false
for event in events {
let eventpins = EventAnnotation()
eventpins.myEvent = event // Here we link the event with the annotation
eventpins.title = event.eventName
eventpins.coordinate = CLLocationCoordinate2D(latitude: event.eventLat, longitude: event.eventLon)
manager.add(eventpins)
eventCount.text = "\(events.count) Events Nearby"
}
@IBAction func goToUser(_ sender: Any) {
self.mapView.setUserTrackingMode( MKUserTrackingMode.follow, animated: true)
}
deinit {
print("deinit cluster")
if events.isEmpty == false {
events.removeAll(keepingCapacity: false)
}
mapView.mapType = .standard
mapView.removeFromSuperview()
mapView.delegate = nil
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
{
if overlay is MKTileOverlay
{
let renderer = MKTileOverlayRenderer(overlay:overlay)
renderer.alpha = 0.8
return renderer
}
return MKOverlayRenderer()
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let reuseId:String
switch annotation {
case is MKUserLocation:
return nil // blue pulsy dot
case is ClusterAnnotation:
reuseId = "Cluster"
var clusterView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
clusterView = ClusterAnnotationView.init(annotation: annotation, reuseIdentifier: reuseId, type:.color(UIColor.init(hexString: "#2E294E"), radius: 25))
return clusterView
default:
reuseId = "Pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if pinView != nil {
pinView!.annotation = annotation
} else {
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.image = UIImage.init(named: "pin")
pinView!.canShowCallout = false
}
return pinView
}
}
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
manager.reload(mapView, visibleMapRect: mapView.visibleMapRect)
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else { return }
if view.annotation!.isKind(of: MKUserLocation.self){
return
}
if let cluster = annotation as? ClusterAnnotation {
mapView.removeAnnotations(mapView.annotations)
var zoomRect = MKMapRectNull
for annotation in cluster.annotations {
let annotationPoint = MKMapPointForCoordinate(annotation.coordinate)
let pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0)
if MKMapRectIsNull(zoomRect) {
zoomRect = pointRect
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect)
}
}
manager.reload(mapView, visibleMapRect: zoomRect)
mapView.setVisibleMapRect(zoomRect, animated: true)
} else if let eventAnnotation = view.annotation as? EventAnnotation {
let theEvent = eventAnnotation.myEvent
let customView = (Bundle.main.loadNibNamed("CustomCalloutView", owner: self, options: nil))?[0] as! CustomCalloutView;
let calloutViewFrame = customView.frame;
customView.frame = CGRect(x: -calloutViewFrame.size.width/2.23, y: -calloutViewFrame.size.height-7, width: 315, height: 200)
customView.configureCell(events: theEvent!)
view.addSubview(customView)
}
}
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView)
{
for childView:AnyObject in view.subviews{
childView.removeFromSuperview();
}
}
}
extension UIImage {
func filled(with color: UIColor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
color.setFill()
guard let context = UIGraphicsGetCurrentContext() else { return self }
context.translateBy(x: 0, y: size.height)
context.scaleBy(x: 1.0, y: -1.0);
context.setBlendMode(CGBlendMode.normal)
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
guard let mask = self.cgImage else { return self }
context.clip(to: rect, mask: mask)
context.fill(rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}
}
class BorderedClusterAnnotationView: ClusterAnnotationView {
let borderColor: UIColor
init(annotation: MKAnnotation?, reuseIdentifier: String?, type: ClusterAnnotationType, borderColor: UIColor) {
self.borderColor = borderColor
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier, type: type)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func configure(with type: ClusterAnnotationType) {
super.configure(with: type)
switch type {
case .image:
layer.borderWidth = 0
case .color:
layer.borderColor = borderColor.cgColor
layer.borderWidth = 2
}
}
}
from cluster.
where do u add annotations?
manager.add(eventpins)
from cluster.
Accidentaly deleted it on edit. Although on my code i have it properly.
I edited the above comment. This is the issue with images.
On the first image you can see that there are 19 pins inside a cluster.
and when i tap the cluster
there are no pins on the map!
from cluster.
ur removing all the annotations on select?
mapView.removeAnnotations(mapView.annotations)
from cluster.
If i comment this line, then when i select the Cluster, it is still there! So i only remove the clusters. and not the normal pins
from cluster.
I'm still not seeing that issue.
from cluster.
@efremidze don't forget that in your example inside this repo, there are no pins on the exact same location. This is my issue, that even after the update of the pod, the pins that are in the exact same location don't show up!
from cluster.
Ill add pins in the same location and try to reproduce.
from cluster.
Any solution for this ?
from cluster.
Related Issues (20)
- Still support Swift 3? HOT 1
- Customize the distance from contested location HOT 1
- User location (i.e. blue dot) not displaying despite storyboard setting checked
- clustering groups changes frequently HOT 5
- Adding a SwiftUI Example HOT 4
- Crashlytics report - NSOperationQueue 0x1c482b240 (QOS: UNSPECIFIED) HOT 8
- Swift Compile Error HOT 1
- Code from example doesn't work
- custom pin image not showing in iOS < 13.0, It showing red default pin image. HOT 1
- Cluster start after appropriate zoom level. Like Zoom Level is 5 Then Cluster After Zoom It's Level 7 Then Show Pin.
- dyld: Library not loaded: @rpath/Cluster.framework/Cluster
- Flyover map type bug.
- More then 8000+ annotation at that time app stuck
- Background thread issue leading to a crash HOT 4
- Total number of annotations on cluster does not match the number of annotations I added to the manager HOT 4
- User Location does not show HOT 1
- Quick Question Regarding 'IPHONEOS_DEPLOYMENT_TARGET'
- how can i add multiple difference cluster? HOT 5
- Cannot click on annotations
- Is it possible for clusters to have sub clusters?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cluster.