mapbox / mapbox/mapbox-gl-js

"mapLayer.layout.get()" is no longer a function

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

Nobody has claimed this yet.

needs discussion :speech_balloon: 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**: 3.5.2

**browser**: Safari, Chrome, Firefox

### Steps to Trigger Behavior

1. attempt to use `map.getLayer(LAYER_ID).layout.get('icon-size').value.value`

### Link to Demonstration

### Expected Behavior

The value of the layer property is returned.

### Actual Behavior

An error stating that get is not a function (it is undefined) is thrown.

### Other tech details

I found that the computed value is now available under `map.style._layers[LAYER_ID].layout._values['icon-size'].value.value`, but this is both using what looks like an internal value, and the types are not set up well to use like `.get()` was with the `@types/` library previously.

Also, `map.style._layers[LAYER_ID]` has a type of `StyleLayer`, which is a base type, (rather than being `TypedStyleLayer` which is the combined type), so there’s no way to use type guards to narrow it to the type, (`SymbolStyleLayer`), required.

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 failure from map.getLayer(LAYER_ID).layout.get('icon-size') and compare it with the internal map.style._layers[LAYER_ID].layout._values access described in the report. Inspect the related style-layer types and the @types/ usage; done means the layer property can be retrieved through a supported, type-safe API without relying on internal values.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.