Search in sources :

Example 6 with Point

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

the class YamapViewManager method setCenter.

private void setCenter(YamapView view, ReadableMap center, float zoom, float azimuth, float tilt, float duration, int animation) {
    if (center != null) {
        Point centerPosition = new Point(center.getDouble("lat"), center.getDouble("lon"));
        CameraPosition pos = new CameraPosition(centerPosition, zoom, azimuth, tilt);
        view.setCenter(pos, duration, animation);
    }
}
Also used : CameraPosition(com.yandex.mapkit.map.CameraPosition) Point(com.yandex.mapkit.geometry.Point)

Example 7 with Point

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

the class YamapView method fitAllMarkers.

public void fitAllMarkers() {
    ArrayList<Point> lastKnownMarkers = new ArrayList<>();
    for (int i = 0; i < childs.size(); ++i) {
        ReactMapObject obj = childs.get(i);
        if (obj instanceof YamapMarker) {
            YamapMarker marker = (YamapMarker) obj;
            lastKnownMarkers.add(marker.point);
        }
    }
    // todo[0]: добавить параметры анимации и дефолтного зума (для одного маркера)
    if (lastKnownMarkers.size() == 0) {
        return;
    }
    if (lastKnownMarkers.size() == 1) {
        Point center = new Point(lastKnownMarkers.get(0).getLatitude(), lastKnownMarkers.get(0).getLongitude());
        getMap().move(new CameraPosition(center, 15, 0, 0));
        return;
    }
    double minLon = lastKnownMarkers.get(0).getLongitude();
    double maxLon = lastKnownMarkers.get(0).getLongitude();
    double minLat = lastKnownMarkers.get(0).getLatitude();
    double maxLat = lastKnownMarkers.get(0).getLatitude();
    for (int i = 0; i < lastKnownMarkers.size(); i++) {
        if (lastKnownMarkers.get(i).getLongitude() > maxLon) {
            maxLon = lastKnownMarkers.get(i).getLongitude();
        }
        if (lastKnownMarkers.get(i).getLongitude() < minLon) {
            minLon = lastKnownMarkers.get(i).getLongitude();
        }
        if (lastKnownMarkers.get(i).getLatitude() > maxLat) {
            maxLat = lastKnownMarkers.get(i).getLatitude();
        }
        if (lastKnownMarkers.get(i).getLatitude() < minLat) {
            minLat = lastKnownMarkers.get(i).getLatitude();
        }
    }
    Point southWest = new Point(minLat, minLon);
    Point northEast = new Point(maxLat, maxLon);
    BoundingBox boundingBox = new BoundingBox(southWest, northEast);
    CameraPosition cameraPosition = getMap().cameraPosition(boundingBox);
    cameraPosition = new CameraPosition(cameraPosition.getTarget(), cameraPosition.getZoom() - 0.8f, cameraPosition.getAzimuth(), cameraPosition.getTilt());
    getMap().move(cameraPosition, new Animation(Animation.Type.SMOOTH, 0.7f), null);
}
Also used : CameraPosition(com.yandex.mapkit.map.CameraPosition) ReactMapObject(ru.vvdev.yamap.models.ReactMapObject) BoundingBox(com.yandex.mapkit.geometry.BoundingBox) ArrayList(java.util.ArrayList) Animation(com.yandex.mapkit.Animation) Point(com.yandex.mapkit.geometry.Point) RequestPoint(com.yandex.mapkit.RequestPoint) Point(com.yandex.mapkit.geometry.Point) RequestPoint(com.yandex.mapkit.RequestPoint)

Example 8 with Point

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

Example 9 with Point

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

Example 10 with Point

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

the class YamapView method positionToJSON.

private WritableMap positionToJSON(CameraPosition position, boolean finished) {
    WritableMap cameraPosition = Arguments.createMap();
    Point point = position.getTarget();
    cameraPosition.putDouble("azimuth", position.getAzimuth());
    cameraPosition.putDouble("tilt", position.getTilt());
    cameraPosition.putDouble("zoom", position.getZoom());
    WritableMap target = Arguments.createMap();
    target.putDouble("lat", point.getLatitude());
    target.putDouble("lon", point.getLongitude());
    cameraPosition.putMap("point", target);
    cameraPosition.putBoolean("finished", finished);
    return cameraPosition;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) Point(com.yandex.mapkit.geometry.Point) RequestPoint(com.yandex.mapkit.RequestPoint)

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