mapbox / mapbox/mapbox-gl-js

Layers are not visible although visibility property is specified ?

Open
#13,012 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs information :pray:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**:

### Question

I have a weird behavior in showing the raster layer,I have a map and mapbox compare in my app. I add the layers in the style.load event listener like this:

```
if (!map.current.getSource(layer?.layer_name + `-` + layer?.id)) {
map.current.addSource(layer?.layer_name + `-` + layer?.id, {
type: "raster",
url: link,
});
}

if (!map.current.getLayer(layer?.layer_name + `-` + layer?.id)) {
map.current.addLayer({
id: layer?.layer_name + `-` + layer?.id,
layout: {
visibility: layer?.show ? "visible" : "none", //if layer is shown, hide it. and vice versa
},
source: layer?.layer_name + `-` + layer?.id,
type: "raster",
});
}

console.log(
map.current.getLayer(layer?.layer_name + `-` + layer?.id),
layer,
map,
map.current.getLayoutProperty(
layer?.layer_name + `-` + layer?.id,
"visibility"
)
);
```

on initial load for the map everything is looking good and the layers are visible, then when I compare 2 maps then going back to the normal map, all the layers are hidden although I specify the visibility property for the layers but all the layers have a none visibility

### Links to related documentation

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

Start with the style.load handler and the addSource, addLayer, and getLayoutProperty calls shown in the report. Reproduce the transition between the compared maps, then verify whether the layer visibility state is changed or reapplied during that transition; done means the reported layers retain the requested visibility when returning to the normal map.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.