Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query*Features and MapMouseEvent.features returns a null feature property as "null" #8497

Closed
nrako opened this issue Jul 17, 2019 · 7 comments · Fixed by #11110
Closed

query*Features and MapMouseEvent.features returns a null feature property as "null" #8497

nrako opened this issue Jul 17, 2019 · 7 comments · Fixed by #11110
Labels

Comments

@nrako
Copy link

nrako commented Jul 17, 2019

mapbox-gl-js version: v1.1.1 (true for previous versions too)

browser: Chrome ...

Link to Demonstration

https://codepen.io/anon/pen/rXBGBb?editors=1001#anon-login

Expected Behavior

I would expect a returned value of property on a geojson feature to remain null and not become "null".

Actual Behavior

A null property geojson feature e.g{ my_property: null } is converted to a string { my_property: 'null' } when queried (i.e querySourceFeatures) or in MapMouseEvent's features.

By inspecting the _data of the source I can see that null values of feature properties are stored as expected.

@jbelien
Copy link

jbelien commented Feb 28, 2020

Same issue with version 1.8.1 (with same use case : GeoJSON file feature queried through a click on map).

jbelien added a commit to EqualStreetNames/equalstreetnames that referenced this issue Feb 28, 2020
Find with null becomes "null" (see mapbox/mapbox-gl-js#8497)
@cafca
Copy link

cafca commented Mar 12, 2020

Can somebody with knowledge of the codebase comment where source / solution of this bug could be found? I may be able to create a PR if given a hint.

@rdmurphy
Copy link

Wanted to flag that this is still an issue that I just hit.

porsager added a commit to porsager/vt-pbf that referenced this issue Apr 29, 2020
I hope this is an acceptable change, although I don't know the complete requirements of this package, but this fix will solve mapbox/mapbox-gl-js#8497.

I also have a hard time thinking of a reason it would make sense to have null as a string `"null"` because of the ambiguity it brings.
@porsager
Copy link

Thought I would add that this PR fixes this issue if it's merged: mapbox/vt-pbf#39

@strech345
Copy link

can please someone check this pr?

mourner added a commit to mapbox/vt-pbf that referenced this issue May 19, 2021
I hope this is an acceptable change, although I don't know the complete requirements of this package, but this fix will solve mapbox/mapbox-gl-js#8497.

I also have a hard time thinking of a reason it would make sense to have null as a string `"null"` because of the ambiguity it brings.

Co-authored-by: Vladimir Agafonkin <agafonkin@gmail.com>
@friendlyswiss
Copy link

Just flagging that I'm still running into this issue.

@andrewharvey
Copy link
Collaborator

copypaste workaround if you know your data has not actual string values called "null"

const features = map.queryRenderedFeatures(...)
for (let i = 0; i < features.length; i++) {
  for (const key of Object.keys(features[i].properties)) {
    if (features[i].properties[key] === 'null') {
      features[i].properties[key] = null
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants