esri-mapsarcgis-android-api

How to set Opacity to a selected Graphic in ESRI map


In my android app I am adding a picture marker symbol on ESRI map using PictureMarkerSymbol class(using Kotlin) like:

val markerSymbol = PictureMarkerSymbol.createAsync(ContextCompat.getDrawable(context!!, icon) as BitmapDrawable?).get()

Here am adding multiple markers on map by setting default opacity of symbol and adding it to overlay like:

        markerSymbol.opacity = 0.3f
        //add a new graphic as marker point
        val markerGraphicPoint = Point(activeCall.lang, activeCall.lat, spatialReference)
        val graphic = Graphic(markerGraphicPoint, markerSymbol)

        graphicsOverlay.graphics.add(graphic)

Now I want to set the opacity to a selected graphic(Anyway I am getting the selected graphic symbol from an array). I can get the symbol from selected graphic like:

selectedGraphic?.symbol

I want to set opacity to selected symbol something like:

selectedGraphic?.symbol = 1.0f // Need this one

But how to set the opacity to it, there is no setOpacity in this symbol class

OR how to get the PictureMarkerSymbol from the selected Graphic.?

I tried by cast it to PictureMarkerSymbol this way:

selectedMarker?.symbol as PictureMarkerSymbol

but here I am getting class cast exception

Also tried:

val markerGraphicsOverlay = selectedMarker?.graphicsOverlay
markerGraphicsOverlay?.opacity = 0.1f

but same result.


Solution

  • Cast Symbol to PictureMarkerSymbol

    if (selectedGraphic!= null && selectedGraphic?.symbol != null) {
        val pictureMarkerSymbol = selectedGraphic?.symbol as PictureMarkerSymbol
    }