WebMap popup definitions not honored in 100.1

653
2
Jump to solution
10-01-2017 10:04 AM
by Anonymous User
Not applicable

In previous versions (10.2.5) of the ArcGIS Runtime for iOS, I have been able to reference a web map when instantiating the AGSPopupsContainerViewController like this:

// Iniitalize popup view controller
self.popupVC = AGSPopupsContainerViewController(webMap: self.webMap, forFeature: self.newSighting, usingNavigationControllerStack: false)
self.popupVC.delegate = self‍‍‍

In the Quartz release the AGSWebMap class has been deprecated and the new popup vc class is AGSPopupViewController, which does not have an option to use a web map or an Item ID.  When creating a map, I can still reference a web map like below and the layers within come in symbolized correctly, but the popups view controller does not seem to honor the popup definition set in the web map. 

override func viewDidLoad() {
        super.viewDidLoad()
        
        // reference map and mapView
        self.map = AGSMap(url: URL(string: "https://www.arcgis.com/home/webmap/viewer.html?webmap=" + webmapID)!)
        self.mapView.map = self.map
        
        // set touch delegate for identify
        self.mapView.touchDelegate = self
        
        //register as an observer for loadStatus property on map
        self.map.addObserver(self, forKeyPath: "loadStatus", options: .new, context: nil)
    }


// poups view controller is defined in this
//MARK: - AGSGeoViewTouchDelegate to handle identify on touch
    func geoView(_ geoView: AGSGeoView, didTapAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {
        if let lastQuery = self.lastQuery{
            lastQuery.cancel()
        }
        
        self.lastQuery = self.mapView.identifyLayer(self.breweries, screenPoint: screenPoint, tolerance: 12, returnPopupsOnly: false, maximumResults: 10) { [weak self] (identifyLayerResult: AGSIdentifyLayerResult) -> Void in
            if let error = identifyLayerResult.error {
                print(error)
            }
            else if let weakSelf = self {
                
                // get popups from touch results
                var popups = [AGSPopup]()
                let geoElements = identifyLayerResult.geoElements
                
                for geoElement in geoElements {
                    
                    let popup = AGSPopup(geoElement: geoElement)
                    popups.append(popup)
                }
            
                if popups.count > 0 {
                    weakSelf.popupsVC = AGSPopupsViewController(popups: popups, containerStyle: .navigationBar)
                    
                    // set custom action button to display directions in apple maps
                    let directionsBtn: UIBarButtonItem = UIBarButtonItem()
                    directionsBtn.title = "Directions"
                    directionsBtn.width = CGFloat(100)
                    directionsBtn.action = #selector(ViewController.getAppleDirections) // call our function
                    directionsBtn.target = weakSelf
                    weakSelf.popupsVC.customActionButton = directionsBtn
                    
                    
                    weakSelf.popupsVC.modalPresentationStyle = .formSheet
                    weakSelf.present(weakSelf.popupsVC, animated: true, completion: nil)
                    weakSelf.popupsVC.delegate = weakSelf
                }
            }
        }
    }

However, when I identify features the popup shows all the fields, not how the popup is configured in the web map.  I have never used the Quartz release until this app, am I missing something for getting the popup definition from the web map?

0 Kudos
1 Solution

Accepted Solutions
MarkDostal
Esri Contributor

Thank you for your question!  As you've figured out, `AGSMap` has replaced `AGSWebMap` in the latest SDK.  The functionality you want is still there, it's just accessed in a slightly different way.

The simplest way to honor web map popup definitions is to set the `returnPopupsOnly` argument of `identifyLayer` to `true`. This will cause the identify operation to only return geoElements which have popups (and popupDefinitions).

Alternately, when creating your `AGSPopup`, use the initializer which has the `popupDefinition` argument and supply the popupDefinition from the layer. Note that the layer must support the `AGSPopupSource` protocol; currently the following layers provide that support: `AGSGraphicsOverlay`, `AGSFeatureLayer`, `AGSFeatureTable`, `AGSRasterLayer`, and `AGSArcGISSublayer`

If you have any additional questions, let me know.

Mark

View solution in original post

0 Kudos
2 Replies
MarkDostal
Esri Contributor

Thank you for your question!  As you've figured out, `AGSMap` has replaced `AGSWebMap` in the latest SDK.  The functionality you want is still there, it's just accessed in a slightly different way.

The simplest way to honor web map popup definitions is to set the `returnPopupsOnly` argument of `identifyLayer` to `true`. This will cause the identify operation to only return geoElements which have popups (and popupDefinitions).

Alternately, when creating your `AGSPopup`, use the initializer which has the `popupDefinition` argument and supply the popupDefinition from the layer. Note that the layer must support the `AGSPopupSource` protocol; currently the following layers provide that support: `AGSGraphicsOverlay`, `AGSFeatureLayer`, `AGSFeatureTable`, `AGSRasterLayer`, and `AGSArcGISSublayer`

If you have any additional questions, let me know.

Mark

0 Kudos
by Anonymous User
Not applicable

Ah, I missed that in the help docs.  The first solution of setting the `returnPopupsOnly` to true did not work (even though there is a popup definition defined in the webmap).  However, it did work when when I passed in the feature layer's popup def when instantiating the AGSPopup.  Thanks!

0 Kudos