Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Implement a Custom Clusterer

  • 8 minutes to read

To implement a custom clusterer, inherit the MapClustererBase class and implement its MapClusterer.Clusterize, CreateObject abstract methods and MapClustererBase.Items property.

In this example, the CURE clustering method is implemented. Note that it has a high algorithmic complexity.

Note

  • The Adapter’s MapDataAdapterBase.OnClustered method should be called to notify the Adapter that clustering is finished.
  • To create a new collection of cluster representatives, the protected CreateItemColelction method should be used.
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:CustomClustererSample"
        xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map" 
        x:Class="CustomClustererSample.MainWindow"
        Title="MainWindow" Height="720" Width="1280">
    <Window.Resources>
        <XmlDataProvider x:Key="dataSource" 
                         Source="Data/TreesCl.xml"/>
    </Window.Resources>
    <Grid>
        <dxm:MapControl x:Name="map">
            <dxm:ImageTilesLayer>
                <dxm:BingMapDataProvider BingKey="YourBingKeyHere"/>
            </dxm:ImageTilesLayer>
            <dxm:VectorLayer DataLoaded="VectorLayer_DataLoaded">
                <dxm:ListSourceDataAdapter DataSource="{Binding Source={StaticResource dataSource}}"
                                           DataMember="Row">
                    <dxm:ListSourceDataAdapter.Mappings>
                        <dxm:MapItemMappingInfo Latitude="lat" 
                                                Longitude="lon"/>
                    </dxm:ListSourceDataAdapter.Mappings>
                    <dxm:ListSourceDataAdapter.Clusterer>
                        <local:CureClusterer ClusterCount="10"/>
                    </dxm:ListSourceDataAdapter.Clusterer>
                </dxm:ListSourceDataAdapter>
            </dxm:VectorLayer>
        </dxm:MapControl>
    </Grid>
</Window>