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

Heatmap dynamic radius and blur #15384

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bjornharrtell
Copy link
Contributor

@bjornharrtell bjornharrtell commented Nov 27, 2023

I'm trying to make radius and blur accept a function to be able to control these parameters similar to what is already possible for weight.

The proposed code change work for blur but not for radius. I've kept the u_size uniform in here until I can figure it out... it seems that for some reason setSymbolSizeExpression will not produce expected result after using a varyings, i.e .setSymbolSizeExpression('vec2(v_prop_size)') for this PR. The result is invisible heatmap in the example.

I found that docs for setSymbolColorExpression mentions varyings but setSymbolSizeExpression but I'm not sure that is intentional. Looking at the ShaderBuilder code indicates that varyings are taken into consideration for setSymbolSizeExpression but I'm too much of a shader novice to be sure I understand it right or to debug.

@bjornharrtell
Copy link
Contributor Author

bjornharrtell commented Nov 27, 2023

@jahow your answer on #15231 would require this feature right? It's more or less what I would like to use it for. Any thoughts on this and why varyings doesn't appear to work in setSymbolSizeExpression?

Copy link

📦 Preview the website for this branch here: https://deploy-preview-15384--ol-site.netlify.app/.

@mike-000
Copy link
Contributor

#15231 is a duplicate of https://stackoverflow.com/q/77263582/10118270 It could be done using the view change:resolution event as in https://codesandbox.io/s/heatmap-earthquakes-forked-3vs5qn?file=/main.js Note also that the weight function is not truly dynamic, a change on the source must be forced to re-evaluate https://stackoverflow.com/q/77515208/10118270

@bjornharrtell
Copy link
Contributor Author

bjornharrtell commented Nov 27, 2023

@mike-000 that's a nice trick, thanks. On the weight function, in my experiments it did appear to reevaluate.. are you sure about that it's not really dynamic?

@jahow
Copy link
Contributor

jahow commented Nov 27, 2023

Thanks for looking into this @bjornharrtell and @mike-000. Because the Heatmap layer currently does not accept expressions for each of its parameters, its reactivity to changes might be limited. If you plan on having the radius and blur depending on feature data, then your approach will work. On the other hand, having these depend on e.g. resolution or other external variables will not produce any result unless source.changed() is called.

I'm not sure what's wrong with your code, but I think it can be simplified by e.g.

  • getting rid of the u_size uniform
  • storing both the blur and radius values in their corresponding attributes (without computing anything)
  • declare their corresponding varyings v_prop_blur and v_prop_radius, again without additional computation
  • adapting the symbol size and symbol color GLSL code to use these new varyings instead of the uniforms

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

Successfully merging this pull request may close these issues.

None yet

3 participants