Search in sources :

Example 1 with CameraPosition

use of com.yandex.mapkit.map.CameraPosition 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 2 with CameraPosition

use of com.yandex.mapkit.map.CameraPosition 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 3 with CameraPosition

use of com.yandex.mapkit.map.CameraPosition in project react-native-yamap by volga-volga.

the class YamapView method emitCameraPositionToJS.

public void emitCameraPositionToJS(String id) {
    CameraPosition position = getMap().getCameraPosition();
    WritableMap cameraPosition = positionToJSON(position, true);
    cameraPosition.putString("id", id);
    ReactContext reactContext = (ReactContext) getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "cameraPosition", cameraPosition);
}
Also used : CameraPosition(com.yandex.mapkit.map.CameraPosition) WritableMap(com.facebook.react.bridge.WritableMap) ReactContext(com.facebook.react.bridge.ReactContext) RCTEventEmitter(com.facebook.react.uimanager.events.RCTEventEmitter)

Example 4 with CameraPosition

use of com.yandex.mapkit.map.CameraPosition in project react-native-yamap by volga-volga.

the class YamapView method setZoom.

public void setZoom(Float zoom, float duration, int animation) {
    CameraPosition prevPosition = getMap().getCameraPosition();
    CameraPosition position = new CameraPosition(prevPosition.getTarget(), zoom, prevPosition.getAzimuth(), prevPosition.getTilt());
    setCenter(position, duration, animation);
}
Also used : CameraPosition(com.yandex.mapkit.map.CameraPosition)

Aggregations

CameraPosition (com.yandex.mapkit.map.CameraPosition)4 Point (com.yandex.mapkit.geometry.Point)2 ReactContext (com.facebook.react.bridge.ReactContext)1 WritableMap (com.facebook.react.bridge.WritableMap)1 RCTEventEmitter (com.facebook.react.uimanager.events.RCTEventEmitter)1 Animation (com.yandex.mapkit.Animation)1 RequestPoint (com.yandex.mapkit.RequestPoint)1 BoundingBox (com.yandex.mapkit.geometry.BoundingBox)1 ArrayList (java.util.ArrayList)1 ReactMapObject (ru.vvdev.yamap.models.ReactMapObject)1