Back to Devexpress

AttributeGroupProvider.AttributeName Property

windowsforms-devexpress-dot-xtramap-dot-attributegroupprovider.md

latest6.1 KB
Original Source

AttributeGroupProvider.AttributeName Property

Gets or sets the attribute name used to group map items by its value.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
[DefaultValue(null)]
public string AttributeName { get; set; }
vb
<DefaultValue(Nothing)>
Public Property AttributeName As String

Property Value

TypeDefaultDescription
Stringnull

A String object, that is the name of the attribute.

|

Example

This example shows how to cluster vector map items.

Follow the steps below to cluster map items:

  1. Assign an object of a class that implements the IClusterer interface to the MapDataAdapterBase.Clusterer property.

  2. To group the items based on an attribute, assign an AttributeGroupProvider object to the MapClustererBase.GroupProvider property. Set the AttributeGroupProvider.AttributeName property to the item attribute name that should be used to cluster items. After that, only items with an equal attribute value are grouped into the same cluster.

  3. Design a class that implements the IClusterItemFactory interface to customize the appearance of clusters. Then, call the MapClustererBase.SetClusterItemFactory method with an object of the class to assign the required factory object to the clusterer.

  4. 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.

View Example

csharp
VectorItemsLayer VectorLayer { get { return (VectorItemsLayer)map.Layers["VectorLayer"]; } }
    // ...
    ListSourceDataAdapter DataAdapter { get { return (ListSourceDataAdapter)VectorLayer.Data; } }
    // ...
    private void Form1_Load(object sender, EventArgs e) {
        DataAdapter.DataSource = LoadData();
        DistanceBasedClusterer clusterer = new DistanceBasedClusterer {
            ItemMaxSize = 60,
            ItemMinSize = 14,
            GroupProvider = new AttributeGroupProvider {
                AttributeName = "LocationName"
            }
        };

        clusterer.SetClusterItemFactory(new CustomClusterItemFactory());
        DataAdapter.Clusterer = clusterer;

        DataAdapter.PropertyMappings.Add(new MapDotSizeMapping { DefaultValue = 14 });

        MouseHoverInteractiveClusterMode interactiveMode = new MouseHoverInteractiveClusterMode();
        interactiveMode.ExpandedClusterLayout = new ExpandedClusterAdaptiveLayout();
        map.InteractiveClusterMode = interactiveMode;
    }
    // ...
class CustomClusterItemFactory : IClusterItemFactory {
    public MapItem CreateClusterItem(IList<MapItem> objects) {
        return new MapDot();
    }

    public void CustomizeCluster(MapItem cluster) {
        ((MapDot)cluster).TitleOptions.Pattern = cluster.ClusteredItems.Count.ToString();
    }
}
vb
Private ReadOnly Property VectorLayer As VectorItemsLayer
        Get
            Return CType(map.Layers("VectorLayer"), VectorItemsLayer)
        End Get
    End Property

    Private ReadOnly Property DataAdapter As ListSourceDataAdapter
        Get
            Return CType(VectorLayer.Data, ListSourceDataAdapter)
        End Get
    End Property
    ' ...
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        DataAdapter.DataSource = LoadData()
        Dim clusterer As DistanceBasedClusterer = New DistanceBasedClusterer With {.ItemMaxSize = 60, .ItemMinSize = 14, .GroupProvider = New AttributeGroupProvider With {.AttributeName = "LocationName"}}
        clusterer.SetClusterItemFactory(New CustomClusterItemFactory())
        DataAdapter.Clusterer = clusterer
        DataAdapter.PropertyMappings.Add(New MapDotSizeMapping With {.DefaultValue = 14})
        Dim interactiveMode As MouseHoverInteractiveClusterMode = New MouseHoverInteractiveClusterMode()
        interactiveMode.ExpandedClusterLayout = New ExpandedClusterAdaptiveLayout()
        map.InteractiveClusterMode = interactiveMode
    End Sub
    ' ...
Friend Class CustomClusterItemFactory
    Implements IClusterItemFactory

    Private Function IClusterItemFactory_CreateClusterItem(objects As IList(Of MapItem)) As MapItem Implements IClusterItemFactory.CreateClusterItem
        Return New MapDot()
    End Function

    Private Sub IClusterItemFactory_CustomizeCluster(cluster As MapItem) Implements IClusterItemFactory.CustomizeCluster
        CType(cluster, MapDot).TitleOptions.Pattern = cluster.ClusteredItems.Count.ToString()
    End Sub
End Class

See Also

AttributeGroupProvider Class

AttributeGroupProvider Members

DevExpress.XtraMap Namespace