Skip to content

Commit ec56282

Browse files
DisplayClusters attribute table and readme (#1444)
1 parent c14fd30 commit ec56282

File tree

9 files changed

+261
-41
lines changed

9 files changed

+261
-41
lines changed

src/MAUI/Maui.Samples/Samples/Layers/DisplayClusters/DisplayClusters.xaml

+67-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,73 @@
2323
Dark=#303030}"
2424
HorizontalOptions="Center"
2525
VerticalOptions="Center">
26-
<esriTK:PopupViewer x:Name="PopupViewer"
27-
Margin="5"
28-
Padding="5"
29-
HeightRequest="250"
30-
WidthRequest="250" />
26+
<StackLayout Margin="5"
27+
Padding="5"
28+
Spacing="5">
29+
<esriTK:PopupViewer x:Name="PopupViewer"
30+
MaximumWidthRequest="{OnIdiom Default=750,
31+
Phone=250}"
32+
MinimumWidthRequest="250"
33+
HeightRequest="150" />
34+
<StackLayout x:Name="GeoElementsPanel"
35+
Margin="5"
36+
Padding="5"
37+
IsVisible="false"
38+
Spacing="5">
39+
<Label FontAttributes="Bold" Text="Contained Geoelements:" />
40+
<!-- On phone, only show the name attribute. -->
41+
<CollectionView x:Name="GeoElementsGrid"
42+
MaximumHeightRequest="{OnIdiom Default=500,
43+
Phone=250}"
44+
MaximumWidthRequest="{OnIdiom Default=750,
45+
Phone=250}">
46+
<CollectionView.Header>
47+
<Grid ColumnDefinitions="*,2*,*,*" ColumnSpacing="50">
48+
<Label Grid.Column="0"
49+
FontAttributes="Bold"
50+
IsVisible="{OnIdiom Default=True,
51+
Phone=False}"
52+
Text="Object ID" />
53+
<Label Grid.Column="{OnIdiom Default=1,
54+
Phone=0}"
55+
Grid.ColumnSpan="{OnIdiom Default=0,
56+
Phone=4}"
57+
FontAttributes="Bold"
58+
Text="Name" />
59+
<Label Grid.Column="2"
60+
FontAttributes="Bold"
61+
IsVisible="{OnIdiom Default=True,
62+
Phone=False}"
63+
Text="Capacity (MW)" />
64+
<Label Grid.Column="3"
65+
FontAttributes="Bold"
66+
IsVisible="{OnIdiom Default=True,
67+
Phone=False}"
68+
Text="Fuel" />
69+
</Grid>
70+
</CollectionView.Header>
71+
<CollectionView.ItemTemplate>
72+
<OnIdiom x:TypeArguments="DataTemplate">
73+
<OnIdiom.Default>
74+
<DataTemplate>
75+
<Grid ColumnDefinitions="*,2*,*,*" ColumnSpacing="50">
76+
<Label Text="{Binding Path=Attributes[objectid]}" />
77+
<Label Grid.Column="1" Text="{Binding Path=Attributes[name]}" />
78+
<Label Grid.Column="2" Text="{Binding Path=Attributes[capacity_mw]}" />
79+
<Label Grid.Column="3" Text="{Binding Path=Attributes[fuel1]}" />
80+
</Grid>
81+
</DataTemplate>
82+
</OnIdiom.Default>
83+
<OnIdiom.Phone>
84+
<DataTemplate>
85+
<Label Text="{Binding Path=Attributes[name]}" />
86+
</DataTemplate>
87+
</OnIdiom.Phone>
88+
</OnIdiom>
89+
</CollectionView.ItemTemplate>
90+
</CollectionView>
91+
</StackLayout>
92+
</StackLayout>
3193
</Border>
3294
</Grid>
3395
</Grid>

src/MAUI/Maui.Samples/Samples/Layers/DisplayClusters/DisplayClusters.xaml.cs

+37-8
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99

1010
using Esri.ArcGISRuntime.Data;
1111
using Esri.ArcGISRuntime.Mapping;
12+
using Esri.ArcGISRuntime.Mapping.Popups;
1213
using Esri.ArcGISRuntime.Portal;
14+
using Esri.ArcGISRuntime.Reduction;
1315

