Search in sources :

Example 1 with Expected

use of com.mapbox.bindgen.Expected in project maps by rnmapbox.

the class RCTMGLShapeSource method getClusterExpansionZoom.

public void getClusterExpansionZoom(String callbackID, int clusterId) {
    if (mSource == null) {
        WritableMap payload = new WritableNativeMap();
        payload.putString("error", "source is not yet loaded");
        AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
        mManager.handleEvent(event);
        return;
    }
    SourceQueryOptions options = new SourceQueryOptions(null, Expression.eq(Expression.get("cluster_id"), Expression.literal(clusterId)));
    RCTMGLShapeSource _this = this;
    mMap.querySourceFeatures(getID(), options, new QueryFeaturesCallback() {

        @Override
        public void run(@NonNull Expected<String, List<QueriedFeature>> features) {
            if (features.isValue()) {
                QueriedFeature cluster = features.getValue().get(0);
                mMap.queryFeatureExtensions(getID(), cluster.getFeature(), "supercluster", "expansion-zoom", null, new QueryFeatureExtensionCallback() {

                    @Override
                    public void run(@NonNull Expected<String, FeatureExtensionValue> extension) {
                        if (extension.isValue()) {
                            Object contents = extension.getValue().getValue().getContents();
                            if (contents instanceof Long) {
                                WritableMap payload = new WritableNativeMap();
                                payload.putInt("data", ((Long) contents).intValue());
                                AndroidCallbackEvent event = new AndroidCallbackEvent(_this, callbackID, payload);
                                mManager.handleEvent(event);
                                return;
                            } else {
                                callbackError(callbackID, "Not a number", "getClusterExpansionZoom/queryFeatureExtensions2");
                                return;
                            }
                        } else {
                            callbackError(callbackID, extension.getError(), "getClusterExpansionZoom/queryFeatureExtensions");
                            return;
                        }
                    }
                });
            } else {
                callbackError(callbackID, features.getError(), "getClusterExpansionZoom/querySourceFeatures");
                return;
            }
        }
    });
}
Also used : Expected(com.mapbox.bindgen.Expected) WritableMap(com.facebook.react.bridge.WritableMap) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) QueryFeaturesCallback(com.mapbox.maps.QueryFeaturesCallback) AndroidCallbackEvent(com.mapbox.rctmgl.events.AndroidCallbackEvent) QueryFeatureExtensionCallback(com.mapbox.maps.QueryFeatureExtensionCallback) QueriedFeature(com.mapbox.maps.QueriedFeature) SourceQueryOptions(com.mapbox.maps.SourceQueryOptions) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

NonNull (androidx.annotation.NonNull)1 WritableMap (com.facebook.react.bridge.WritableMap)1 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)1 Expected (com.mapbox.bindgen.Expected)1 QueriedFeature (com.mapbox.maps.QueriedFeature)1 QueryFeatureExtensionCallback (com.mapbox.maps.QueryFeatureExtensionCallback)1 QueryFeaturesCallback (com.mapbox.maps.QueryFeaturesCallback)1 SourceQueryOptions (com.mapbox.maps.SourceQueryOptions)1 AndroidCallbackEvent (com.mapbox.rctmgl.events.AndroidCallbackEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1