You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] map.flyTo centers on the incorrect spot when terrain is enabled. #2194
I recently tried to upgrade our version of react-map-gl to v7.0.25. During the upgrade I encountered a bug where map.flyTo goes to the incorrect location when map.setTerrain() has been called. Once at the incorrect location, if I manually move the map around, the Marker at that location stutters between the actual location and several incorrect locations.
With terrain enabled, I would expect the same behavior as without terrain enabled. flyTo should center the map view on the actual location of the Marker taking into account the terrain information. This was working when using react-map-glv6.1.10.
Steps to Reproduce
Behavior is reproducible at this sandbox, although you will need your own Mapbox API token.
Comment out the following line (line 21) to toggle the behavior:
Is there any update on this? I am also experiencing a similar issue. When the terrain is enabled, my popup is not rendering where expected (both on a hillside as well as on a flat area).
See this screenshot, where I would expect the popup to only appear when my cursor is over the blue feature, yet it appears even when my cursor is just outside of the polygon. This does not occur if I don't include terrain on my map.
I think this has something to do with the order in which the source layer is added and the terrain source is set. Mapbox GL JS seems to add the source layer and then set the terrain (code taken from this Mapbox example):
map.on('style.load', () => {
map.addSource('mapbox-dem', {
'type': 'raster-dem',
'url': 'mapbox://mapbox.mapbox-terrain-dem-v1',
'tileSize': 512,
'maxzoom': 14
});
// add the DEM source as a terrain layer with exaggerated height
map.setTerrain({ 'source': 'mapbox-dem', 'exaggeration': 1.5 });
});
It is not clear to me the order that react-map-gl adds the source and sets the terrain source, but the terrain source is set already on the Map component, while the source layer itself is a child of the map. Example of this from react-map-gl.
When I render the map using exclusively Mapbox GL JS, the popup works as expected (even on 3D terrain), while when using react-map-gl, this bug appears.
@Pessimistress I tested this on another project - v8.1.0-alpha2 has fixed the flyTo issue for me.
edit: I'm playing around with this more, as I toggle terrain/fog programmatically after the map is rendered, there's a maximum call stack exceeded error that gets thrown in _calcMatrices. This seems to be due to changing numeric settings as props (ex: maxPitch prop).
@Pessimistress thanks for the update! it looks like that issue above is still breaking the 8.1.0 experience. Toggling between terrain & non-terrain views with dynamic pitches still seems to break the map experience. See #2535 for a potential solution
Activity
loganbrunner commentedon Aug 3, 2023
Is there any update on this? I am also experiencing a similar issue. When the terrain is enabled, my popup is not rendering where expected (both on a hillside as well as on a flat area).
See this screenshot, where I would expect the popup to only appear when my cursor is over the blue feature, yet it appears even when my cursor is just outside of the polygon. This does not occur if I don't include terrain on my map.

I think this has something to do with the order in which the source layer is added and the terrain source is set. Mapbox GL JS seems to add the source layer and then set the terrain (code taken from this Mapbox example):
It is not clear to me the order that
react-map-gladds the source and sets the terrain source, but the terrain source is set already on the Map component, while the source layer itself is a child of the map. Example of this fromreact-map-gl.When I render the map using exclusively Mapbox GL JS, the popup works as expected (even on 3D terrain), while when using
react-map-gl, this bug appears.I also think this is a similar issue to #2196.
Pessimistress commentedon Mar 28, 2025
Can you try 8.1.0-alpha
hwandrew commentedon May 13, 2025
@Pessimistress I tested this on another project - v8.1.0-alpha2 has fixed the
flyToissue for me.edit: I'm playing around with this more, as I toggle terrain/fog programmatically after the map is rendered, there's a maximum call stack exceeded error that gets thrown in
_calcMatrices. This seems to be due to changing numeric settings as props (ex:maxPitchprop).Pessimistress commentedon Oct 3, 2025
v8.1.0 is published.
hwandrew commentedon Oct 7, 2025
@Pessimistress thanks for the update! it looks like that issue above is still breaking the 8.1.0 experience. Toggling between terrain & non-terrain views with dynamic pitches still seems to break the map experience. See #2535 for a potential solution