windowsforms-devexpress-dot-xtramap-7b875de1.md
This class groups items based on the attribute values.
Namespace : DevExpress.XtraMap
Assembly : DevExpress.XtraMap.v25.2.dll
NuGet Package : DevExpress.Win.Map
public class AttributeGroupProvider :
MapClustererGroupProviderBase
Public Class AttributeGroupProvider
Inherits MapClustererGroupProviderBase
This class introduces the AttributeGroupProvider.AttributeName property allowing you to specify the name of an attribute used to group items.
This example shows how to cluster vector map items.
Follow the steps below to cluster map items:
Assign an object of a class that implements the IClusterer interface to the MapDataAdapterBase.Clusterer property.
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.
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.
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.
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();
}
}
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
Object MapClustererGroupProviderBase AttributeGroupProvider
See Also