# Clusterization

**RadMap** supports clusterization of its layers allowing grouping of their items. This feature is extremely useful when dealing with large collections having items located close to each other.

> caption Figure 1: Clustering

![WinForms RadMap Clustering](https://www.telerik.com/products/winforms/documentation/assets/0dff880c44bbb56fe410080e6a5fd318/map-features-layers-clusterization001.png)

## Clusterization Modes

The **ClusterDistance** property of a certain layer is responsible for setting a distance according to which each of the layer items will be evaluated to form a group. There are two types of clusters which can be assigned to the **ClusterStrategy** property of the layer:

* **ElementClusterStrategy**: All of the layer items are evaluated and a cluster is being created on the exact coordinates of an item within the cluster.

* **DistanceClusterStrategy**: All of the layer items are evaluated and a cluster is being created on the geographic center of the items part of the cluster.

The example below creates a layer with four **MapPin** elements and defines clusters using **ElementClusterStrategy** and **DistanceClusterStrategy** having the same **ClusterDistance**.

#### Add Layer and Data

```C#
private void SetupLayers()
{
    MapLayer easternLayer = new MapLayer("CitiesLayer");
    this.radMap1.Layers.Add(easternLayer);
}
    
private void SetupData()
{
    MapPin element = new MapPin(new PointG(40.4467648, -80.01576030));
    element.Text = "Pittsburgh";
    element.BackColor = Color.Red;
    this.radMap1.Layers["CitiesLayer"].Add(element);

    element = new MapPin(new PointG(40.8130697, -74.07439790));
    element.Text = "New York";
    element.BackColor = Color.Green;
    this.radMap1.Layers["CitiesLayer"].Add(element);

    element = new MapPin(new PointG(42.3665137, -71.06160420));
    element.Text = "Boston";
    element.BackColor = Color.Blue;
    this.radMap1.Layers["CitiesLayer"].Add(element);

    element = new MapPin(new PointG(43.6434661, -79.37909890));
    element.Text = "Toronto";
    element.BackColor = Color.Yellow;
    this.radMap1.Layers["CitiesLayer"].Add(element);
}
```

```VB.NET
Private Sub SetupLayers()
    Dim easternLayer As New MapLayer("CitiesLayer")
    Me.RadMap1.Layers.Add(easternLayer)
End Sub

Private Sub SetupData()
    Dim element As New MapPin(New PointG(40.4467648, -80.0157603))
    element.Text = "Pittsburgh"
    element.BackColor = Color.Red
    Me.RadMap1.Layers("CitiesLayer").Add(element)

    element = New MapPin(New PointG(40.8130697, -74.0743979))
    element.Text = "New York"
    element.BackColor = Color.Green
    Me.RadMap1.Layers("CitiesLayer").Add(element)

    element = New MapPin(New PointG(42.3665137, -71.0616042))
    element.Text = "Boston"
    element.BackColor = Color.Blue
    Me.RadMap1.Layers("CitiesLayer").Add(element)

    element = New MapPin(New PointG(43.6434661, -79.3790989))
    element.Text = "Toronto"
    element.BackColor = Color.Yellow
    Me.RadMap1.Layers("CitiesLayer").Add(element)
End Sub
```

> caption Figure 2: Initial Result

![WinForms RadMap Initial Result](https://www.telerik.com/products/winforms/documentation/assets/588efc015a67adaaad88cdad8fe1a250/map-features-layers-clusterization002.png)

#### ElementClusterStrategy

```C#
private void SetElementCluster()
{
    this.radMap1.Layers[0].ClusterStrategy = new ElementClusterStrategy();
    this.radMap1.Layers["CitiesLayer"].ClusterDistance = 200;
}
```

```VB.NET
Private Sub SetElementCluster()
    Me.RadMap1.Layers(0).ClusterStrategy = New ElementClusterStrategy()
    Me.RadMap1.Layers("CitiesLayer").ClusterDistance = 200
End Sub
```

> caption Figure 3: ElementClusterStrategy

![WinForms RadMap ElementClusterStrategy](https://www.telerik.com/products/winforms/documentation/assets/afdae6b97859e56dff5ef516a3613def/map-features-layers-clusterization003.png)

#### DistanceClusterStrategy

```C#
private void DistanceElementCluster()
{
    this.radMap1.Layers[0].ClusterStrategy = new DistanceClusterStrategy();
    this.radMap1.Layers["CitiesLayer"].ClusterDistance = 200;
}
```

```VB.NET
Private Sub SetDistanceCluster()
    Me.RadMap1.Layers(0).ClusterStrategy = New DistanceClusterStrategy()
    Me.RadMap1.Layers("CitiesLayer").ClusterDistance = 200
End Sub
```

> caption Figure 4: DistanceClusterStrategy

![WinForms RadMap DistanceClusterStrategy](https://www.telerik.com/products/winforms/documentation/assets/3ab2496aee24363db46be546124aefc8/map-features-layers-clusterization004.png)

## See Also

* [Layers Overview](https://www.telerik.com/products/winforms/documentation/controls/map/features/layers/overview)
* [Colorization](https://www.telerik.com/products/winforms/documentation/controls/map/features/layers/colorization)
