windowsforms-114673-controls-and-libraries-map-control-vector-data-clusterers.md
This document introduces the Map Clusterers , lists clusterer types, and explains how to create a clusterer and customize its settings.
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.
The Marker Clusterer aggregates items using the following approach.
The Marker Clusterer is represented by the MarkerClusterer class.
The Distance-based Clusterer aggregates items using the following approach.
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.
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.
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.
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:
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;
Dim interactiveMode As MouseHoverInteractiveClusterMode = New MouseHoverInteractiveClusterMode()
interactiveMode.ExpandedClusterLayout = New ExpandedClusterAdaptiveLayout()
map.InteractiveClusterMode = interactiveMode
The following examples demonstrate clusterers in action.
Explore the clustering demos in the Demo Center: