Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set textVariableAnchorOffset with an expression via the JSON converter #3100

Open
sargunv opened this issue Dec 19, 2024 · 0 comments
Open

Comments

@sargunv
Copy link
Collaborator

sargunv commented Dec 19, 2024

Describe the bug

MapLibre Compose uses MapLibre Native's Android/iOS JSON -> Expression converters to set layer properties. This works for most properties, but errors out on SymbolLayer.textVariableAnchorOffset. The error is different on iOS and Android:

Android: Nested literal arrays are not supported
iOS: -[NSConstantValueExpression getValue:]: unrecognized selector sent to instance 0x60000028c800

To Reproduce

On Android (Kotlin):

layer.setProperties(
  PropertyFactory.textVariableAnchorOffset(
    Expression.Converter.convert(
      JsonArray().apply {
        add("literal")
        add(JsonArray().apply {
          add("top")
          add(JsonArray().apply {
            add(0)
            add(1)
          })
          add("bottom")
          add(JsonArray().apply {
            add(0)
            add(-2)
          })
        })
      })
  )
)

On iOS (Kotlin via Obj-C interop)

layer.textVariableAnchorOffset =
  NSExpression.expressionWithMLNJSONObject(
    listOf(
      "literal", listOf(
        "top",
        NSValue.valueWithCGVector(
          CGVectorMake(0.0, 1.0)
        ),
        "bottom",
        NSValue.valueWithCGVector(
          CGVectorMake(0.0, -2.0)
        ),
      )
    )
  )

Expected behavior

Setting the value via the JSON converter should work the same as via literal/expressionForConstantValue.

Platform information:

  • maplibre-android-sdk = "11.7.1"
  • maplibre-ios = "6.9.0"

Additional context

Slack thread: https://osmus.slack.com/archives/C02B2CBSNBU/p1734582889691469

Interestingly, setting the value with a literal expression does work:

On Android:

layer.setProperties(
  PropertyFactory.textVariableAnchorOffset(
    Expression.literal(
      arrayOf(
        "top",
        arrayOf(0, 1),
        "bottom",
        arrayOf(0, -2)
      )
    )
  )
)

on iOS: similar, but with NSExpression.expressionForConstantValue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant