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

SymbolLayer.textVariableAnchorOffset can't be set to any value but nil() #143

Open
sargunv opened this issue Dec 19, 2024 · 1 comment
Open
Labels
bug Something isn't working upstream This issue can't be resolved until an upstream issue is resolved

Comments

@sargunv
Copy link
Owner

sargunv commented Dec 19, 2024

related: maplibre/maplibre-native#2358

this doesn't seem to be possible to set with the JSON expression converter at all in Native right now.

It crashes on iOS and logs an error on Android. Both with the same error message: Error setting property: text-variable-anchor-offset anchor offset must have two numbers

investigation copied from Slack thread:

Details

Does anyone have insight into setting textVariableAnchorOffset programmatically on a symbol layer? I’m trying to get this working with MapLibre Compose, but I just get: “Error setting property: text-variable-anchor-offset anchor offset must have two numbers” on both iOS and Android.

Here’s some sample code on Android:

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

(edited)
4 replies

sargunv
27 minutes ago
Setting it with a regular Array instead of via an Expression works fine, but I want to support expressions

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

sargunv
15 minutes ago
relevant C++ code: https://github.com/maplibre/maplibre-native/blob/c94864f1a9a742d09d4619ec6aa786bb46824cb0/src/mbgl/style/conversion/constant.cpp#L176
nothing jumps out as an obvious cause here; my value seems to be meeting the conditions presented there but it’s still erroring

sargunv
5 minutes ago
Interestingly, this works:

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

So it needs to be a literal array, and expressions within the array aren’t supported. That makes this pretty rough to use (edited)
11:01
extra interestingly, doing the same literal construct with the JSON converter presents an error: “Nested literal arrays are not supported.”
but we see above that nested literal arrays aren’t just supported, they’re required by this property. Feels like a bug to me

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)
          })
        })
      })
  )
)
@sargunv sargunv added this to the v0.3.0 milestone Dec 19, 2024
@sargunv sargunv added the bug Something isn't working label Dec 19, 2024
@sargunv sargunv changed the title Properly type and support text variable anchor offset on symbol layer SymbolLayer.textVariableAnchorOffset can't be set to any value but nil() Dec 19, 2024
@sargunv sargunv removed this from the v0.3.0 milestone Dec 19, 2024
@sargunv
Copy link
Owner Author

sargunv commented Dec 19, 2024

Blocked by maplibre/maplibre-native#3100

@sargunv sargunv added the upstream This issue can't be resolved until an upstream issue is resolved label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream This issue can't be resolved until an upstream issue is resolved
Projects
None yet
Development

No branches or pull requests

1 participant