mapbox / mapbox/mapbox-gl-js

Using 3d terrain elevation in a 3rd party basemap style throws javascript error

Open
#13,497 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: 3.12.0

**browser**: Chrome

### Steps to Trigger Behavior

1. Setup a terrain in your map:
```
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 });
```

2. Use a 3rd party basemap style such as USGS or World Topo (see code in demonstration link below)
3. Notice the error in your javascript console `Uncaught TypeError: Cannot read properties of undefined (reading 'get')`

### Link to Demonstration

https://codepen.io/Matt-Palmerlee/pen/NWZrVoJ

### Expected Behavior

The basemap style is changed and elevation is shown without Javascript errors

### Actual Behavior

Elevation seems to display fine, however javascript error is thrown:

```
Uncaught TypeError: Cannot read properties of undefined (reading 'get')
at qs.update (terrain.ts:386:48)
...
```

Image

Perhaps the check on [this line in terrain.ts](https://github.com/mapbox/mapbox-gl-js/blob/main/src/terrain/terrain.ts#L369) should also check style.terrain.properties?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the CodePen example, a raster-dem terrain source, and a third-party basemap style. Inspect src/terrain/terrain.ts around the style.terrain check near line 369 and the failing update code around line 386; done means terrain elevation and style changes work without a JavaScript error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.