I'm currently migrating from 100.15.x to 200.4 and am having trouble with clustering graphics. I have a dynamic graphic overlay using a unique value renderer that has 1 field name, entirely comprised of graphics with point geometry. I've tried to create a ClusteringFeatureReduction with a simple renderer and simple marker symbol to add to the overlay but after adding it all of the graphics no longer appear. I've tried tweaking radius, maxSymbolSize, minSymbolSize, maxScale, but nothing seems to have an effect. I believe I've gone through all of the feature reduction for graphic overlays documentation and (feature layer clustering) samples but can't seem to get it to work. Is there anything else that I need to consider? Help will be greatly appreciated.
Hi Jacob, thanks for reporting this issue. I'll check with our team to see if this is a bug.
Meanwhile, can you try adding the ClusteringFeatureReduction after the map is loaded, to see if it helps?
Below is a code snippet for testing purposes.
import SwiftUI
import ArcGIS
struct ContentView: View {
@State private var map: Map = {
let map = Map(basemapStyle: .arcGISLightGray)
map.initialViewpoint = Viewpoint(
center: Point(x: -117.17, y: 34.17, spatialReference: .wgs84),
scale: 1e5
)
return map
}()
@State private var graphicsOverlay: GraphicsOverlay = {
let overlay = GraphicsOverlay()
overlay.renderingMode = .dynamic
return overlay
}()
var body: some View {
MapView(map: map, graphicsOverlays: [graphicsOverlay])
.task {
try? await map.load()
setupGraphicsOverlay()
addPointsToOverlay()
}
}
private func setupGraphicsOverlay() {
// Create a unique value renderer
let symbol = SimpleMarkerSymbol(
style: .circle,
color: .blue,
size: 10
)
let uniqueValueRenderer = UniqueValueRenderer(
fieldNames: ["type"],
uniqueValues: [
UniqueValue(
description: "Point",
label: "Point",
symbol: symbol,
values: ["Point"]
)
]
)
graphicsOverlay.renderer = uniqueValueRenderer
// Set up clustering feature reduction.
let clusterSymbol = SimpleMarkerSymbol(
style: .circle,
color: .red,
size: 10
)
let clusterRenderer = SimpleRenderer(symbol: clusterSymbol)
let clusteringFeatureReduction = ClusteringFeatureReduction(renderer: clusterRenderer)
graphicsOverlay.featureReduction = clusteringFeatureReduction
}
private func addPointsToOverlay() {
// Coordinates for points near Redlands, CA
let coordinates = [
Point(x: -117.17, y: 34.15, spatialReference: .wgs84),
Point(x: -117.18, y: 34.16, spatialReference: .wgs84),
Point(x: -117.19, y: 34.17, spatialReference: .wgs84),
Point(x: -117.20, y: 34.18, spatialReference: .wgs84),
Point(x: -117.21, y: 34.19, spatialReference: .wgs84),
Point(x: -117.22, y: 34.20, spatialReference: .wgs84)
]
// Add points to the graphics overlay
for coordinate in coordinates {
let graphic = Graphic(geometry: coordinate, attributes: ["type": "Point"])
graphicsOverlay.addGraphic(graphic)
}
}
}
Hello, thank you for the reply. I tried with the above code and I'm still experiencing the same issue. I messed around with this quite a bit today and the only way I was able to get it to work consistently was if I suspended the task for a split second prior to loading the map.
.task() {
try? await Task.sleep(nanoseconds: 200_000_000)
try? await map.load()
setupGraphicsOverlay()
addPointsToOverlay()
}
I've logged an internal issue, sounds like a timing bug 😕 . Will keep you posted on the progress…
Thanks for reporting it again!
An update: it is still a bug that we are trying to solve - we added more reproducible cases to the internal ticket.
Another update - this issue will be fixed in the upcoming 200.6.0 release.
Do you have a target date for that release?
Towards the end of November and early December.