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

Maplibre >=4.2.0: can't use "within" filter in "all" filter anymore: ["all", ["within", ...], ...] #4212

Closed
azarz opened this issue May 31, 2024 · 10 comments
Labels
need more info Further information is requested

Comments

@azarz
Copy link

azarz commented May 31, 2024

Hi, thank you for the amazing work on Maplibre GL JS! Without it, we could not have made anything close to what we made. I am running into an issue while trying to upgrade from 3.6.2 to 4.3.2

maplibre-gl-js version: 4.3.2

browser: Chromium

Steps to Trigger Behavior (4.3.2)

  1. Create a filter with a "within" filter in a "all" filter
  2. Try to apply it to the map
  3. This appears in the console:
Error: layers.layerId.filter[2][1][0]: expected one of [==, !=, >, >=, <, <=, in, !in, all, any, none, has, !has], "within" found

Link to Demonstration

Filter working (maplibre gl js 3.6.2) : https://jsbin.com/dozeqofofa/1/edit?html,css,js,output
Filter not working (maplibre gl js 4.3.2) : https://jsbin.com/wuzowelebo/1/edit?html,css,js,output

Expected Behavior (3.6.2)

  1. Create a filter with a "within" filter in a "all" filter
  2. Try to apply it to the map
  3. The filter works and ther is no errors in the console.
@HarelM
Copy link
Collaborator

HarelM commented May 31, 2024

Can you try and find the last version this worked?
I think it has to do with a change I made in the spec when I added the distance expression support.
Generally speaking, this error indicates you are mixing "old" and "new" expression syntax.

@HarelM
Copy link
Collaborator

HarelM commented May 31, 2024

Use ["!", [in, ...]] Instead of !in also.

@azarz
Copy link
Author

azarz commented May 31, 2024

Thanks a lot for the quick response!

When I try converting "!in" into "!", ["in ... in my style json, I get the following error :

layers.layerId.filter[1][0]: expected one of [==, !=, >, >=, <, <=, in, !in, all, any, none, has, !has], "!" found

I will try to convert everything to "new" expression syntax, and let you know which specific version causes the issue next week!

@HarelM HarelM added the need more info Further information is requested label May 31, 2024
@azarz
Copy link
Author

azarz commented May 31, 2024

I've tested the issue with several versions, and it seems that it appeared between 4.1.3 and 4.2.0.

Working example : (4.1.3) https://jsbin.com/fisuyubuna/edit?html,css,js,output
Not working example : (4.2.0) https://jsbin.com/nebucuvaqu/edit?html,css,js,output

And I confinrm I can't find a way to use ["!", ["in"... instead of ["!in", getting the error I mentioned in my previous comment. For more precision:

  • The style with the filters is originally loaded from a json (this is where the "!in" is defined)
  • The "within" filter is then added on the fly in the web app according to user input.

@HarelM
Copy link
Collaborator

HarelM commented Jun 1, 2024

I think it's the distance support and the changes I made here:
maplibre/maplibre-style-spec#642

If you turn style validation off, does it work with latest version?

@azarz azarz changed the title Maplibre 4: can't use "within" filter in "all" filter anymore: ["all", ["within", ...], ...] Maplibre 4.2.0: can't use "within" filter in "all" filter anymore: ["all", ["within", ...], ...] Jun 3, 2024
@azarz
Copy link
Author

azarz commented Jun 3, 2024

I have added

  validateStyle: false

in the map options, and it does not seem to change anything: https://jsbin.com/qikecefawi/edit?html,css,js,output

@azarz azarz changed the title Maplibre 4.2.0: can't use "within" filter in "all" filter anymore: ["all", ["within", ...], ...] Maplibre >=4.2.0: can't use "within" filter in "all" filter anymore: ["all", ["within", ...], ...] Jun 3, 2024
@HarelM
Copy link
Collaborator

HarelM commented Jun 4, 2024

I don't think there's an easy way to check that the syntax is ok besides using the validation function, which doesn't help much.
I would consider "complicating" the expression step by step and see when it starts to fail.
I'll see if I can improve the deprecated docs in the style spec to help understand how to properly migrate an old expression to new.

@azarz
Copy link
Author

azarz commented Jun 4, 2024

I managed to convert all my filter to "new" syntax, I needed more ["get", "..."] and ["literal",["...",
https://jsbin.com/geyelihija/edit?js,output
Thanks a lot for the help!!

@azarz azarz closed this as completed Jun 4, 2024
@HarelM
Copy link
Collaborator

HarelM commented Jun 5, 2024

@azarz can you help me update the following doc to better explain how to migrate from old syntax to new syntax:
https://github.com/maplibre/maplibre-style-spec/blob/main/docs/deprecations.md

@HarelM
Copy link
Collaborator

HarelM commented Jun 5, 2024

I've opened the following PR:
maplibre/maplibre-style-spec#695

Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants