'MapBox Android: How to dynamically set the iconOffset property in a SymbolLayer?

MapBox version: 9.5.0

I'm trying to make my MapBox SymbolLayer to dynamically set the iconOffset value for each feature in my source. I have several different types of mark designs, some which needs to be slightly offset depending on the content of the view. Im using SymbolLayer instead of Annotation Views because i need to support a large number of map marks and performance is key.

When creating the features i'm adding the property values for the offset

private fun createMark(mark: MapMark<out Any>, onFinish: (Feature) -> Unit) {
        mark.createViewHolder(context) { holder ->
            style?.addImage(holder.imageId, holder.renderedBitmap)
            val feature = Feature.fromGeometry(mark.getMapBoxPoint(converter)).apply {
                addStringProperty(PROP_ICON, holder.imageId)
                addStringProperty(PROP_ID, holder.id)
                addBooleanProperty(PROP_FOCUSED, false)
                addBooleanProperty(PROP_CLUSTERABLE, mark.isClusterable)
                
                // mark.offsetX/Y is of type Float
                addNumberProperty(PROP_OFFSET_X, mark.offsetX) 
                addNumberProperty(PROP_OFFSET_Y, mark.offsetY)

            }

            onFinish(feature)
        }

In my SymbolLayer i now need to get the offset values from the feature to set the iconOffset, which can be different depending on the layout of the symbol feature.

mMarkerLayer = SymbolLayer(MARKER_LAYER_ID, SOURCE_ID).withProperties(
            iconImage(get(PROP_ICON)),
            iconAnchor(Property.ICON_ANCHOR_BOTTOM),
            iconOffset(arrayOf(0f, 0f)), <-- This needs to be set from feature props 
            iconAllowOverlap(true),
            iconOpacity(get(PROP_TRANSPARENCY)),
            iconSize(options.mapMark.scaleSize),
           
        ).withFilter(
            all(
                eq(
                    get(PROP_VISIBLE), literal(true)
                ),
                eq(
                    get(PROP_FOCUSED), literal(false)
                )
            )
        )

I've been trying create an expression to set the iconOffset but with no success and realising that I have yet to master MapBox expressions. Hoping anyone out there can help me create this expression or convince me that it's impossible.

I've tried out different combinations but it does not work:

iconOffset(
    literal(
        arrayOf(
            switchCase(
                has(PROP_OFFSET_X), get(PROP_OFFSET_X),
                    literal(0f)
                ),
            switchCase(
                has(PROP_OFFSET_Y), get(PROP_OFFSET_Y),
                    literal(0f)
            )
        )
    )
),

iconOffset(
    literal(
        arrayOf(
            literal(toNumber(get((PROP_OFFSET_X)))),
            literal(toNumber(get((PROP_OFFSET_Y))))
        )
    )
)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source