You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
queryRenderedFeatures loses Feature IDs when using clustering #12347
I'm using queryRenderedFeatures to check what features are tapped by the user. This works great, until I set new GeoJsonOptions().withCluster(true) to the source of the layer I'm querying. I'm not expecting queryRenderedFeatures to work for individual features when the features are clustered, only when they are displayed separately when zoomed in.
Steps to reproduce
Create a layer with clustering set to true and add a bunch of features with IDs to that layer.
Use queryRenderedFeatures for that layer, with camera zoomed in close enough that the features are not clustered.
Check the returned features for IDs.
Expected behavior
The IDs are present, as without clustering.
Actual behavior
The ID is an empty string.
Configuration
Android versions: 8.1.0 Device models: Nexus 5X Mapbox SDK versions: Tested on 5.5.0-5.5.3 and 6.2.1.
changed the title [-]queryMapFeatures loses Feature IDs when using clustering[/-][+]queryRenderedFeatures loses Feature IDs when using clustering[/+]on Jul 9, 2018
@SamiPatanen the library responsible for providing clustering is the supercluster.hpp project here. Quickly glanced through the code and seeing constructions as these. This means that the clustering algorithm overwrites/replaces feature ids. To unblock your use-case, you can create a new id-like field and add/use that one instead.
For this issue, if you feel this should be addressed, can you create a new ticket upstream in supercluster.hpp? We won't be able to fix this up in codebase found in this repository.
Thank you for reaching out and reporting this to us!
(closing as this should be reopened upstream)
"To unblock your use-case, you can create a new id-like field and add/use that one instead."
I assume you mean something like:
String id = "something";
feature.addStringProperty("customID", id);
And then retrieving this property after queryRenderedFeatures like so:
String id = feature.getStringProperty("customID");
This results in a NullPointerException:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.gson.JsonElement.getAsString()' on a null object reference
at com.mapbox.geojson.Feature.getStringProperty(Feature.java:324)
@tobrun I opened an issue in the supercluster repository, and it was quickly closed, as they were already working on improving related things. However, they said that the supercluster shouldn't remove features.
I tested without clustering, and it resulted in a NullPointerException as well. It turns out I managed to mess it up somehow. So the workaround works well after all.
Activity
[-]queryMapFeatures loses Feature IDs when using clustering[/-][+]queryRenderedFeatures loses Feature IDs when using clustering[/+]tobrun commentedon Jul 10, 2018
@SamiPatanen the library responsible for providing clustering is the supercluster.hpp project here. Quickly glanced through the code and seeing constructions as these. This means that the clustering algorithm overwrites/replaces feature ids. To unblock your use-case, you can create a new id-like field and add/use that one instead.
For this issue, if you feel this should be addressed, can you create a new ticket upstream in supercluster.hpp? We won't be able to fix this up in codebase found in this repository.
Thank you for reaching out and reporting this to us!
(closing as this should be reopened upstream)
SamiPatanen commentedon Jul 10, 2018
Hi @tobrun!
"To unblock your use-case, you can create a new id-like field and add/use that one instead."
I assume you mean something like:
And then retrieving this property after queryRenderedFeatures like so:
This results in a NullPointerException:
tobrun commentedon Jul 10, 2018
@SamePatanen, wasn't expecting this behaviour tbh, can you open a ticket in the supercluster repository? thanks!
SamiPatanen commentedon Jul 10, 2018
@tobrun I opened an issue in the supercluster repository, and it was quickly closed, as they were already working on improving related things. However, they said that the supercluster shouldn't remove features.
I tested without clustering, and it resulted in a NullPointerException as well. It turns out I managed to mess it up somehow. So the workaround works well after all.