Search in sources :

Example 1 with TileRegionError

use of com.mapbox.common.TileRegionError in project maps by rnmapbox.

the class RCTMGLOfflineModule method convertRegionsToJSON.

private void convertRegionsToJSON(List<TileRegion> tileRegions, Promise promise) {
    CountDownLatch countDownLatch = new CountDownLatch(tileRegions.size());
    ArrayList<TileRegionError> errors = new ArrayList<>();
    ArrayList<Geometry> geometries = new ArrayList<>();
    try {
        for (TileRegion region : tileRegions) {
            getTileStore().getTileRegionGeometry(region.getId(), new TileRegionGeometryCallback() {

                @Override
                public void run(@NonNull Expected<TileRegionError, Geometry> result) {
                    if (result.isValue()) {
                        geometries.add(result.getValue());
                    } else {
                        errors.add(result.getError());
                    }
                    countDownLatch.countDown();
                }
            });
        }
    } catch (Error error) {
        Logger.e("OS", "a");
    }
    try {
        countDownLatch.await();
        WritableArray result = Arguments.createArray();
        for (Geometry geometry : geometries) {
            result.pushMap(fromOfflineRegion(geometry));
        }
        for (TileRegionError error : errors) {
            WritableMap errorMap = Arguments.createMap();
            errorMap.putString("type", "error");
            errorMap.putString("message", error.getMessage());
            errorMap.putString("errorType", error.getType().toString());
            result.pushMap(errorMap);
        }
        promise.resolve(result);
    } catch (InterruptedException interruptedException) {
        promise.reject(interruptedException);
    }
}
Also used : TileRegionGeometryCallback(com.mapbox.common.TileRegionGeometryCallback) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) ArrayList(java.util.ArrayList) TileRegionError(com.mapbox.common.TileRegionError) CountDownLatch(java.util.concurrent.CountDownLatch) TileRegion(com.mapbox.common.TileRegion) Geometry(com.mapbox.geojson.Geometry) TileRegionError(com.mapbox.common.TileRegionError)

Aggregations

WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 TileRegion (com.mapbox.common.TileRegion)1 TileRegionError (com.mapbox.common.TileRegionError)1 TileRegionGeometryCallback (com.mapbox.common.TileRegionGeometryCallback)1 Geometry (com.mapbox.geojson.Geometry)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1