Search in sources :

Example 1 with Error

use of com.yandex.runtime.Error in project react-native-yamap by volga-volga.

the class YamapView method findRoutes.

public void findRoutes(ArrayList<Point> points, final ArrayList<String> vehicles, final String id) {
    final YamapView self = this;
    if (vehicles.size() == 1 && vehicles.get(0).equals("car")) {
        DrivingSession.DrivingRouteListener listener = new DrivingSession.DrivingRouteListener() {

            @Override
            public void onDrivingRoutes(@NonNull List<DrivingRoute> routes) {
                WritableArray jsonRoutes = Arguments.createArray();
                for (int i = 0; i < routes.size(); ++i) {
                    DrivingRoute _route = routes.get(i);
                    WritableMap jsonRoute = Arguments.createMap();
                    String id = RouteManager.generateId();
                    jsonRoute.putString("id", id);
                    WritableArray sections = Arguments.createArray();
                    for (DrivingSection section : _route.getSections()) {
                        WritableMap jsonSection = convertDrivingRouteSection(_route, section, i);
                        sections.pushMap(jsonSection);
                    }
                    jsonRoute.putArray("sections", sections);
                    jsonRoutes.pushMap(jsonRoute);
                }
                self.onRoutesFound(id, jsonRoutes, "success");
            }

            @Override
            public void onDrivingRoutesError(@NonNull Error error) {
                self.onRoutesFound(id, Arguments.createArray(), "error");
            }
        };
        ArrayList<RequestPoint> _points = new ArrayList<>();
        for (int i = 0; i < points.size(); ++i) {
            Point point = points.get(i);
            RequestPoint _p = new RequestPoint(point, RequestPointType.WAYPOINT, null);
            _points.add(_p);
        }
        drivingRouter.requestRoutes(_points, new DrivingOptions(), new VehicleOptions(), listener);
        return;
    }
    ArrayList<RequestPoint> _points = new ArrayList<>();
    for (int i = 0; i < points.size(); ++i) {
        Point point = points.get(i);
        _points.add(new RequestPoint(point, RequestPointType.WAYPOINT, null));
    }
    Session.RouteListener listener = new Session.RouteListener() {

        @Override
        public void onMasstransitRoutes(@NonNull List<Route> routes) {
            WritableArray jsonRoutes = Arguments.createArray();
            for (int i = 0; i < routes.size(); ++i) {
                Route _route = routes.get(i);
                WritableMap jsonRoute = Arguments.createMap();
                String id = RouteManager.generateId();
                self.routeMng.saveRoute(_route, id);
                jsonRoute.putString("id", id);
                WritableArray sections = Arguments.createArray();
                for (Section section : _route.getSections()) {
                    WritableMap jsonSection = convertRouteSection(_route, section, SubpolylineHelper.subpolyline(_route.getGeometry(), section.getGeometry()), _route.getMetadata().getWeight(), i);
                    sections.pushMap(jsonSection);
                }
                jsonRoute.putArray("sections", sections);
                jsonRoutes.pushMap(jsonRoute);
            }
            self.onRoutesFound(id, jsonRoutes, "success");
        }

        @Override
        public void onMasstransitRoutesError(@NonNull Error error) {
            self.onRoutesFound(id, Arguments.createArray(), "error");
        }
    };
    if (vehicles.size() == 0) {
        pedestrianRouter.requestRoutes(_points, new TimeOptions(), listener);
        return;
    }
    MasstransitOptions masstransitOptions = new MasstransitOptions(new ArrayList<String>(), vehicles, new TimeOptions());
    masstransitRouter.requestRoutes(_points, masstransitOptions, listener);
}
Also used : RequestPoint(com.yandex.mapkit.RequestPoint) MasstransitOptions(com.yandex.mapkit.transport.masstransit.MasstransitOptions) ArrayList(java.util.ArrayList) TimeOptions(com.yandex.mapkit.transport.masstransit.TimeOptions) NonNull(androidx.annotation.NonNull) DrivingRoute(com.yandex.mapkit.directions.driving.DrivingRoute) List(java.util.List) ArrayList(java.util.ArrayList) DrivingSession(com.yandex.mapkit.directions.driving.DrivingSession) DrivingRoute(com.yandex.mapkit.directions.driving.DrivingRoute) Route(com.yandex.mapkit.transport.masstransit.Route) DrivingOptions(com.yandex.mapkit.directions.driving.DrivingOptions) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) Error(com.yandex.runtime.Error) Point(com.yandex.mapkit.geometry.Point) RequestPoint(com.yandex.mapkit.RequestPoint) Section(com.yandex.mapkit.transport.masstransit.Section) DrivingSection(com.yandex.mapkit.directions.driving.DrivingSection) Point(com.yandex.mapkit.geometry.Point) RequestPoint(com.yandex.mapkit.RequestPoint) DrivingSection(com.yandex.mapkit.directions.driving.DrivingSection) VehicleOptions(com.yandex.mapkit.directions.driving.VehicleOptions) DrivingSession(com.yandex.mapkit.directions.driving.DrivingSession) Session(com.yandex.mapkit.transport.masstransit.Session)

Aggregations

NonNull (androidx.annotation.NonNull)1 WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 RequestPoint (com.yandex.mapkit.RequestPoint)1 DrivingOptions (com.yandex.mapkit.directions.driving.DrivingOptions)1 DrivingRoute (com.yandex.mapkit.directions.driving.DrivingRoute)1 DrivingSection (com.yandex.mapkit.directions.driving.DrivingSection)1 DrivingSession (com.yandex.mapkit.directions.driving.DrivingSession)1 VehicleOptions (com.yandex.mapkit.directions.driving.VehicleOptions)1 Point (com.yandex.mapkit.geometry.Point)1 MasstransitOptions (com.yandex.mapkit.transport.masstransit.MasstransitOptions)1 Route (com.yandex.mapkit.transport.masstransit.Route)1 Section (com.yandex.mapkit.transport.masstransit.Section)1 Session (com.yandex.mapkit.transport.masstransit.Session)1 TimeOptions (com.yandex.mapkit.transport.masstransit.TimeOptions)1 Error (com.yandex.runtime.Error)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1