Display popup with multiple feature layers information

666
3
Jump to solution
10-08-2021 08:06 AM
RaymondLi
New Contributor III

Hi,

The requirement of the App is when user tap on the location, it will display a popup with all the visible and related feature layer information. How can I do it?

 

// MARK: - AGSGeoViewTouchDelegate
    func geoView(_ geoView: AGSGeoView, didTapAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {


        
        // Identify graphics at the tapped location.
                mapView.identifyLayers(atScreenPoint: screenPoint,
                                       tolerance: 10,
                                       returnPopupsOnly: false,
                                       maximumResultsPerLayer: 20
                ) { [weak self] (results, error)  in
                    //check for errors and ensure identifyLayerResults is not nil
                    if let error = error {
                        print(error)
                        return
                    }
                    guard let identifyLayerResults = results,
                    let self = self else { return }

                    var resultCount:Int = 0
                    print("identifyLayerResults.count = \(identifyLayerResults.count)")
                    
                    // Loop through all results and get the count for those.
                    for identifyLayerResult in identifyLayerResults {
                        resultCount += self.getIdentifyLayerResultCount(identifyLayerResult)
                    }
                    if resultCount > 0 {
//Want to add code here to display the result in the popups with more than one from feature layers
                    }
                    print("result count = \(resultCount)")
                }
    }

func getIdentifyLayerResultCount(_ identifyLayerResult: AGSIdentifyLayerResult) -> Int {
            var resultCount: Int = 0
            resultCount += identifyLayerResult.geoElements.count
            
            //process the sublayer results for each layer (e.g. for map image layers)
            print("identifyLayerResult.sublayerResults.count = \(identifyLayerResult.sublayerResults.count)")
            // Loop through each subLayerResult recursively and get their count.
            for subLayerResult in identifyLayerResult.sublayerResults {
                resultCount += getIdentifyLayerResultCount(subLayerResult)
            }

            return resultCount
        }

 

 

0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

First, if you only want to identify features with popup configured, set `returnPopupsOnly` to true.

To get the pre-defined popup on the layer, you'll need to get them from the appropriate `AGSIdentifyLayerResult`. It might be in the main results, or the `sublayerResults`. It depends on the sublayers tree structure. Maybe try the snippet below?

results.flatMap { $0.sublayerResults.flatMap { $0.popups } }

Alternately, when creating your `AGSPopup`, use the initializer which has the `popupDefinition` argument and supply the `popupDefinition` from the layer.

View solution in original post

0 Kudos
3 Replies
Ting
by Esri Contributor
Esri Contributor

Hi,

Here is a snippet to identify multiple layers in the map, and show all the popups for the results. When the popup view controller is shown, swipe left and right to browse all the popups - see the screenshot.

Does it do what you need?

 

mapView.identifyLayers(atScreenPoint: screenPoint, tolerance: 10, returnPopupsOnly: false, maximumResultsPerLayer: 10) { [weak self] (results: [AGSIdentifyLayerResult]?, error: Error?) in
    if let results = results {
        let popups = results.flatMap { $0.geoElements.map(AGSPopup.init) }  // results.flatMap { $0.popups } if the features already have popups configured in ArcGIS Pro.
        if !popups.isEmpty {
            let popupsViewController = AGSPopupsViewController(popups: popups, containerStyle: .navigationBar)
            popupsViewController.delegate = self
            self?.present(popupsViewController, animated: true)
        } else {
            self?.presentAlert(message: "No features identified.")
        }
    }
}

 

swipe.gif

0 Kudos
RaymondLi
New Contributor III

Ting,

 

Thank. However, I change the results to below.

results += results.flatMap { $0.sublayerResults }

let popups = results.flatMap { $0.geoElements.map(AGSPopup.init) }

then I am able to get the all the related feature layer's info show up in the popup.

However, the popup window is not same as what we have inside the ArcGIS Pro. It is a plain form with all the fields enable to display. We have configure each layer different on the ArcGIS Pro layer. How can we show the popup that match the ArcGIS Pro??

 

0 Kudos
Ting
by Esri Contributor
Esri Contributor

First, if you only want to identify features with popup configured, set `returnPopupsOnly` to true.

To get the pre-defined popup on the layer, you'll need to get them from the appropriate `AGSIdentifyLayerResult`. It might be in the main results, or the `sublayerResults`. It depends on the sublayers tree structure. Maybe try the snippet below?

results.flatMap { $0.sublayerResults.flatMap { $0.popups } }

Alternately, when creating your `AGSPopup`, use the initializer which has the `popupDefinition` argument and supply the `popupDefinition` from the layer.

0 Kudos