Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

queryRenderedFeatures loses Feature IDs when using clustering #12347

Closed

Description

@SamiPatanen

Hi!

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

  1. Create a layer with clustering set to true and add a bunch of features with IDs to that layer.
  2. Use queryRenderedFeatures for that layer, with camera zoomed in close enough that the features are not clustered.
  3. 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.

Activity

  1. changed the title [-]queryMapFeatures loses Feature IDs when using clustering[/-] [+]queryRenderedFeatures loses Feature IDs when using clustering[/+] on Jul 9, 2018
  2. added
    Android
    on Jul 9, 2018
  3. tobrun commented on Jul 10, 2018

    @tobrun
    Member

    @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)

  4. SamiPatanen commented on Jul 10, 2018

    @SamiPatanen
    Author

    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:

    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)
    
  5. tobrun commented on Jul 10, 2018

    @tobrun
    Member

    @SamePatanen, wasn't expecting this behaviour tbh, can you open a ticket in the supercluster repository? thanks!

  6. SamiPatanen commented on Jul 10, 2018

    @SamiPatanen
    Author

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Android

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions