-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Markers update on terrain change #10985
Conversation
@@ -100,7 +100,7 @@ | |||
}); | |||
|
|||
document.getElementById('terrain-checkbox').onclick = function() { | |||
map.setTerrain(this.checked ? {"source": "mapbox-dem"} : null); | |||
map.setTerrain(this.checked ? {"source": "mapbox-dem", "exaggeration": 10} : null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Higher terrain exaggeration makes the bug more visible.
@@ -1380,12 +1380,31 @@ test('Marker interaction and raycast', (t) => { | |||
const bottomLngLat = tr.pointLocation3D(new Point(terrainTop.x, tr.height)); | |||
// Raycast returns distance to closer point evaluates to occluded marker. | |||
t.stub(tr, 'pointLocation3D').returns(bottomLngLat); | |||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setTimeout
in a test seems hacky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great and fixes the issue. 👍 💯
src/ui/map.js
Outdated
@@ -2764,6 +2764,10 @@ class Map extends Camera { | |||
this.painter._updateFog(this.style); | |||
this._updateTerrain(); // Terrain DEM source updates here and skips update in style._updateSources. | |||
this.style._updateSources(this.transform); | |||
// Update positions of markers on enabling/disabling terrain | |||
for (const marker of this._markers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I don't immediately see why this is the correct location at which to update judiciously in order to fix the bug, but it looks reasonable, and if it fixes the issue, then it seems correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you put these three lines into _forceMarkerUpdate()
function so that its easier to reason about and use in other cases as they come up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arindam1993 Done!
@rreusser The update needs to happen after _updateSources
is called, since the markers derive their position from map.transform
which has no knowledge of terrain until that function is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving, just one change that would be a nice to have.
In #10985 we removed setTimeout in test, which caused behaviour impacted by workload of host machine and becomes execution order unpredictable[1], because marker style modification uses Timers API, but rendering calls setImmediate [1] https://nodejs.org/en/guides/event-loop-timers-and-nexttick#setimmediate-vs-settimeout
Fixes #10982
Launch Checklist
mapbox-gl-js
changelog:<changelog>Fixed markers not updating position on terrain change</changelog>