Teiki
Teiki

Reputation: 200

MapBox queryRenderedFeatures return too much values

I'm using MapBox SDK for Android to display a geojson file on top of a map.

From geojson "features", I create some "fillLayer", each of them is associate to a value from properties object in geojson. I fill each layer with a colour corresponding to the value.

To get this value from a specific localisation I use the API call: "queryRenderedFeatures"

Here is how I create layer from previously created geojsonSource object:

for (int i=0; i < list_value_geojson.size(); i++){
    Map.Entry<Integer, GeoJsonSource> entry = list_value_geojson.get(i);
        mapboxMap.addSource(entry.getValue());
        FillLayer fillLayer = new FillLayer(entry.getValue().getId(), entry.getValue().getId());
        fillLayer.setProperties(PropertyFactory.fillColor(Color.parseColor(hashMapColors.get(entry.getKey()))));
        mapboxMap.addLayer(fillLayer);
}

Here, how I use queryRenderedFeatures from a "Location" object:

final PointF pixel = my_mapboxMap.getProjection().toScreenLocation(new LatLng(location.getLatitude(), location.getLongitude()));
List<Feature> features = my_mapboxMap.queryRenderedFeatures(pixel);

My problem

queryRenderedFeatures function, sometime, return me too much Features, exemple: I search for a specific location and I get three features, but only the third one has the correct value, the two first have the value from the layer just next to.

Exemple

Wrong value

The good value is 174 not 181, colour should be dark bue.

Here is queryrenderedfeatures result:

0 = {Feature@6242} : {"value":181}
1 = {Feature@6243} : {"value":181}
2 = {Feature@6244} : {"value":174}

Question

How do I know which feature should I use? MapBox "know" because the colour of the display layer is correct.

Thank you a lot for having read me.

Upvotes: 2

Views: 1596

Answers (1)

cammace
cammace

Reputation: 3168

You can limit the layer you are querying by passing in the layer id as a parameter in the queryRenderedFeatures method. Checkout this example.

Upvotes: 1

Related Questions