Search in sources :

Example 1 with Point

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

the class YamapMarker method animatedMoveTo.

public void animatedMoveTo(Point point, final float duration) {
    PlacemarkMapObject placemark = (PlacemarkMapObject) this.getMapObject();
    Point p = placemark.getGeometry();
    final double startLat = p.getLatitude();
    final double startLon = p.getLongitude();
    final double deltaLat = point.getLatitude() - startLat;
    final double deltaLon = point.getLongitude() - startLon;
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
    valueAnimator.setDuration((long) duration);
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            try {
                float v = animation.getAnimatedFraction();
                moveAnimationLoop(startLat + v * deltaLat, startLon + v * deltaLon);
            } catch (Exception ex) {
            // I don't care atm..
            }
        }
    });
    valueAnimator.start();
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) Point(com.yandex.mapkit.geometry.Point) ValueAnimator(android.animation.ValueAnimator) PlacemarkMapObject(com.yandex.mapkit.map.PlacemarkMapObject)

Example 2 with Point

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

the class YamapMarker method moveAnimationLoop.

public void moveAnimationLoop(double lat, double lon) {
    PlacemarkMapObject placemark = (PlacemarkMapObject) this.getMapObject();
    placemark.setGeometry(new Point(lat, lon));
}
Also used : Point(com.yandex.mapkit.geometry.Point) PlacemarkMapObject(com.yandex.mapkit.map.PlacemarkMapObject)

Example 3 with Point

use of com.yandex.mapkit.geometry.Point 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 4 with Point

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

the class YamapPolygonManager method setInnerRings.

@ReactProp(name = "innerRings")
public void setInnerRings(View view, ReadableArray _rings) {
    ArrayList<ArrayList<Point>> rings = new ArrayList<>();
    if (_rings != null) {
        for (int j = 0; j < _rings.size(); ++j) {
            ReadableArray points = _rings.getArray(j);
            if (points != null) {
                ArrayList<Point> parsed = new ArrayList<>();
                for (int i = 0; i < points.size(); ++i) {
                    ReadableMap markerMap = points.getMap(i);
                    if (markerMap != null) {
                        double lon = markerMap.getDouble("lon");
                        double lat = markerMap.getDouble("lat");
                        Point point = new Point(lat, lon);
                        parsed.add(point);
                    }
                }
                rings.add(parsed);
            }
        }
    }
    castToPolygonView(view).setInnerRings(rings);
}
Also used : ReadableArray(com.facebook.react.bridge.ReadableArray) ArrayList(java.util.ArrayList) ReadableMap(com.facebook.react.bridge.ReadableMap) Point(com.yandex.mapkit.geometry.Point) Point(com.yandex.mapkit.geometry.Point) ReactProp(com.facebook.react.uimanager.annotations.ReactProp)

Example 5 with Point

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

the class YamapPolygonManager method setPoints.

// props
@ReactProp(name = "points")
public void setPoints(View view, ReadableArray points) {
    if (points != null) {
        ArrayList<Point> parsed = new ArrayList<>();
        for (int i = 0; i < points.size(); ++i) {
            ReadableMap markerMap = points.getMap(i);
            if (markerMap != null) {
                double lon = markerMap.getDouble("lon");
                double lat = markerMap.getDouble("lat");
                Point point = new Point(lat, lon);
                parsed.add(point);
            }
        }
        castToPolygonView(view).setPolygonPoints(parsed);
    }
}
Also used : ArrayList(java.util.ArrayList) ReadableMap(com.facebook.react.bridge.ReadableMap) Point(com.yandex.mapkit.geometry.Point) Point(com.yandex.mapkit.geometry.Point) ReactProp(com.facebook.react.uimanager.annotations.ReactProp)

Aggregations

Point (com.yandex.mapkit.geometry.Point)15 ArrayList (java.util.ArrayList)8 ReadableMap (com.facebook.react.bridge.ReadableMap)5 ReactProp (com.facebook.react.uimanager.annotations.ReactProp)5 RequestPoint (com.yandex.mapkit.RequestPoint)5 WritableMap (com.facebook.react.bridge.WritableMap)4 WritableArray (com.facebook.react.bridge.WritableArray)3 WritableNativeArray (com.facebook.react.bridge.WritableNativeArray)2 Polyline (com.yandex.mapkit.geometry.Polyline)2 CameraPosition (com.yandex.mapkit.map.CameraPosition)2 PlacemarkMapObject (com.yandex.mapkit.map.PlacemarkMapObject)2 HashMap (java.util.HashMap)2 ValueAnimator (android.animation.ValueAnimator)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 NonNull (androidx.annotation.NonNull)1 ReadableArray (com.facebook.react.bridge.ReadableArray)1 Animation (com.yandex.mapkit.Animation)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