0

I have created a feature service on ArcGIS online which has approximately 2000 features. Each feature has four fields: name, latitude, longitude and a boolean validation field (true/false). Two custom symbols are used - one for validated features and one for non-validated features. I have successfully connected to the feature service from my native (xcode/swift) iOS application and the features are displayed properly on top of the basemap. I have implemented a touch delegate and successfully detect when a feature symbol is tapped. The issue I am having is trying to query (read) the "name" field attribute associated with the symbol that was tapped. I have tried using the code below but have not been able to read the attribute:

 func geoView(_ geoView: AGSGeoView, didTapAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {

    if let activeSelectionQuery = activeSelectionQuery {
        activeSelectionQuery.cancel()
    }
    guard let featureLayer = featureLayer else {
        return
    }
    //tolerance level
    let toleranceInPoints: Double = 12
    //use tolerance to compute the envelope for query
    let toleranceInMapUnits = toleranceInPoints * viewMap.unitsPerPoint
    let envelope = AGSEnvelope(xMin: mapPoint.x - toleranceInMapUnits,
                               yMin: mapPoint.y - toleranceInMapUnits,
                               xMax: mapPoint.x + toleranceInMapUnits,
                               yMax: mapPoint.y + toleranceInMapUnits,
                               spatialReference: viewMap.map?.spatialReference)

    //create query parameters object
    let queryParams = AGSQueryParameters()
    queryParams.geometry = envelope


    //run the selection query
    activeSelectionQuery = featureLayer.selectFeatures(withQuery: queryParams, mode: .new) { [weak self] (queryResult: AGSFeatureQueryResult?, error: Error?) in
        if let error = error {
            print("error: ",error)
        }
        if let result = queryResult {
            print("\(result.featureEnumerator().allObjects.count) feature(s) selected")
            print("name: ", result.fields)
        }
    }
}

I am using the ArGIS iOS 100.6 SDK. Any help would be appreciated in solving this issue.

4

1 回答 1

0

The featureLayer selection methods merely update the map view display to visually highlight the features.

From the featureLayer, you should get the featureTable and then call query() on that. Note that there are two methods. A simple query() that gets minimal attributes back, or an override on AGSServiceFeatureTable that allows you to specify that you want all fields back. You might need to specify .loadAll on that override to get the name field back. We do it this way to avoid downloading too much information (by default we download enough to symbolize and label the feature).

于 2019-11-12T18:36:18.967 回答