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

Markers update on terrain change #10985

Merged
merged 5 commits into from Sep 14, 2021
Merged

Markers update on terrain change #10985

merged 5 commits into from Sep 14, 2021

Conversation

SnailBones
Copy link
Contributor

@SnailBones SnailBones commented Sep 2, 2021

Fixes #10982

Launch Checklist

  • write tests for all new functionality
  • post benchmark scores
  • manually test the debug page
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Fixed markers not updating position on terrain change</changelog>

@SnailBones SnailBones changed the title Bugfix, increased exaggeration in example to make bug more apparent Markers update on terrain change Sep 2, 2021
@@ -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);
Copy link
Contributor Author

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(() => {
Copy link
Contributor Author

@SnailBones SnailBones Sep 9, 2021

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

@SnailBones SnailBones added this to the v2.4.2 milestone Sep 9, 2021
Copy link
Contributor

@rreusser rreusser left a 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) {
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@arindam1993 arindam1993 left a 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.

@SnailBones SnailBones merged commit 1940dbc into main Sep 14, 2021
@SnailBones SnailBones deleted the aidan/marker-update-3d branch September 14, 2021 20:11
mourner pushed a commit that referenced this pull request Jan 4, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug - Marker positions not updated when DEM data loads
3 participants