Marker clusters (v2.1.x - iOS)

It’s possible to display overlapping user markers as clusters using NMGeoMarkerClusterManager.

First, create an instance of NMGeoMarkerClusterManager using NMMapView method
-(nullable NMGeoMarkerClusterManager *)createMarkerClusterManager :

NMGeoMarkerClusterManager *markerClusterManager = [mapView createMarkerClusterManager];

To add markers, use addGeoMarker or addGeoMarkers methods:

[markerClusterManager addGeoMarker:marker];

Markers are removed using removeGeoMarker and removeGeoMarkers methods. The method removeAllGeoMarkers is available to remove all markers at once.

The destroy method removes all markers from the map and releases all resources associated with the manager. Once this method is called, the manager should not be used.

Customizing Cluster Appearance

It's possible to customize the appearance of markers and clusters. The setImage method allows changing the cluster image. Adjustments to the item count labels on clusters, like font size, color, and offset, can be made using setLabelFontSize, setLabelColor, and setLabelOffset.

Example:

[markerClusterManager setImage: [UIImage imageNamed: @"cluster_icon"] imageScale:[UIScreen mainScreen].scale]; [markerClusterManager setShowItemCount:YES]; [markerClusterManager setLabelFontSize:16]; [markerClusterManager setLabelColor: [UIColor blueColor];

 

map_cluster.jpg

Interacting with Clusters

Retrieving clusters at specific screen positions is possible using getClustersAtPoint. The returned clusters will be ordered by their distance from the specified point.

If an object implementing NMGeoObjectListener interface is added to a map view using NMMapView method -(void)addGeoObjectsListener, clicking on clusters will result in the corresponding callbacks being called, with NMGeoMarkerCluster objects passed as arguments.

NMGeoMarkerCluster contains methods that allow retrieving its position, bounds, the number of markers it contains and the markers themselves. This can be used, for example, to change the camera position when a cluster is clicked: