Search in sources :

Example 1 with RenderedQueryOptions

use of com.mapbox.maps.RenderedQueryOptions in project maps by rnmapbox.

the class RCTMGLMapView method handleTapInSources.

void handleTapInSources(LinkedList<RCTSource> sources, ScreenCoordinate screenPoint, HashMap<String, List<Feature>> hits, ArrayList<RCTSource> hitTouchableSources, HandleTap handleTap) {
    if (sources.isEmpty()) {
        handleTap.run(hitTouchableSources, hits);
        return;
    }
    RCTSource source = sources.removeFirst();
    Map<String, Double> hitbox = source.getTouchHitbox();
    if (hitbox != null) {
        double halfWidth = hitbox.get("width").floatValue() / 2.0f;
        double halfHeight = hitbox.get("height").floatValue() / 2.0f;
        ScreenBox screenBox = new ScreenBox(new ScreenCoordinate(screenPoint.getX() - halfWidth, screenPoint.getY() - halfHeight), new ScreenCoordinate(screenPoint.getX() + halfWidth, screenPoint.getY() + halfHeight));
        getMapboxMap().queryRenderedFeatures(screenBox, new RenderedQueryOptions(source.getLayerIDs(), null), new QueryFeaturesCallback() {

            @Override
            public void run(@NonNull Expected<String, List<QueriedFeature>> features) {
                HashMap<String, List<Feature>> newHits = hits;
                if (features.isValue()) {
                    if (features.getValue().size() > 0) {
                        ArrayList<Feature> featuresList = new ArrayList<>();
                        for (QueriedFeature i : features.getValue()) {
                            featuresList.add(i.getFeature());
                        }
                        newHits.put(source.getID(), featuresList);
                        hitTouchableSources.add(source);
                    }
                } else {
                    Logger.e("handleTapInSources", features.getError());
                }
                handleTapInSources(sources, screenPoint, newHits, hitTouchableSources, handleTap);
            }
        });
    }
}
Also used : RCTSource(com.mapbox.rctmgl.components.styles.sources.RCTSource) HashMap(java.util.HashMap) ScreenCoordinate(com.mapbox.maps.ScreenCoordinate) ArrayList(java.util.ArrayList) QueryFeaturesCallback(com.mapbox.maps.QueryFeaturesCallback) Feature(com.mapbox.geojson.Feature) QueriedFeature(com.mapbox.maps.QueriedFeature) AbstractMapFeature(com.mapbox.rctmgl.components.AbstractMapFeature) RenderedQueryOptions(com.mapbox.maps.RenderedQueryOptions) QueriedFeature(com.mapbox.maps.QueriedFeature) ScreenBox(com.mapbox.maps.ScreenBox) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

Feature (com.mapbox.geojson.Feature)1 QueriedFeature (com.mapbox.maps.QueriedFeature)1 QueryFeaturesCallback (com.mapbox.maps.QueryFeaturesCallback)1 RenderedQueryOptions (com.mapbox.maps.RenderedQueryOptions)1 ScreenBox (com.mapbox.maps.ScreenBox)1 ScreenCoordinate (com.mapbox.maps.ScreenCoordinate)1 AbstractMapFeature (com.mapbox.rctmgl.components.AbstractMapFeature)1 RCTSource (com.mapbox.rctmgl.components.styles.sources.RCTSource)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1