View in MAUI WPF WinUI View on GitHub
import InlineCode from "@esri-dx/starship-doc-components/components/InlineCode.astro";

Add client side feature reduction on a point feature layer that is not pre-configured with clustering.

Use case

Feature clustering can be used to dynamically aggregate groups of points that are within proximity of each other in order to represent each group with a single symbol. Such grouping allows you to see patterns in the data that are difficult to visualize when a layer contains hundreds or thousands of points that overlap and cover each other. Users can add feature clustering to point feature layers. This is useful when the layer does not have the feature reduction defined or when the existing feature reduction properties need to be overridden.

How to use the sample

Tap the

button to set new feature reduction object on the feature layer. Interact with the controls to customize clustering feature reduction properties. Tap on any clustered aggregate geoelement to see the cluster feature count and aggregate fields in the popup.

How it works

  1. Create a map from a web map
    .
  2. Create a
    and define a
    and
    .
    must be one of the summary fields in the
    collection.
  3. Add
    objects each with an associated
    to the renderer.
  4. Create a
    using the renderer.
  5. Add
    objects to the feature reduction where the
    is the name of the field to aggregate and the
    is the type of aggregation to perform.
  6. Define the
    and
    for the feature reduction. If these are not defined they default to 12 and 70 respectively.
  7. Add the
    to the
    .
  8. Create a
    with a
    and
    to define the cluster label.
  9. Configure a
    event handler on the
    to display feature cluster information in a
    .

Relevant API

  • AggregateGeoElement
  • ClassBreaksRenderer
  • FeatureLayer
  • FeatureReduction
  • GeoElement
  • IdentifyLayerResult
  • PopupViewer

About the data

This sample uses a web map that displays residential data for Zurich, Switzerland.

Tags

aggregate, bin, cluster, group, merge, normalize, popup, reduce, renderer, summarize

Sample Code

ConfigureClusters.xaml ConfigureClusters.xaml ConfigureClusters.xaml.cs
<UserControl x:Class="ArcGIS.WinUI.Samples.ConfigureClusters.ConfigureClusters"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriTK="using:Esri.ArcGISRuntime.Toolkit.UI.Controls"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<Border Width="auto"
Height="auto"
Style="{StaticResource BorderStyle}">
<StackPanel Orientation="Vertical">
<Button x:Name="DrawClustersButton"
Padding="5"
HorizontalAlignment="Center"
Click="DrawClustersButton_Click"
Content="Draw clusters"
IsEnabled="False" />
<Grid x:Name="ClusteringOptions" Visibility="Collapsed">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.ColumnSpan="2"
Padding="5"
HorizontalAlignment="Center"
FontSize="16"
FontWeight="Bold"
Text="Clustering Properties" />
<TextBlock Grid.Row="1"
Grid.Column="0"
Padding="5"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontWeight="Bold"
Text="Display labels:" />
<CheckBox x:Name="DisplayLabelsCheckBox"
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
Checked="DisplayLabelsCheckBox_CheckedChanged"
IsChecked="false"
Unchecked="DisplayLabelsCheckBox_CheckedChanged" />
<TextBlock Grid.Row="2"
Grid.Column="0"
Padding="5"
HorizontalAlignment="Right"
VerticalAlignment="Center">
<Run FontWeight="Bold" Text="Cluster radius:" />
<Run Text="{Binding ElementName=ClusterRadiusSlider, Path=Value, Mode=OneWay}" />
</TextBlock>
<ComboBox x:Name="ClusterRadiusPicker"
Grid.Row="2"
Grid.Column="1"
Width="100"
HorizontalAlignment="Left"
VerticalAlignment="Center"
SelectionChanged="ClusterRadiusPicker_SelectionChanged" />
<TextBlock Grid.Row="3"
Grid.Column="0"
Padding="5"
HorizontalAlignment="Right"
VerticalAlignment="Center">
<Run FontWeight="Bold" Text="Maximum map scale:" />
<Run Text="{Binding ElementName=MaxScaleSlider, Path=Value, Mode=OneWay}" />
</TextBlock>
<ComboBox x:Name="MaxScalePicker"
Grid.Row="3"
Grid.Column="1"
Width="100"
VerticalAlignment="Center"
SelectionChanged="MaxScalePicker_SelectionChanged" />
<TextBlock Grid.Row="4"
Grid.Column="0"
Grid.ColumnSpan="2"
Padding="5"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Run FontWeight="Bold" Text="Current map scale: " />
<Run Text="1:" />
<Run Text="{Binding ElementName=MyMapView, Path=MapScale, Mode=OneWay}" />
</TextBlock>
</Grid>
</StackPanel>
</Border>
<Grid x:Name="PopupBackground"
Background="#AA333333"
Visibility="Collapsed">
<Border HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="White">
<esriTK:PopupViewer x:Name="PopupViewer"
MaxWidth="400"
MaxHeight="400"
Margin="5"
Padding="5" />
</Border>
</Grid>
</Grid>
</UserControl>