Hi,
I'm using a FeatureCollectionLayer to load custom geometry and attributes on my map. I have no problem displaying points on the map. But I do have an issue when selecting a feature.
Here is how I'm calling the tap method:
lifecycleScope.launch {
mapView.onSingleTapConfirmed.collect { event ->
selectFeature(event.screenCoordinate)
}
}Here's the method to select feature:
private suspend fun selectFeature(coordinate: ScreenCoordinate) {
val layer = featureCollectionLayer.layers.value[0]
layer.clearSelection()
val layerResult = mapView.identifyLayer(layer, coordinate, 25.0, false, -1)
layerResult.apply {
onSuccess { result ->
val features = result.geoElements.filterIsInstance<Feature>()
if (features.isEmpty()) {
Log.d(localClassName, "No feature selected")
return@onSuccess
}
val selectedFeature = features[0]
layer.selectFeatures(features)
Snackbar.make(
mapView,
"${selectedFeature.attributes["Name"]} selected",
Snackbar.LENGTH_SHORT
).show()
}
onFailure {
val errorMessage = "Select feature failed: " + it.message
Log.e(localClassName, errorMessage)
Snackbar.make(mapView, errorMessage, Snackbar.LENGTH_SHORT).show()
}
}
}Based on what I have logged ("No feature selected"), it seems there are no features, but the points do display. If anyone can see an issue, that would be greatly appreciated.
Thanks,
Dave