swift - Cannot Query Feature Attributes from ArcGIS Online Feature Service
问题描述
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.
解决方案
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).
推荐阅读
- docker - microk8s拉镜像,卡在ContainerCreating状态
- python - Leetcode中ListNode的Python逻辑
- regex - 不要在正则表达式中捕获可选的 html 标记
- mysql - Mysql SELECT ... WHERE IN(从多个表中选择多个子)
- java - 无法在 Jira 客户端中捕获 SSLHandshakeException
- c# - MVC:显示分组列表的视图
- angular - 如何在spring boot中处理angular对JSON对象的put请求?
- javascript - 如果 PHP 中的编码字符串包含 Unicode 字符,则无法在 JavaScript 中解码
- python - 使用python删除单个对象上未使用的材料
- wordpress - 如何阻止从我的 wordpress 网站获取请求