Click on symbols to show a small text field

404
2
Jump to solution
05-25-2023 05:11 AM
padmalcom
Occasional Contributor

We draw several graphics in a GraphicsOverlay. We want our users to touch these graphics and show a small hint, some kind of ballon. But there does not seem to be something like a touch event. Maybe a popup is the right object for such a ballon but to be honest: I don't know what it is, since it is not documented.

Can you help me out here?

0 Kudos
1 Solution

Accepted Solutions
Shubham_Sharma
Esri Contributor

You will need to retrieve the list of feature layers as part of the `FeatureCollectionLayer`: 

featureCollectionLayer.layers

 

Then you can get the selected features using the same function used in the Select features in feature layer sample: v100.15 sample, v200.0 sample 

 

val featureCollectionLayer: FeatureCollectionLayer =
    FeatureCollectionLayer(featureCollection)
featureCollectionLayer.layers.collect { featureLayerList ->
    featureLayerList.forEach { featureLayer ->
        // function used in "Select features in feature layer" sample
        getSelectedFeatureLayer(screenCoordinate, featureLayer)
    }
}

 

 

Here is a snippet of the function from the ArcGIS Maps SDK Kotlin sample (v200.0): 

 

/**
 * Displays the number of features selected on the given [screenCoordinate]
 */
private suspend fun getSelectedFeatureLayer(
    screenCoordinate: ScreenCoordinate,
    featureLayer: FeatureLayer
) {
    // clear the previous selection
    featureLayer.clearSelection()
    // set a tolerance for accuracy of returned selections from point tapped
    val tolerance = 25.0
    // create a IdentifyLayerResult using the screen coordinate
    val identifyLayerResult = mapView.identifyLayer(
        layer = featureLayer,
        screenCoordinate = screenCoordinate,
        tolerance = tolerance,
        returnPopupsOnly = false,
        maximumResults = -1
    )
    // handle the result's onSuccess and onFailure
    identifyLayerResult.apply {
        onSuccess { identifyLayerResult ->
            // get the elements in the selection that are features
            val features = identifyLayerResult.geoElements.filterIsInstance<Feature>()
            // add the features to the current feature layer selection
            featureLayer.selectFeatures(features)
            Snackbar.make(mapView, "${features.size} features 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()
        }
    }
}

 

 

Hopefully you find this code snippet helpful for your use case! 

 

- Here's a related question regarding the popup component for v200.0:

https://community.esri.com/t5/kotlin-maps-sdk-questions/how-to-show-popup-view-in-kotlin-maps-sdk/m-...

Currently, you can create a popup graphic by adding text to a graphic and adding it to the graphics overlay at the tapped location to emulate the popup behavior. 

Visit the sample, Render multilayer symbols to checkout how to work with multilayer symbols to add graphics with text and a fill symbol. 

Visit the sample, Style graphics with renderer to checkout how to style graphics to custom shapes/geometries to create your own popup symbol shape. 

 

 

View solution in original post

2 Replies
padmalcom
Occasional Contributor

A switched from GraphicsOveray to a FeatureCollectionLayer to display features as proposed here: https://community.esri.com/t5/kotlin-maps-sdk-questions/create-empty-featurelayer-and-fill-manually-...

Now, I try to follow this tutorial on making features clickable: https://github.com/Esri/arcgis-runtime-samples-android/blob/main/kotlin/feature-layer-selection/src/...

Unfortunately, a FeatureCollectionLayer has no attributes to get or set selected features. Or am I looking at the wrong object?

0 Kudos
Shubham_Sharma
Esri Contributor

You will need to retrieve the list of feature layers as part of the `FeatureCollectionLayer`: 

featureCollectionLayer.layers

 

Then you can get the selected features using the same function used in the Select features in feature layer sample: v100.15 sample, v200.0 sample 

 

val featureCollectionLayer: FeatureCollectionLayer =
    FeatureCollectionLayer(featureCollection)
featureCollectionLayer.layers.collect { featureLayerList ->
    featureLayerList.forEach { featureLayer ->
        // function used in "Select features in feature layer" sample
        getSelectedFeatureLayer(screenCoordinate, featureLayer)
    }
}

 

 

Here is a snippet of the function from the ArcGIS Maps SDK Kotlin sample (v200.0): 

 

/**
 * Displays the number of features selected on the given [screenCoordinate]
 */
private suspend fun getSelectedFeatureLayer(
    screenCoordinate: ScreenCoordinate,
    featureLayer: FeatureLayer
) {
    // clear the previous selection
    featureLayer.clearSelection()
    // set a tolerance for accuracy of returned selections from point tapped
    val tolerance = 25.0
    // create a IdentifyLayerResult using the screen coordinate
    val identifyLayerResult = mapView.identifyLayer(
        layer = featureLayer,
        screenCoordinate = screenCoordinate,
        tolerance = tolerance,
        returnPopupsOnly = false,
        maximumResults = -1
    )
    // handle the result's onSuccess and onFailure
    identifyLayerResult.apply {
        onSuccess { identifyLayerResult ->
            // get the elements in the selection that are features
            val features = identifyLayerResult.geoElements.filterIsInstance<Feature>()
            // add the features to the current feature layer selection
            featureLayer.selectFeatures(features)
            Snackbar.make(mapView, "${features.size} features 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()
        }
    }
}

 

 

Hopefully you find this code snippet helpful for your use case! 

 

- Here's a related question regarding the popup component for v200.0:

https://community.esri.com/t5/kotlin-maps-sdk-questions/how-to-show-popup-view-in-kotlin-maps-sdk/m-...

Currently, you can create a popup graphic by adding text to a graphic and adding it to the graphics overlay at the tapped location to emulate the popup behavior. 

Visit the sample, Render multilayer symbols to checkout how to work with multilayer symbols to add graphics with text and a fill symbol. 

Visit the sample, Style graphics with renderer to checkout how to style graphics to custom shapes/geometries to create your own popup symbol shape.