mapbox / mapbox/mapbox-gl-js

Nested objects with GeoJSON will not after setFeatureState

Open
#7,194 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi!

**mapbox-gl-js version**: v0.48

**browser**: Chrome 68.0.3440.106

### Steps to Trigger Behavior

Playing around with the hover-styles example (https://www.mapbox.com/mapbox-gl-js/example/hover-styles/), I encountered an issue that nested objects in a features object will not work after setFeatureState is called.

More specifically, doing this will work fine on initial rendering.
```
"line-color":
["case", ["boolean", ["feature-state", "hover"], false],
["get", "default-color"],
["get", "0", ["get", "colors"]]
],
```
However, after a `mouseover` and `mouseleave`, it will however revert to using the default fallback line color instead of the one retrieved with ` ["get", "0", ["get", "colors"]]`.

Additionally, this warning will be logged to the console:
`Expected value to be of type object, but found string instead.`

### Link to Demonstration

https://jsfiddle.net/43bq7mfg/

### Expected Behavior

Using `get` on nested objects in feature properties to work after using `setFeatureState()`

### Actual Behavior

Using `get` on nested objects in feature properties logs a warning and will revert to the fallback/default value.

I'm not sure, but could this be related to #2434?

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 issue in the hover-styles example or the linked JSFiddle, focusing on setFeatureState, feature-state, and nested get expressions. Done means nested GeoJSON properties still resolve after mouseover and mouseleave, without the reported type warning or fallback color.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.