Mapbox iOS clustering works, but circle style layer and numbers layer aren't appearing/reflecting the marker density of the cluster
So, I feel like an idiot.
The issue was in the MGLShapeSource:
MGLShapeSource(identifier: "clusteredPoints", shape: shapes, options: [.clustered: true, .clusterRadius: 0.5])
For whatever reason, I had been messing around with the clusterRadius, and had it set to 0.5, which I assume is in points. Note that the example was using the marker's width to determine the cluster radius.
let source = MGLShapeSource(identifier: "clusteredPorts",
url: url,
options: [.clustered: true, .clusterRadius: icon.size.width])
I though that, because some of the markers were disappearing whenever they overlapped with another marker, that they were clustering but the cluster layer was not being shown. They weren't clustering, I guess shape sources are just able to know when they are overlapping with another, and will disappear accordingly. Just because they disappear doesn't meant that they are clustered.
Clustering annotations with Mapbox
I did some research on this not too long ago and it didn't seem to be possible on iOS. Here is the suggestion on github that is still open. Here is another issue about how it wasn't mentioned in the documentation but has since been added.
How can i parse a custom marker icon with clustering in iOS Swift
Solution found:Here starts the class in GMUDefaultClusterRenderer.m at clustering folder
- (GMSMarker *)markerWithPosition:(CLLocationCoordinate2D)position
from:(CLLocationCoordinate2D)from
userData:(id)userData
clusterIcon:(UIImage *)clusterIcon
animated:(BOOL)animated {.....
......
I replace the original with this:
if (clusterIcon != nil) {
marker.icon = clusterIcon;
marker.groundAnchor = CGPointMake(0.5, 0.5);
}else{
marker.icon = [UIImage imageNamed:@"K_Annotation.png"];
}
Related Topics
Is It a Good Way to Access Instance Variable with Self? If I Use a Lot
Gmsmarker Not Appearing on Map
Implementing a Custom Viewmodifier Where Output Is Conditional on Concrete View Type (Swiftui)
Realitykit - Updating Entity's Translation Returns Unexpected Values
Why I Can't Access My 3Rd Level Coredata Data in Swift
Comparing Time Without Date Swift3
Swift Xml Rss Reader... Make It Async
.Childadded Observer Doesn't Get Called If The Function Is Not Called Explicitly. Swift 4
Got Error: Return an Empty String to Bool
Generate Random Questions in Swift
iOS Application Support Directory Exists on Devices by Default
What's The How to Access a Swift Package Item from Objective-C
How to Download Video Urlstring from Firebase Database Not Storage in Swift
How to Make Phone Calls in Swift
How to Convert a Pair of Bytes into a Float Using Swift