Skip to content

Commit 28ca204

Browse files
authored
Merge pull request #382 from Esri/Caleb/Update-DisplayClustersDesign
[Update] `Display clusters` design
2 parents c3813c3 + 1231b27 commit 28ca204

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

Shared/Samples/Display clusters/DisplayClustersView.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct DisplayClustersView: View {
3434
/// The screen point to perform an identify operation.
3535
@State private var identifyScreenPoint: CGPoint?
3636

37+
/// The geoelements in the selected cluster.
38+
@State private var geoElements: [GeoElement] = []
39+
3740
/// The popup to be shown as the result of the layer identify operation.
3841
@State private var popup: Popup?
3942

@@ -53,6 +56,9 @@ struct DisplayClustersView: View {
5356
identifyScreenPoint = screenPoint
5457
}
5558
.task(id: identifyScreenPoint) {
59+
layer?.clearSelection()
60+
geoElements.removeAll()
61+
5662
guard let identifyScreenPoint,
5763
let layer,
5864
let identifyResult = try? await proxy.identify(
@@ -63,6 +69,15 @@ struct DisplayClustersView: View {
6369
else { return }
6470
self.popup = identifyResult.popups.first
6571
self.showsPopup = self.popup != nil
72+
73+
guard let identifyGeoElement = identifyResult.geoElements.first else { return }
74+
if let aggregateGeoElement = identifyGeoElement as? AggregateGeoElement {
75+
aggregateGeoElement.isSelected = true
76+
let geoElements = try? await aggregateGeoElement.geoElements
77+
self.geoElements = geoElements ?? []
78+
} else if let feature = identifyGeoElement as? Feature {
79+
layer.selectFeature(feature)
80+
}
6681
}
6782
.floatingPanel(
6883
selectedDetent: .constant(.half),
@@ -71,7 +86,26 @@ struct DisplayClustersView: View {
7186
) { [popup] in
7287
PopupView(popup: popup!, isPresented: $showsPopup)
7388
.showCloseButton(true)
74-
.padding()
89+
.padding([.top, .horizontal])
90+
91+
if !geoElements.isEmpty {
92+
List {
93+
Section {
94+
ForEach(Array(geoElements.enumerated()),
95+
id: \.offset
96+
) { offset, geoElement in
97+
let name = geoElement.attributes["name"] as? String
98+
Text(name ?? "Geoelement: \(offset)")
99+
}
100+
} header: {
101+
Text("Geoelements")
102+
.font(.title3)
103+
.bold()
104+
.foregroundColor(.primary)
105+
}
106+
}
107+
.listStyle(.inset)
108+
}
75109
}
76110
.toolbar {
77111
ToolbarItem(placement: .bottomBar) {

Shared/Samples/Display clusters/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Feature clustering can be used to dynamically aggregate groups of points that ar
1010

1111
## How to use the sample
1212

13-
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 toggled 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.
13+
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 toggled on, you can tap on a clustered geoelement to view aggregated information and summary statistics for that cluster as well as a list of containing geoelements. When clustering is disabled and you tap on the original feature you get access to information about individual power plant features.
1414

1515
## How it works
1616

@@ -20,7 +20,8 @@ Pan and zoom the map to view how clustering is dynamically updated. Toggle clust
2020
4. Use the `onSingleTapGesture` modifier to listen for tap events on the map view.
2121
5. Identify tapped features on the map using `identify(on:screenPoint:tolerance:returnPopupsOnly:maximumResults:)` on the feature layer and pass in the map screen point location.
2222
6. Get the `Popup` from the resulting `IdentifyLayerResult` and use it to construct a `PopupView`.
23-
7. Use a `FloatingPanel` to display the popup information from the `PopupView`.
23+
7. Get the `AggregateGeoElement` from the `IdentifyLayerResult` and use `geoElements` to retrieve the contained `GeoElement` objects.
24+
8. Use a `FloatingPanel` to display the popup information from the `PopupView` and the list containing the `GeoElement` objects.
2425

2526
## Relevant API
2627

Shared/Samples/Display clusters/README.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"category": "Visualization",
2+
"category": "Layers",
33
"description": "Display a web map with a point feature layer that has feature reduction enabled to aggregate points into clusters.",
44
"ignore": false,
55
"images": [

0 commit comments

Comments
 (0)