1416
namespace ArcGIS.Samples.DisplayClusters
1517
{
1618
[ArcGIS.Samples.Shared.Attributes.Sample(
1719
name: "Display clusters",
1820
category: "Layers",
1921
description: "Display a web map with a point feature layer that has feature reduction enabled to aggregate points into clusters.",
20-
instructions: "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 tap on a clustered geoelement to view aggregated information and summary statistics for that cluster. When clustering is toggled off and you tap on the original feature you get access to information about individual power plant features.",
22+
instructions: "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 as well as a list geo elements in the identified cluster. When clustering is toggled off and you click on the original feature you get access to information about individual power plant features.",
2123
tags: new[] { "aggregate", "bin", "cluster", "group", "merge", "normalize", "reduce", "summarize" })]
2224
[ArcGIS.Samples.Shared.Attributes.OfflineData()]
2325
public partial class DisplayClusters
2426
{
27+
// Hold a reference to the feature layer.
2528
private FeatureLayer _layer;
2629

2730
public DisplayClusters()
@@ -50,23 +53,49 @@ private async Task Initialize()
5053
{
5154
PopupBackground.IsVisible = false;
5255
PopupViewer.Popup = null;
56+
GeoElementsGrid.ItemsSource = null;
57+
GeoElementsPanel.IsVisible = false;
5358
})
5459
});
5560

56-
MyMapView.ViewpointChanged += (s, e) => Console.WriteLine($"Viewpoint changed");
5761
}
5862

5963
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Maui.GeoViewInputEventArgs e)
6064
{
65+
// Clear any previously selected features or clusters.
66+
_layer.ClearSelection();
67+
6168
// Identify the tapped observation.
62-
IdentifyLayerResult results = await MyMapView.IdentifyLayerAsync(_layer, e.Position, 3, true);
69+
var results = await MyMapView.IdentifyLayerAsync(_layer, e.Position, 3, false);
70+
71+
// Return if no popups are found.
72+
if (results.GeoElements.Count == 0 || results.Popups.Count == 0) return;
6373

64-
// Return if no observations were found.
65-
if (results.Popups.Count == 0) return;
74+
if (results.Popups.FirstOrDefault() is Popup popup)
75+
{
76+
// Set the popup and make it visible.
77+
PopupViewer.Popup = popup;
78+
PopupBackground.IsVisible = true;
79+
}
6680

67-
// Set the popup and make it visible.
68-
PopupViewer.Popup = results.Popups.FirstOrDefault();
69-
PopupBackground.IsVisible = true;
81+
// If the tapped observation is an AggregateGeoElement then select it.
82+
if (results.GeoElements.FirstOrDefault() is AggregateGeoElement aggregateGeoElement)
83+
{
84+
// Select the AggregateGeoElement.
85+
aggregateGeoElement.IsSelected = true;
86+
87+
// Get the contained GeoElements.
88+
IReadOnlyList<GeoElement> geoElements = await aggregateGeoElement.GetGeoElementsAsync();
89+
90+
// Set the geoelements as an items source and set the visibility.
91+
GeoElementsGrid.ItemsSource = geoElements;
92+
GeoElementsPanel.IsVisible = true;
93+
}
94+
else if (results.GeoElements.FirstOrDefault() is ArcGISFeature feature)
95+
{
96+
// If the tapped observation is not an AggregateGeoElement select the feature.
97+
_layer.SelectFeature(feature);
98+
}
7099
}
71100

72101
// Enable clustering feature reduction if the checkbox has been checked, disable otherwise.

src/MAUI/Maui.Samples/Samples/Layers/DisplayClusters/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Pan and zoom the map to view how clustering is dynamically updated. Toggle clust
3333

