mapbox / mapbox/mapbox-gl-js

Cannot read property 'getLayoutProperty' of undefined

Open
#8,733 4 comments 0 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

Hello !
im trying to use the example 'show and hide layers'

`var visibility = map.getLayoutProperty(clickedLayer, 'visibility');

if (visibility === 'visible') {
map.setLayoutProperty(clickedLayer, 'visibility', 'none');
this.className = '';
} else {
this.className = 'active';
map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
}
};
`

but i have this error each time i use getLayoutProperty :

Cannot read property 'getLayoutProperty' of undefined,

why ?

thanks.

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 by reproducing the “show and hide layers” example and checking how the map instance and clickedLayer are initialized before getLayoutProperty is called. Compare the reported snippet with the example’s setup and capture the library version and a minimal reproduction. Done means identifying the cause of the undefined value and documenting or confirming a focused fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
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.