-
-
Notifications
You must be signed in to change notification settings - Fork 735
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
Fix setting line-gradient to null/undefined #2837
Fix setting line-gradient to null/undefined #2837
Conversation
f7c6da1
to
7958060
Compare
@HarelM This is my first time contributing to this project -- do I need to do something to start the CI jobs? |
I need to start it, I changed the settings now so that it won't happen in the future... |
Thanks for taking the time to solve this! |
I think I prefer to do it separate. I will make a ticket for it and link this PR. I suspect it might get pretty messy so I don't want to hold up this bugfix. |
|
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2837 +/- ##
==========================================
+ Coverage 75.03% 75.06% +0.03%
==========================================
Files 240 240
Lines 19131 19134 +3
Branches 4318 4320 +2
==========================================
+ Hits 14355 14363 +8
+ Misses 4776 4771 -5
☔ View full report in Codecov by Sentry. |
@HarelM Are you okay with this branch as is or did you want me to do anything else before shipping? |
See my last comment. Otherwise approved. |
@tangerine-orange where are we with this PR? |
@HarelM Sorry for the delay. I've added the type guard you suggest to maplibre/maplibre-style-spec#334. I integrated the updated maplibre-style-spec locally and it works as intended. |
…ates when updating line-gradient
…ression existence to handle setting undefined line-gradient
a257bad
to
a322f55
Compare
@HarelM okay, I integrated the new version of @maplibre/maplibre-gl-style-spec and am using the type guard. |
Am I missing a change in the package.json file? I see the luck file change, but not the package...? |
my bad, added. |
This PR fixes #2683
Problem
A
StyleLayer
is added to a map by callingmap.addLayer
. In particular, we can add aLineStyleLayer
that adds a color gradient (line-gradient
) as follows:Our problem comes when we try to unset the
line-gradient
usingMap.setPaintProperty
:Note the third argument,
null
, which is meant to unset the property. (Note thatnull
andundefined
have same behavior in this case)Our app crashes and we see an error in console:
Explanation
When we call
map.setPaintProperty('line', 'line-gradient', null)
, our callstack is:-->
LineStyleLayer._handleSpecialPaintPropertyUpdate
->
StyleLayer.setPaintProperty
Map.setPaintProperty
In
LineStyleLayer._handleSpecialPaintPropertyUpdate
, there is a special case forline-gradient
.You can see that this code assumes the existence of
expression._styleExpression
. This assumption is broken when we're setting the property tonull
.Solution
Check for the existence of
_styleExpression
before trying to access it.Bonus
Map.setPaintProperty
expects you to passnull
when unsetting the existing value, notundefined
. This is what we test for. I added this info to the documentation for this method.Potential future work
null
overundefined
for unsetting? I'd imagine we would do this using Typescript. If so I can make ticket.ZoomConstantExpression
doesn't seem ideal, especially sinceZoomConstantExpression
isn't even one of the possible types forthis._transitionablePaint._values['line-gradient'].value.expression
. We should probably clean up the typing here? If so I can make ticket.Launch Checklist
CHANGELOG.md
under the## main
section.