Search in sources :

Example 1 with AndroidCallbackEvent

use of com.mapbox.rctmgl.events.AndroidCallbackEvent in project maps by rnmapbox.

the class RCTMGLRasterDemSource method querySourceFeatures.

public void querySourceFeatures(String callbackID, @Size(min = 1) List<String> layerIDs, @Nullable Expression filter) {
    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;
    }
    WritableMap payload = new WritableNativeMap();
    mMap.querySourceFeatures(mID, new SourceQueryOptions(layerIDs, filter), new QueryFeaturesCallback() {

        @Override
        public void run(@NonNull Expected<String, List<QueriedFeature>> queriedFeatures) {
            if (queriedFeatures.isError()) {
                // V10todo
                payload.putString("error", queriedFeatures.getError());
            } else {
                List<Feature> features = new LinkedList<>();
                for (QueriedFeature feature : queriedFeatures.getValue()) {
                    features.add(feature.getFeature());
                }
                payload.putString("data", FeatureCollection.fromFeatures(features).toJson());
            }
        }
    });
    AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
    mManager.handleEvent(event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) QueriedFeature(com.mapbox.maps.QueriedFeature) SourceQueryOptions(com.mapbox.maps.SourceQueryOptions) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) QueryFeaturesCallback(com.mapbox.maps.QueryFeaturesCallback) AndroidCallbackEvent(com.mapbox.rctmgl.events.AndroidCallbackEvent)

Example 2 with AndroidCallbackEvent

use of com.mapbox.rctmgl.events.AndroidCallbackEvent 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)

Example 3 with AndroidCallbackEvent

use of com.mapbox.rctmgl.events.AndroidCallbackEvent in project maps by rnmapbox.

the class RCTMGLMapView method getZoom.

public void getZoom(String callbackID) {
    CameraPosition position = mMap.getCameraPosition();
    WritableMap payload = new WritableNativeMap();
    payload.putDouble("zoom", position.zoom);
    AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
    mManager.handleEvent(event);
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) WritableMap(com.facebook.react.bridge.WritableMap) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) AndroidCallbackEvent(com.mapbox.rctmgl.events.AndroidCallbackEvent)

Example 4 with AndroidCallbackEvent

use of com.mapbox.rctmgl.events.AndroidCallbackEvent in project maps by rnmapbox.

the class RCTMGLMapView method queryRenderedFeaturesInRect.

public void queryRenderedFeaturesInRect(String callbackID, RectF rect, Expression filter, List<String> layerIDs) {
    List<Feature> features = mMap.queryRenderedFeatures(rect, filter, layerIDs.toArray(new String[layerIDs.size()]));
    WritableMap payload = new WritableNativeMap();
    payload.putString("data", FeatureCollection.fromFeatures(features).toJson());
    AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
    mManager.handleEvent(event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) Feature(com.mapbox.geojson.Feature) AbstractMapFeature(com.mapbox.rctmgl.components.AbstractMapFeature) AndroidCallbackEvent(com.mapbox.rctmgl.events.AndroidCallbackEvent)

Example 5 with AndroidCallbackEvent

use of com.mapbox.rctmgl.events.AndroidCallbackEvent in project maps by rnmapbox.

the class RCTMGLMapView method getCenter.

public void getCenter(String callbackID) {
    LatLng center = mMap.getCameraPosition().target;
    WritableArray array = new WritableNativeArray();
    array.pushDouble(center.getLongitude());
    array.pushDouble(center.getLatitude());
    WritableMap payload = new WritableNativeMap();
    payload.putArray("center", array);
    AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
    mManager.handleEvent(event);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) AndroidCallbackEvent(com.mapbox.rctmgl.events.AndroidCallbackEvent)

Aggregations

WritableMap (com.facebook.react.bridge.WritableMap)19 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)19 AndroidCallbackEvent (com.mapbox.rctmgl.events.AndroidCallbackEvent)19 Feature (com.mapbox.geojson.Feature)10 FeatureCollection (com.mapbox.geojson.FeatureCollection)4 WritableArray (com.facebook.react.bridge.WritableArray)3 WritableNativeArray (com.facebook.react.bridge.WritableNativeArray)3 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)2 QueriedFeature (com.mapbox.maps.QueriedFeature)2 QueryFeaturesCallback (com.mapbox.maps.QueryFeaturesCallback)2 SourceQueryOptions (com.mapbox.maps.SourceQueryOptions)2 AbstractMapFeature (com.mapbox.rctmgl.components.AbstractMapFeature)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PointF (android.graphics.PointF)1 NonNull (androidx.annotation.NonNull)1 Expected (com.mapbox.bindgen.Expected)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 VisibleRegion (com.mapbox.mapboxsdk.geometry.VisibleRegion)1 QueryFeatureExtensionCallback (com.mapbox.maps.QueryFeatureExtensionCallback)1