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

Display a web map with a point feature layer that has feature reduction enabled to aggregate points into clusters.

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.

How to use the sample

Pan and zoom the map to view how clustering is dynamically updated. Toggle clustering off to view the original point features that make up the clustered elements. When clustering is on, you can click on a clustered geoelement to view aggregated information and summary statistics for that cluster. When clustering is toggled off and you click on the original feature you get access to information about individual power plant features.

How it works

  1. Create a map from a web map
    .
  2. Get the cluster enabled layer from the map’s operational layers.
  3. Get the
    from the feature layer and set the
    bool to enable or disable clustering on the feature layer.
  4. When the user clicks on the map, call
    , passing in the layer, map click location, tolerance, and
    as true.
  5. Set the
    from the resulting
    to the
    .
  6. Make the
    visible.

Relevant API

  • AggregateGeoElement
  • FeatureLayer
  • FeatureReduction
  • GeoElement
  • IdentifyLayerResult

About the data

This sample uses a web map that displays the Esri Global Power Plants feature layer with feature reduction enabled. When enabled, the aggregate features symbology shows the color of the most common power plant type, and a size relative to the average plant capacity of the cluster.

Additional information

Graphics in a graphics overlay can also be aggregated into clusters. To do this, set the

property on the
to a new
.

Tags

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

Sample Code

DisplayClusters.xaml DisplayClusters.xaml DisplayClusters.xaml.cs
<UserControl x:Class="ArcGIS.WinUI.Samples.DisplayClusters.DisplayClusters"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:communityTK="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:esriTK="using:Esri.ArcGISRuntime.Toolkit.UI.Controls"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<Grid>
<esriUI:MapView x:Name="MyMapView" GeoViewTapped="MyMapView_GeoViewTapped" />
<Border Width="auto" Style="{StaticResource BorderStyle}">
<CheckBox Checked="CheckBox_CheckChanged"
Content="Feature clustering"
IsChecked="True"
Unchecked="CheckBox_CheckChanged" />
</Border>
<Grid x:Name="PopupBackground"
Background="#AA333333"
Visibility="Collapsed">
<StackPanel MaxWidth="600"
MaxHeight="500"
Margin="5"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="White">
<esriTK:PopupViewer x:Name="PopupViewer"
Margin="5"
Padding="5" />
<StackPanel x:Name="GeoElementsPanel"
Margin="5,0,5,5"
Visibility="Collapsed">
<TextBlock Padding="10,0,10,5"
FontWeight="Bold"
Text="Contained Geoelements:" />
<communityTK:DataGrid x:Name="GeoElementsGrid"
MaxHeight="250"
Margin="10,5"
AutoGenerateColumns="False"
HorizontalScrollBarVisibility="Visible"
IsReadOnly="True">
<communityTK:DataGrid.Columns>
<communityTK:DataGridTextColumn Binding="{Binding Path=Attributes[objectid]}"
Width="auto"
Header="Object ID" />
<communityTK:DataGridTextColumn Binding="{Binding Path=Attributes[name]}"
Width="auto"
Header="Name" />
<communityTK:DataGridTextColumn Binding="{Binding Path=Attributes[capacity_mw]}"
Width="auto"
Header="Capacity (MW)" />
<communityTK:DataGridTextColumn Width="auto"
Binding="{Binding Path=Attributes[fuel1]}"
Header="Fuel" />
</communityTK:DataGrid.Columns>
</communityTK:DataGrid>
</StackPanel>
</StackPanel>
</Grid>
</Grid>
</UserControl>