1

I'm trying to use the match() Expression from Mapbox's Android SDK 9.0.0 with a list of ids. But I'm getting the following error at runtime:

"Error setting property: icon-image [2] Branch labels must be numbers or strings."

I am coding in Kotlin.

To isolate the essence of the problem, I'm trying to pass match() an array of a single String element using the arrayOf() operator:

match(get(KEY_ID), literal(arrayOf("134")), appearanceIfSelected, appearanceIfNotSelected)

The code above didn't work though and gave the error above. The following code that used arrayListOf() also failed:

match(get(KEY_ID), literal(arrayListOf(pois!!.first().id)), appearanceIfSelected, appearanceIfNotSelected)

listOf() also failed:

match(get(KEY_ID), literal(listOf(pois!!.first().id)), appearanceIfSelected, appearanceIfNotSelected)

Wrapping in array() failed too:

match(get(KEY_ID), array(literal(listOf("134"))), appearanceIfSelected, appearanceIfNotSelected)

I have been wrapping in literal() because the following won't even compile:

match(get(KEY_ID), arrayOf("134"), appearanceIfSelected, appearanceIfNotSelected)
Michael Osofsky
  • 11,429
  • 16
  • 68
  • 113

1 Answers1

0

As a workaround, I replaced match() with any() and passed a variable number of arguments using the Kotlin spread operator "*"

val eqPOIIdExpressions = arrayOf(eq(get(KEY_ID), "134"))

// The * operator below converts the Array<Expression> into varargs for any
// see https://proandroiddev.com/kotlins-vararg-and-spread-operator-4200c07d65e1

switchCase(
    any(*eqPOIIdExpressions), appearanceIfSelected,
    appearanceIfNotSelected
)

Once I got that working, I went ahead and added all the array elements:

val eqPOIIdExpressions = pois!!.map {
    eq(get(KEY_ID), it.id)
}.toTypedArray()
Michael Osofsky
  • 11,429
  • 16
  • 68
  • 113