mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
451 stars 126 forks source link

Getting GeoJson cluster leaves sometimes results in "No FeatureExtension `supercluster`" errors #2404

Open jasonccox opened 1 month ago

jasonccox commented 1 month ago

Environment

Observed behavior and steps to reproduce

I'm unable to get the features corresponding to a point cluster. I have the following code that shows details about the features in a cluster when it's clicked:

    private val handlePointClusterClick = OnMapClickListener {  point ->
        lifecycleScope.launch {
            val featuresOrError = mapboxMap.queryRenderedFeatures(
                RenderedQueryGeometry(mapboxMap.pixelForCoordinate(point)),
                RenderedQueryOptions(listOf(clusterTextLayerId), null)
            )

            if (featuresOrError.isError) {
                Log.e(TAG, "error querying for cluster ${featuresOrError.error}")
            } else {
                featuresOrError.value?.firstOrNull()?.let { cluster ->
                    val leavesOrError = mapboxMap.getGeoJsonClusterLeaves(
                        cluster.queriedFeature.source,
                        cluster.queriedFeature.feature,
                        Long.MAX_VALUE,
                        0
                    )

                    if (leavesOrError.isError) {
                        Log.e(TAG, "error querying for leaves ${leavesOrError.error}")
                    } else {
                        leavesOrError.value?.featureCollection?.let { features ->
                            // display features here...
                        }
                    }
                }
            }
        }

        true
    }

For most of the clusters on my map, this code works fine. However, for some the call to getGeoJsonClusterLeaves results in the following error in the logs:

[maps-core]: {}[General]: No FeatureExtension `supercluster` found for `mapbox-android-pointAnnotation-source-1` source.
error querying for leaves No FeatureExtension found for source mapbox-android-pointAnnotation-source-1

Expected behavior

I expect getGeoJsonClusterLeaves to return a value, not an error, containing all of the features in the cluster.

Notes / preliminary analysis

I attempted to write my own function to get the leaves by recursively calling getGeoJsonClusterChildren. In doing so, most of the calls to getGeoJsonClusterChildren succeeded, and I was able to get most of the leaves, but a few of the calls returned this same No FeatureExtension... error. As far as I can tell, there seems to be something wrong with a few of the sub-clusters that causes this behavior.

Additional links and references

None

cgaisl commented 2 weeks ago

I ran into the same problem where, for some of my clusters, getGeoJsonClusterLeaves would return "No FeatureExtension ..." for no apparent reason.

What fixed the issue for me was reducing the clusterMaxZoom of my GeoJsonSource to 30 or below. I had it set to 99 because I always wanted to continue clustering. Please don't ask me how long it took me to figure that out...

jasonccox commented 1 week ago

Nice find! That seems to solve the problem for me as well. Still seems like a bug, but it's good to have a workaround.