I have a feature layer that I can load up, view, and tap without issues. I'm able to see the built-in popup that ArcGIS provides that allows me to edit particular parts of each feature. Here is the code that I'm using.
let item = AGSPortalItem(portal: self.portal, itemID:"PORTALITEMID")
self.featureTable = AGSServiceFeatureTable(item: item, layerID: 0)
self.waypointFeatureLayer = AGSFeatureLayer(featureTable: self.featureTable)
self.mapView.map?.operationalLayers.add(waypointFeatureLayer!)
However, when I attempt to query the layers, I run into issues. The query works (I only see what I'm looking for), but I can't tap on any features. I get the following error.
Error Domain=com.esri.arcgis.runtime.error Code=2 "Invalid argument." UserInfo={NSLocalizedFailureReason=Unable to run identify on the specified layer.
Layer not identifiable
layer not found in view., NSLocalizedDescription=Invalid argument., Additional Message=Unable to run identify on the specified layer.
Layer not identifiable
layer not found in view.}
The code I'm using to identify the queried layer is as follows.
guard self.waypointFeatureCollectionLayer != nil else { return }
guard let featureLayer = self.waypointFeatureCollectionLayer.layers.first else {
fatalError()
}
mapView.identifyLayer(featureLayer, screenPoint: screenPoint, tolerance: 12, returnPopupsOnly: false) { [weak self] (result: AGSIdentifyLayerResult) in
guard let self = self else { return }
if let error = result.error {
log.error(error)
} else if !result.popups.isEmpty {
// Unselect the previous feature.
featureLayer.clearSelection()
// Select the new feature.
let features = result.geoElements as? [AGSFeature]
let selectedFeature = features?.first
featureLayer.select(selectedFeature!)
// Display a popup only if it exists.
let popupsViewController = AGSPopupsViewController(popups: result.popups)
// Display the popup as a formsheet -- specified for iPads.
popupsViewController.modalPresentationStyle = .formSheet
// Present the popup.
popupsViewController.delegate = self
self.present(popupsViewController, animated: true)
}
}
And the code to load the queried layer is...
let item = AGSPortalItem(portal: self.portal, itemID: "PORTALITEMID")
self.featureTable = AGSServiceFeatureTable(item: item, layerID: 0)
let queryParams = AGSQueryParameters()
if let primaryUser = CoreDataManager().getPrimaryUser() {
let clause = "CustomerID=\(primaryUser.id)"
queryParams.whereClause = clause
self.featureTable.queryFeatures(with: queryParams) { [weak self] (queryResult: AGSFeatureQueryResult?, error: Error?) in
if let error = error {
log.error("Error querying feature table: \(error)")
} else {
guard let queryResult = queryResult else { return }
let featureCollectionTable = AGSFeatureCollectionTable(featureSet: queryResult)
let featureCollection = AGSFeatureCollection(featureCollectionTables: [featureCollectionTable])
self?.waypointFeatureCollectionLayer = AGSFeatureCollectionLayer(featureCollection: featureCollection)
self?.mapView.map?.operationalLayers.add(self?.waypointFeatureCollectionLayer)
}
}
} else {
assertionFailure()
}
The one difference I notice is that the queried layer is actually a collection layer. When I run the identifyLayer above, I can find a reference to one layer by using collectionLayer.layers.first (note that this does return a result, so my assumption is it's the layer with my queried features)
Is there a way to make queried layers identifiable?
Side note...when I query layers they also show only small black dots, unlike the different types of dots (red/black) on the unqueried layers. I'm not sure if this is something by design or if there is a way to edit how they look after they are queried. The issue with tapping/editing the layers is more important however.
Notes:
Using arcgis-runtime-ios 100.11.2
Followed these docs
https://developers.arcgis.com/ios/swift/sample-code/feature-collection-layer-query/
https://developers.arcgis.com/ios/swift/sample-code/add-features-feature-service/
https://developers.arcgis.com/ios/swift/sample-code/show-popup/