3434
This sample uses a [web map](https://www.arcgis.com/home/item.html?id=8916d50c44c746c1aafae001552bad23) that displays the Esri [Global Power Plants](https://www.arcgis.com/home/item.html?id=eb54b44c65b846cca12914b87b315169) 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.
3535

36+
## Additional information
37+
38+
Graphics in a graphics overlay can also be aggregated into clusters. To do this, set the `FeatureReduction` property on the `GraphicsOverlay` to a new `ClusteringFeatureReduction`.
39+
3640
## Tags
3741

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

src/WPF/WPF.Viewer/Samples/Layers/DisplayClusters/DisplayClusters.xaml

+35-11
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,48 @@
55
<Grid>
66
<esri:MapView x:Name="MyMapView" GeoViewTapped="MyMapView_GeoViewTapped" />
77
<Border Width="auto" Style="{StaticResource BorderStyle}">
8-
<CheckBox Checked="CheckBox_CheckChanged"
9-
Content="Feature clustering"
10-
IsChecked="True"
11-
Unchecked="CheckBox_CheckChanged" />
8+
<StackPanel>
9+
<CheckBox Checked="EnableClusteringCheckBox_CheckChanged"
10+
Content="Feature clustering"
11+
IsChecked="True"
12+
Unchecked="EnableClusteringCheckBox_CheckChanged" />
13+
</StackPanel>
1214
</Border>
1315
<Grid x:Name="PopupBackground"
1416
Background="#AA333333"
1517
MouseLeftButtonDown="PopupBackground_MouseLeftButtonDown"
1618
Visibility="Collapsed">
17-
<Border HorizontalAlignment="Center"
18-
VerticalAlignment="Center"
19-
Background="White">
19+
<StackPanel MaxWidth="600"
20+
MaxHeight="500"
21+
Margin="5"
22+
HorizontalAlignment="Center"
23+
VerticalAlignment="Center"
24+
Background="White">
2025
<esri:PopupViewer x:Name="PopupViewer"
21-
MaxWidth="400"
22-
MaxHeight="400"
23-
Margin="5"
26+
Margin="5,0,5,5"
2427
Padding="5" />
25-
</Border>
28+
<StackPanel x:Name="GeoElementsPanel"
29+
Margin="5,0,5,5"
30+
Visibility="Collapsed">
31+
<TextBlock Padding="10,0,10,5"
32+
FontWeight="Bold"
33+
Text="Contained Geoelements:" />
34+
<DataGrid x:Name="GeoElementsGrid"
35+
MaxHeight="250"
36+
Margin="10,5"
37+
AutoGenerateColumns="False"
38+
IsReadOnly="True">
39+
<DataGrid.Columns>
40+
<DataGridTextColumn Binding="{Binding Path=Attributes[objectid]}" Header="Object ID" />
41+
<DataGridTextColumn Binding="{Binding Path=Attributes[name]}" Header="Name" />
42+
<DataGridTextColumn Binding="{Binding Path=Attributes[capacity_mw]}" Header="Capacity (MW)" />
43+
<DataGridTextColumn Width="*"
44+
Binding="{Binding Path=Attributes[fuel1]}"
45+
Header="Fuel" />
46+
</DataGrid.Columns>
47+
</DataGrid>
48+
</StackPanel>
49+
</StackPanel>
2650
</Grid>
2751
</Grid>
2852
</UserControl>

src/WPF/WPF.Viewer/Samples/Layers/DisplayClusters/DisplayClusters.xaml.cs

+38-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
using Esri.ArcGISRuntime.Data;
1111
using Esri.ArcGISRuntime.Mapping;
12+
using Esri.ArcGISRuntime.Mapping.Popups;
1213
using Esri.ArcGISRuntime.Portal;
14+
using Esri.ArcGISRuntime.Reduction;
1315
using Esri.ArcGISRuntime.UI.Controls;
16+
using System.Collections.Generic;
1417
using System.Linq;
1518
using System.Threading.Tasks;
1619
using System.Windows;
@@ -22,11 +25,12 @@ namespace ArcGIS.WPF.Samples.DisplayClusters
2225
name: "Display clusters",
2326
category: "Layers",
2427
description: "Display a web map with a point feature layer that has feature reduction enabled to aggregate points into clusters.",
25-
instructions: "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.",
28+
instructions: "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 as well as a list geo elements in the identified cluster. When clustering is toggled off and you click on the original feature you get access to information about individual power plant features.",
2629
tags: new[] { "aggregate", "bin", "cluster", "group", "merge", "normalize", "reduce", "summarize" })]
2730
[ArcGIS.Samples.Shared.Attributes.OfflineData()]
2831
public partial class DisplayClusters
2932
{
33+
// Hold a reference to the feature layer.
3034
private FeatureLayer _layer;
3135

3236
public DisplayClusters()
@@ -51,19 +55,44 @@ private async Task Initialize()
5155

5256
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
5357
{
58+
// Clear any previously selected features or clusters.
59+
_layer.ClearSelection();
60+
5461
// Identify the tapped observation.
55-
IdentifyLayerResult results = await MyMapView.IdentifyLayerAsync(_layer, e.Position, 3, true);
62+
var results = await MyMapView.IdentifyLayerAsync(_layer, e.Position, 3, false);
5663

5764
// Return if no popups are found.
58-
if (results.Popups.Count == 0) return;
65+
if (results.GeoElements.Count == 0 || results.Popups.Count == 0) return;
66+
67+
if (results.Popups.FirstOrDefault() is Popup popup)
68+
{
69+
// Set the popup and make it visible.
70+
PopupViewer.Popup = popup;
71+
PopupBackground.Visibility = Visibility.Visible;
72+
}
73+
74+
// If the tapped observation is an AggregateGeoElement then select it.
75+
if (results.GeoElements.FirstOrDefault() is AggregateGeoElement aggregateGeoElement)
76+
{
77+
// Select the AggregateGeoElement.
78+
aggregateGeoElement.IsSelected = true;
79+
80+
// Get the contained GeoElements.
81+
IReadOnlyList<GeoElement> geoElements = await aggregateGeoElement.GetGeoElementsAsync();
5982

60-
// Set the popup and make it visible.
61-
PopupViewer.Popup = results.Popups.FirstOrDefault();
62-
PopupBackground.Visibility = Visibility.Visible;
83+
// Set the geoelements as an items source and set the visibility.
84+
GeoElementsGrid.ItemsSource = geoElements;
85+
GeoElementsPanel.Visibility = Visibility.Visible;
86+
}
87+
else if (results.GeoElements.FirstOrDefault() is ArcGISFeature feature)
88+
{
89+
// If the tapped observation is not an AggregateGeoElement select the feature.
90+
_layer.SelectFeature(feature);
91+
}
6392
}
6493

6594
// Enable clustering feature reduction if the checkbox has been checked, disable otherwise.
66-
private void CheckBox_CheckChanged(object sender, RoutedEventArgs e)
95+
private void EnableClusteringCheckBox_CheckChanged(object sender, RoutedEventArgs e)
6796
{
6897
// This event is raised when sample is initially loaded when layer is null.
6998
if (_layer == null) return;
@@ -75,7 +104,9 @@ private void CheckBox_CheckChanged(object sender, RoutedEventArgs e)
75104
private void PopupBackground_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
76105
{
77106
PopupBackground.Visibility = Visibility.Collapsed;
107+
GeoElementsPanel.Visibility = Visibility.Collapsed;
78108
PopupViewer.Popup = null;
109+
GeoElementsGrid.ItemsSource = null;
79110
}
80111
}
81112
}

src/WPF/WPF.Viewer/Samples/Layers/DisplayClusters/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Pan and zoom the map to view how clustering is dynamically updated. Toggle clust
3333

3434
This sample uses a [web map](https://www.arcgis.com/home/item.html?id=8916d50c44c746c1aafae001552bad23) that displays the Esri [Global Power Plants](https://www.arcgis.com/home/item.html?id=eb54b44c65b846cca12914b87b315169) 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.
3535

36+
## Additional information
37+
38+
Graphics in a graphics overlay can also be aggregated into clusters. To do this, set the `FeatureReduction` property on the `GraphicsOverlay` to a new `ClusteringFeatureReduction`.
39+
3640
## Tags
3741

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

0 commit comments

Comments
 (0)