Search in sources :

Example 1 with Polyline

use of com.yandex.mapkit.geometry.Polyline in project react-native-yamap by volga-volga.

the class YamapPolyline method setPolygonPoints.

// props
public void setPolygonPoints(ArrayList<Point> points) {
    _points = points != null ? points : new ArrayList<Point>();
    polyline = new Polyline(_points);
    updatePolyline();
}
Also used : ArrayList(java.util.ArrayList) Polyline(com.yandex.mapkit.geometry.Polyline)

Example 2 with Polyline

use of com.yandex.mapkit.geometry.Polyline 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)

Example 3 with Polyline

use of com.yandex.mapkit.geometry.Polyline in project react-native-yamap by volga-volga.

the class YamapView method convertDrivingRouteSection.

private WritableMap convertDrivingRouteSection(DrivingRoute route, final DrivingSection section, int routeIndex) {
    com.yandex.mapkit.directions.driving.Weight routeWeight = route.getMetadata().getWeight();
    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.putString("timeWithTraffic", routeWeight.getTimeWithTraffic().getText());
    routeWeightData.putDouble("distance", routeWeight.getDistance().getValue());
    sectionWeightData.putString("time", section.getMetadata().getWeight().getTime().getText());
    sectionWeightData.putString("timeWithTraffic", section.getMetadata().getWeight().getTimeWithTraffic().getText());
    sectionWeightData.putDouble("distance", section.getMetadata().getWeight().getDistance().getValue());
    routeMetadata.putMap("sectionInfo", sectionWeightData);
    routeMetadata.putMap("routeInfo", routeWeightData);
    routeMetadata.putInt("routeIndex", routeIndex);
    final WritableArray stops = new WritableNativeArray();
    routeMetadata.putArray("stops", stops);
    routeMetadata.putString("sectionColor", formatColor(Color.DKGRAY));
    if (section.getMetadata().getWeight().getDistance().getValue() == 0) {
        routeMetadata.putString("type", "waiting");
    } else {
        routeMetadata.putString("type", "car");
    }
    WritableMap wTransports = Arguments.createMap();
    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) Polyline(com.yandex.mapkit.geometry.Polyline)

Aggregations

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