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

setStyle()/style property throws "Cannot read properties of undefined (reading 'expression')" for some style.json files #11457

Closed
MaxGeldner opened this issue Feb 1, 2022 · 1 comment · Fixed by #11475
Labels

Comments

@MaxGeldner
Copy link

MaxGeldner commented Feb 1, 2022

For some map styles an error is thrown, when set via setStyle or the map is initially loaded with the style. Specifically the MapTiler Hybrid style (https://api.maptiler.com/maps/hybrid/style.json?key=<key>) doesn't work on newer versions of mapbox. The same style json worked fine in mapbox v2.1.1.. Did something in validating/setting the style change, so that some styles, which worked in ealier mapbox v2 versions, now wont work anymore, so that the style files need to be updated? If thats the case and no compatibility for older styles is wanted in mapbox, this issue can be ignored and closed. I will contact maptiler then and hope that they will update their styles :)
Here is the error with some of its stack trace:
style switch error

mapbox-gl-js version: 2.6.1 (same Error on 2.7.0 as well)

browser: Chrome

Link to Demonstration

Demo only works with valid maptiler and mapbox keys: https://jsfiddle.net/0pfyhds5/
If changing the mapbox version to 2.1.1, the style works fine.

Expected Behavior

Style should change.

Actual Behavior

Error is thrown and no style change is made.

@ryanhamley
Copy link
Contributor

This appears to be a regression from #10795. That PR introduced a function to disallow certain parameters in filter expressions and it assumes that the options object will have a valueSpec.expression property. With the MapTiler style, valueSpec is undefined, leading to this problem. If you guard against this, the style loads properly. However, a little more debugging is needed to determine what the actual correct behavior here is.

for (const param of options.valueSpec.expression.parameters) {
disallowedParameters.delete(param);
}

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

Successfully merging a pull request may close this issue.

2 participants