SymbolLayer listening event Kotlin

  android, kotlin, mapbox

I am trying to implement a code in kotlin which displays an image in my case a button has a given position (I use mapBox)
I managed to display my button using a SymbolLayer at a given position, however I cannot implement the listener of this SymbolLayer

fun displayButton(lat: Double, lng: Double) {

            if (button == 0) {
                val symbolLayerIconFeatureList: MutableList<Feature> = ArrayList()
                symbolLayerIconFeatureList.add(Feature.fromGeometry(
                        Point.fromLngLat(lng, lat)))
                mapboxMap?.getStyle { style ->

                    //set position
                    style.addSource(GeoJsonSource(MARKER_SOURCE_ID, FeatureCollection.fromFeatures(symbolLayerIconFeatureList)))

                    // Add the marker image
                    style.addImage(MARKER_IMAGE_ID, BitmapFactory.decodeResource(parentContext.resources, R.drawable.epuratrion_button))

                    //adding an offset
                    symbolLayer = SymbolLayer(MARKER_LAYER_ID, MARKER_SOURCE_ID)
                            .withFilter(eq((get(PROPERTY_SELECTED)), literal(true)))

                            .withProperties(iconImage(MARKER_IMAGE_ID),
                                    iconAllowOverlap(true),
                                    iconOffset(arrayOf(0f, -9f)))

                    style.addLayer(symbolLayer!!)

                }
                button += 1
            }
    }

I added a "button" status variable which allows me to display a single button because when I display several buttons the application crashes
If you have a solution, I’m interested

Source: Android Questions

LEAVE A COMMENT