Select to view content in your preferred language

mapViewProxy.identifyGraphicsOverlays returns only one object per layer

299
3
Jump to solution
10-10-2024 02:35 AM
zdtorok
Occasional Contributor

I have added multiple objects to the same coordinate and layer. I have four layers and tried adding multiple objects for each layers but when I tap on the object it returns an array only with 4 elements - one per layer.

I also set maximumResultsPerOverlay to both a high number and to nil as well - neither of these worked.

The code I refer to:

ArcGIS.MapViewReader { proxy in
            ArcGIS.MapView(map: model.map,
                           viewpoint: model.viewpoint,
                           graphicsOverlays: model.graphicsOverlays)
            .onSingleTapGesture { screenPoint, mapPoint in
                onSingleTapGesture(screenPoint: screenPoint, mapPoint: mapPoint, proxy: proxy)
            }
            ...
        }
    }

    private func onSingleTapGesture(screenPoint: CGPoint, mapPoint: ArcGIS.Point, proxy: ArcGIS.MapViewProxy) {
        Task {
            guard !model.geometryEditor.isStarted,
                  let identifiedGraphicsOverlays = try? await proxy.identifyGraphicsOverlays(screenPoint: screenPoint,
                                                                                             tolerance: 100,
                                                                                             maximumResultsPerOverlay: 😎 else {
                return
            }
            // Here identifiedGraphicsOverlays.count = 4
            ...
        }
    }

I'm using v200.5.1.

Is it a known issue?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

I see. The problem is that each "result" (IdentifyGraphicsOverlayResult type) contains the identified geo-elements for a single graphics overlay. You can access the identified geo-elements, or in this case, the graphics, in each result object, with identifyResult.graphics.

See the following code snippet as an example

 

struct ContentView: View {
    @State private var map = Map(basemapStyle: .arcGISLightGray)
    
    @State private var graphicsOverlays: [GraphicsOverlay] = {
        let g1 = Graphic(geometry: Point(latitude: 34.05, longitude: -117), symbol: SimpleMarkerSymbol(color: .red))
        let g2 = Graphic(geometry: Point(latitude: 33.95, longitude: -117), symbol: SimpleMarkerSymbol(color: .blue))
        let g3 = Graphic(geometry: Point(latitude: 34, longitude: -117.05), symbol: SimpleMarkerSymbol(color: .yellow))
        let g4 = Graphic(geometry: Point(latitude: 34, longitude: -116.95), symbol: SimpleMarkerSymbol(color: .green))
        
        let overlay1 = GraphicsOverlay(graphics: [g1, g2])
        let overlay2 = GraphicsOverlay(graphics: [g3, g4])
        return [overlay1, overlay2]
    }()
    
    @State private var screenPoint: CGPoint?
    
    var body: some View {
        MapViewReader { proxy in
            MapView(map: map, graphicsOverlays: graphicsOverlays)
                .onSingleTapGesture { screenPoint, _ in
                    self.screenPoint = screenPoint
                }
                .task(id: screenPoint) {
                    guard let screenPoint,
                          let identifyResult = try? await proxy.identifyGraphicsOverlays(
                            screenPoint: screenPoint,
                            tolerance: 10,
                            maximumResultsPerOverlay: nil  // nil means unlimited result count
                          )
                    else {
                        return
                    }
                    print(identifyResult.count) // 2 because we have 2 overlays
                    print(identifyResult.flatMap(\.graphics).count)  // 4 because we have 4 graphics
                }
        }
    }
}

 

 

View solution in original post

0 Kudos
3 Replies
Ting
by Esri Contributor
Esri Contributor

Just want to clarify, are you trying to identify on layers or graphics overlays?

The former uses this API: identifyLayers(screenPoint:tolerance:returnPopupsOnly:maximumResultsPerLayer:), whereas the latter uses this: identifyGraphicsOverlays(screenPoint:tolerance:returnPopupsOnly:maximumResultsPerOverlay:)

0 Kudos
zdtorok
Occasional Contributor
0 Kudos
Ting
by Esri Contributor
Esri Contributor

I see. The problem is that each "result" (IdentifyGraphicsOverlayResult type) contains the identified geo-elements for a single graphics overlay. You can access the identified geo-elements, or in this case, the graphics, in each result object, with identifyResult.graphics.

See the following code snippet as an example

 

struct ContentView: View {
    @State private var map = Map(basemapStyle: .arcGISLightGray)
    
    @State private var graphicsOverlays: [GraphicsOverlay] = {
        let g1 = Graphic(geometry: Point(latitude: 34.05, longitude: -117), symbol: SimpleMarkerSymbol(color: .red))
        let g2 = Graphic(geometry: Point(latitude: 33.95, longitude: -117), symbol: SimpleMarkerSymbol(color: .blue))
        let g3 = Graphic(geometry: Point(latitude: 34, longitude: -117.05), symbol: SimpleMarkerSymbol(color: .yellow))
        let g4 = Graphic(geometry: Point(latitude: 34, longitude: -116.95), symbol: SimpleMarkerSymbol(color: .green))
        
        let overlay1 = GraphicsOverlay(graphics: [g1, g2])
        let overlay2 = GraphicsOverlay(graphics: [g3, g4])
        return [overlay1, overlay2]
    }()
    
    @State private var screenPoint: CGPoint?
    
    var body: some View {
        MapViewReader { proxy in
            MapView(map: map, graphicsOverlays: graphicsOverlays)
                .onSingleTapGesture { screenPoint, _ in
                    self.screenPoint = screenPoint
                }
                .task(id: screenPoint) {
                    guard let screenPoint,
                          let identifyResult = try? await proxy.identifyGraphicsOverlays(
                            screenPoint: screenPoint,
                            tolerance: 10,
                            maximumResultsPerOverlay: nil  // nil means unlimited result count
                          )
                    else {
                        return
                    }
                    print(identifyResult.count) // 2 because we have 2 overlays
                    print(identifyResult.flatMap(\.graphics).count)  // 4 because we have 4 graphics
                }
        }
    }
}

 

 

0 Kudos