Clusterers
- 4 minutes to read
This document introduces the Map Clusterers, lists clusterer types, and explains how to create a clusterer and customize its settings.
#Overview
The Clusterer is used to aggregate map items based on their location.
For example, this can be useful to perform density analysis.
To apply clustering, assign one of the clusterers described below to the IMapDataAdapter.Clusterer property.
#Marker Clusterer
The Marker Clusterer aggregates items using the following approach.
- The center item is selected from the collection of source items.
- All source items that are located closer to the item than the specified threshold and the item itself form a cluster.
- A cluster representative is created and added to the resulting collection. The cluster representative location is equal to the location of the center item.
- All clustered items are removed from the source collection.
- The previous steps are repeated until the source collection contains items.
The Marker Clusterer is represented by the MarkerClusterer class.
#Distance-based Clusterer
The Distance-based Clusterer aggregates items using the following approach.
- Select an item from source items collection.
- Find the closest cluster to the item.
- If distance between the cluster and the item is smaller than a specified threshold, then the item is added to the cluster; otherwise, the item forms a new cluster.
- The item is removed from the source collection. Update the cluster parameters. Note, that the cluster representative location is the mean of cluster item locations.
- The previous steps are repeated until the source collection contains items.
The Distance-based Clusterer is represented by the DistanceBasedClusterer class.
The following table represents the results comparison of clustering using the described above methods.
The clusterer | The resulting image |
---|---|
Marker | |
Distance-based |
Note
To implement a custom clusterer, design a class implementing the IClusterer interface.
#Common Clusterer Settings
All clusterers shipped with the Map Control support item group providers and custom item factories.
Group Providers allow you to separate vector items depending on certain values. By default, the clusterers can use the predefined AttributeGroupProvider to group items by attribute values.
Note
To implement a custom Group Provider, design a class implementing the IClusterer
Group interface.Provider The following image demonstrates vector items grouped by location name.
To customize a cluster representative, you can use the custom Cluster Item Factories. To do this, create a class implementing the IClusterItemFactory interface. Then, send an object of this class as an argument of the MapClustererBase.SetClusterItemFactory method.
The following image demonstrates custom cluster representatives created using a custom cluster item factory.
#Allow Users to Expand Clusters
Users can hover over a cluster to expand it and see all nested map items. To enable this functionality, follow the steps below:
Create a MouseHoverInteractiveClusterMode object and assign it to the MapControl.InteractiveClusterMode property.
Select a layout algorithm that defines how to position nested map items when a cluster is expanded. To do this, assign one of the following objects to the InteractiveClusterModeBase.ExpandedClusterLayout property:
- ExpandedClusterAdaptiveLayout – Items are positioned in a circle or spiral depending on the item count in the cluster.
- ExpandedClusterCircularLayout – Items are positioned in a circle.
- ExpandedClusterSourceLocationLayout – Items are positioned based on their source locations.
- ExpandedClusterSpiralLayout – Items are positioned in a spiral.
After a user moves the mouse cursor out of the cluster, clustered items are repositioned based on their actual locations. Then, clustered items are collapsed into the cluster.
The following example selects an optimal view (circular or spiral) for nested cluster items depending on their count in the cluster:
MouseHoverInteractiveClusterMode interactiveMode = new MouseHoverInteractiveClusterMode();
interactiveMode.ExpandedClusterLayout = new ExpandedClusterAdaptiveLayout();
map.InteractiveClusterMode = interactiveMode;
#Examples
The following examples demonstrate clusterers in action.
#Demos
Explore the clustering demos in the Demo Center: