mapbox / mapbox/mapbox-gl-js

Layer.isVisible()

Open
#11,897 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple: needs discussion :speech_balloon:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: 2.8.2

### Question
I would like to know if my layer is visible
The layer is hidden according to the zoom in the map, is there a method to know the layers visible on the map ? I have tried to parse the array but is quiet complicated :/

The function `map.getLayoutProperty(layerId, 'visibility')` doesn't work because my layer is hidden with the zoom and not with an attribute

I would like to have a function like that :
`map.getLayer(id).isVisible() => boolean`

Thx

### 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

The issue points to map.getLayer(id).isVisible() and map.getLayoutProperty(layerId, 'visibility'); begin by reviewing those API paths and how zoom-based visibility is represented. Done means defining and implementing a way to determine whether a layer is currently visible at the map's zoom, with the behavior documented and tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api, frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.