Feature Table for IdentifyLayerResult

224
5
Jump to solution
12-21-2019 07:55 AM
nafotoisrael
New Contributor

Hello, I'm using this this guide to identify which layers were clicked on MapView.

it works perfectly for every layers I have except from Feature Collection Layers. where the attributes are in a feature table and not elements.

how do I get the attributes inside a feature table?

to identify layers:

fun identifyClickedLayerResults(point: android.graphics.Point, mMap: MapView, callback: (MutableList<IdentifyLayerResult>) -> Unit){
val TAG = "ClickedLayerResults"
var identifyLayerResult: MutableList<IdentifyLayerResult>
val identifyLayerResultsFuture = mMap
.identifyLayersAsync(point, 12.0, false, 5)

identifyLayerResultsFuture.addDoneListener {
try {
identifyLayerResult = identifyLayerResultsFuture.get()
callback(identifyLayerResult)

} catch (e: InterruptedException) {
Log.e(TAG, "Error identifying results: " + e.message)
} catch (e: ExecutionException) {
Log.e(TAG, "Error identifying results: " + e.message)
}
}
}

to get attributes: 

fun layerDetails(forLayer: IdentifyLayerResult): ArrayList<Map<String, String>>{
val resultGeoElements = forLayer.elements
if (forLayer.layerContent.name == "Feature Collection"){
//doesn't work here
}
var mAttributesString = ArrayList<String>()
var layersAttributeList = ArrayList<Map<String, String>>()

if (!resultGeoElements.isEmpty()){
resultGeoElements.forEach {
if (it is ArcGISFeature){
val mArcGISFeature = it as? ArcGISFeature
mAttributesString.add(mArcGISFeature?.attributes.toString())
var mTempMap = mutableMapOf<String, String>()
mArcGISFeature?.attributes?.forEach {
if (!it.value.toString().isEmpty() && !it.key.toString().isEmpty()
&& !it.key.toString().contains(".FID"))
mTempMap[it.key.toString()] = it.value.toString()
}
layersAttributeList.add(mTempMap)
}
}

}

return layersAttributeList
}

what i got now : 

private fun featureCollectionDetails(forLayer: IdentifyLayerResult){
var featureCollectionLayer = forLayer.layerContent as FeatureCollectionLayer
var mFeatureTable = featureCollectionLayer.layers[0].featureTable

}

the code is in kotlin, its ok if the answer will be in java

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Actually, looking at your code, I must not understand what you're trying to achieve. I'm not an Android dev, but it looks like you're stripping out all the attributes from all the identified features, converting each attribute value to a string (is there a reason you want to discard the type info here?), and putting a Map of these converted values in a list - one Map for each feature.

If you're saying that in the case of a Feature Collection you're not getting any GeoElements back to read the attributes from, have you tried looking at the subLayerResults?

View solution in original post

5 Replies
Nicholas-Furness
Esri Regular Contributor

If I understand your question properly, you're nearly there! Each FeatureTable has Fields you can read. See getFields().

Does that help?

0 Kudos
nafotoisrael
New Contributor

fields only return field aliases, is there any way to get attributes for the table?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Fields returns you a list of Field objects. Each Field has a Name and an Alias: Field (ArcGIS Runtime SDK for Android 100.7.0) 

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Actually, looking at your code, I must not understand what you're trying to achieve. I'm not an Android dev, but it looks like you're stripping out all the attributes from all the identified features, converting each attribute value to a string (is there a reason you want to discard the type info here?), and putting a Map of these converted values in a list - one Map for each feature.

If you're saying that in the case of a Feature Collection you're not getting any GeoElements back to read the attributes from, have you tried looking at the subLayerResults?

View solution in original post

nafotoisrael
New Contributor

brilliant! subLayerResults solved it! I was looking at the wrong place

thank you dearly

0 Kudos