Search in sources :

Example 1 with RouteStop

use of com.yandex.mapkit.transport.masstransit.RouteStop in project react-native-yamap by volga-volga.

the class YamapView method convertRouteSection.

private WritableMap convertRouteSection(Route route, final Section section, Polyline geometry, Weight routeWeight, int routeIndex) {
    SectionMetadata.SectionData data = section.getMetadata().getData();
    WritableMap routeMetadata = Arguments.createMap();
    WritableMap routeWeightData = Arguments.createMap();
    WritableMap sectionWeightData = Arguments.createMap();
    Map<String, ArrayList<String>> transports = new HashMap<>();
    routeWeightData.putString("time", routeWeight.getTime().getText());
    routeWeightData.putInt("transferCount", routeWeight.getTransfersCount());
    routeWeightData.putDouble("walkingDistance", routeWeight.getWalkingDistance().getValue());
    sectionWeightData.putString("time", section.getMetadata().getWeight().getTime().getText());
    sectionWeightData.putInt("transferCount", section.getMetadata().getWeight().getTransfersCount());
    sectionWeightData.putDouble("walkingDistance", section.getMetadata().getWeight().getWalkingDistance().getValue());
    routeMetadata.putMap("sectionInfo", sectionWeightData);
    routeMetadata.putMap("routeInfo", routeWeightData);
    routeMetadata.putInt("routeIndex", routeIndex);
    final WritableArray stops = new WritableNativeArray();
    for (RouteStop stop : section.getStops()) {
        stops.pushString(stop.getStop().getName());
    }
    routeMetadata.putArray("stops", stops);
    if (data.getTransports() != null) {
        for (Transport transport : data.getTransports()) {
            for (String type : transport.getLine().getVehicleTypes()) {
                if (type.equals("suburban"))
                    continue;
                if (transports.get(type) != null) {
                    ArrayList<String> list = transports.get(type);
                    if (list != null) {
                        list.add(transport.getLine().getName());
                        transports.put(type, list);
                    }
                } else {
                    ArrayList<String> list = new ArrayList<>();
                    list.add(transport.getLine().getName());
                    transports.put(type, list);
                }
                routeMetadata.putString("type", type);
                int color = Color.BLACK;
                if (transportHasStyle(transport)) {
                    try {
                        color = transport.getLine().getStyle().getColor();
                    } catch (Exception ignored) {
                    }
                }
                routeMetadata.putString("sectionColor", formatColor(color));
            }
        }
    } else {
        routeMetadata.putString("sectionColor", formatColor(Color.DKGRAY));
        if (section.getMetadata().getWeight().getWalkingDistance().getValue() == 0) {
            routeMetadata.putString("type", "waiting");
        } else {
            routeMetadata.putString("type", "walk");
        }
    }
    WritableMap wTransports = Arguments.createMap();
    for (Map.Entry<String, ArrayList<String>> entry : transports.entrySet()) {
        wTransports.putArray(entry.getKey(), Arguments.fromList(entry.getValue()));
    }
    routeMetadata.putMap("transports", wTransports);
    Polyline subpolyline = SubpolylineHelper.subpolyline(route.getGeometry(), section.getGeometry());
    List<Point> linePoints = subpolyline.getPoints();
    WritableArray jsonPoints = Arguments.createArray();
    for (Point point : linePoints) {
        WritableMap jsonPoint = Arguments.createMap();
        jsonPoint.putDouble("lat", point.getLatitude());
        jsonPoint.putDouble("lon", point.getLongitude());
        jsonPoints.pushMap(jsonPoint);
    }
    routeMetadata.putArray("points", jsonPoints);
    return routeMetadata;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) HashMap(java.util.HashMap) WritableArray(com.facebook.react.bridge.WritableArray) ArrayList(java.util.ArrayList) Point(com.yandex.mapkit.geometry.Point) RequestPoint(com.yandex.mapkit.RequestPoint) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) Point(com.yandex.mapkit.geometry.Point) RequestPoint(com.yandex.mapkit.RequestPoint) SectionMetadata(com.yandex.mapkit.transport.masstransit.SectionMetadata) Polyline(com.yandex.mapkit.geometry.Polyline) RouteStop(com.yandex.mapkit.transport.masstransit.RouteStop) Transport(com.yandex.mapkit.transport.masstransit.Transport) Map(java.util.Map) HashMap(java.util.HashMap) WritableMap(com.facebook.react.bridge.WritableMap)

Aggregations

WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 WritableNativeArray (com.facebook.react.bridge.WritableNativeArray)1 RequestPoint (com.yandex.mapkit.RequestPoint)1 Point (com.yandex.mapkit.geometry.Point)1 Polyline (com.yandex.mapkit.geometry.Polyline)1 RouteStop (com.yandex.mapkit.transport.masstransit.RouteStop)1 SectionMetadata (com.yandex.mapkit.transport.masstransit.SectionMetadata)1 Transport (com.yandex.mapkit.transport.masstransit.Transport)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1