-
-
Notifications
You must be signed in to change notification settings - Fork 977
Description
maplibre-gl-js version: 5.14.0 (latest)
browser: All browsers i believe
Steps to Trigger Behavior
- Set a map with terrain.
- Let the map flying or zoom in.
- When flying or zoom in is still happening, use
map.setStyle()to set a new style with terrain.
Link to Demonstration
To use this example:
- Click the compass button to let the map move.
- Before map move is finished, set the map to another style.
- Error occurs.
Expected Behavior
No error and the map is able to set a new style with terrain.
Actual Behavior
There is an error:
Uncaught TypeError: Cannot read properties of undefined (reading 'shaderPreludeCode')
useProgram @ painter.ts:729
(anonymous) @ draw_terrain.ts:23
maybeDrawDepthAndCoords @ painter.ts:653
render @ painter.ts:519
_render @ map.ts:3483
(anonymous) @ map.ts:3617
(anonymous)
Use-case
Users should be able to change basemap layers freely no matter the terrain is ready or not.
Explanation
I belive that when map.setStyle() is called, the map.painter.style.projection is immediately set to undefined at initialization untill the correct projection is set. As a result, if the terrain is still drawing, in the Painter.useprogram() implementation, this following line will lead to an error
const projectionPrelude = forceSimpleProjection ? shaders.projectionMercator : projection.shaderPreludeCode;
I'm new to maplibre internal implementation so lmk if I'm wrong.
Might be related to #6184 and #6817
Solution
Change the following line in Painter.maybeDrawDepthAndCoords():
- if (!this.style || !this.style.map || !this.style.map.terrain) {
+ if (!this.style || !this.style.map || !this.style.map.terrain || !this.style.projection) {
I could create a PR but I need to learn how to properly write tests as per the contribution guideline and see if it breaks anything else..