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

Treat Strings as Arrays in GL JS Expressions #8909

Open
adrianababakanian opened this issue Oct 25, 2019 · 1 comment
Open

Treat Strings as Arrays in GL JS Expressions #8909

adrianababakanian opened this issue Oct 25, 2019 · 1 comment

Comments

@adrianababakanian
Copy link
Contributor

Motivation

This suggestion relates closely to the substring functionality discussed in #4113, as well as the regex expression support in #4089. I think these existing issues do a better job of addressing the underlying problem (lack of ability to work with substrings in expressions), but this feature request provides another option.

Programming languages commonly implement strings as arrays of characters. Mapbox GL JS expressions could treat strings in the same way to allow for existing expressions (i.e. at) to be used with strings. For example, this would allow filtering for streets whose name property starts with the string "Ba".

Design

If GL JS parsed strings in expressions as arrays, developers could make use of the current at expression to implement the filtering use case described above.

Mock-Up

If a developer wanted to filter for features where the street name property starts with "Ba" , they could set the opacity attribute of the road-label layer to be determined by the following expression:

[
  "case",
  [
    "all",
    [
      "==",
      ["at", 
        0, 
        ["get", "name_en"]
      ],
      "B"
    ],
    [
      "==",
      ["at", 
        1, 
        ["get", "name_en"]
      ],
      "a"
    ]
  ],
  0,
  1
]
@ryanhamley
Copy link
Contributor

I actually am finishing up #8876 which implements the in operator which tests both that an element is in an array and that a substring is in a string. This will close #4113

Updating at to work with strings is an interesting idea. I'm not sure there's any other expressions that would really benefit from this behavior.

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

No branches or pull requests

2 participants