Mapbox-gl-js: For GeoJSON sources, can query*Features return the original geometry?

Created on 9 Nov 2017  路  3Comments  路  Source: mapbox/mapbox-gl-js

Currently, queryRenderedFeatures or querySourceFeatures on a GeoJSON source return geometries that have gone through a round trip to tiled form, reducing coordinate precision and therefore giving different coordinates at different zoom levels. This has proven to be confusing: #5638, #4733, #5397, https://github.com/mapbox/mapbox-gl-native/issues/8992.

For GeoJSON sources specifically, we may be able to change the behavior of queryRenderedFeatures or querySourceFeatures such that features are always returned with their original, input geometry, regardless of zoom level.

I can't _guarantee_ that we'll be able to do this -- there are considerations that we'll need to work through, like whether this means that GeoJSON sources will have different behavior with regards to features being clipped along tile edges, and whether we'd have to give up on #3220. But we should at least investigate it.

feature

Most helpful comment

I'm trying to use the coordinate out of the querySourceFeatures to animate a marker, however since the coordinate changes on different zoom levels I run into issues where the coordinate is "invalid" so the marker "disappears".

Is there a temporary alternative to getting the original coordinate?
Is it possible to reverse calculate the coordinate based on tile & zoom level?
Or should I also put the original coordinate as a property in the geojson?

All 3 comments

For GeoJSON sources specifically, we may be able to change the behavior of queryRenderedFeatures or querySourceFeatures such that features are always returned with their original, input geometry, regardless of zoom level.

This change has also been requested on the native side in mapbox/mapbox-gl-native#6178 and mapbox/mapbox-gl-native#7376, where it could help to unblock reimplementing annotations atop GeoJSON sources.

I'm trying to use the coordinate out of the querySourceFeatures to animate a marker, however since the coordinate changes on different zoom levels I run into issues where the coordinate is "invalid" so the marker "disappears".

Is there a temporary alternative to getting the original coordinate?
Is it possible to reverse calculate the coordinate based on tile & zoom level?
Or should I also put the original coordinate as a property in the geojson?

In my case I'm trying to incorporate dynamic behaviour such that when someone selects a feature's Id (elsewhere in the app) I'd like to be able to query the feature (to derive the centroid or bounds) and then fly towards (or fit the bounds) of the selected feature. When zoomed-in and the feature is off-screen, or if only partially (split over adjacent tiles?) then the query returns null or off-centre locations, respectively.

Long story short, it would be really useful to have access to the original features, or at least the original feature centroids or bounds. This saves having to preprocess the geometry elsewhere and storing bounds / centroids.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PBrockmann picture PBrockmann  路  3Comments

iamdenny picture iamdenny  路  3Comments

BernhardRode picture BernhardRode  路  3Comments

muesliq picture muesliq  路  3Comments

stevage picture stevage  路  3Comments