Search in sources :

Example 1 with BoundingBox

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

Aggregations

Animation (com.yandex.mapkit.Animation)1 RequestPoint (com.yandex.mapkit.RequestPoint)1 BoundingBox (com.yandex.mapkit.geometry.BoundingBox)1 Point (com.yandex.mapkit.geometry.Point)1 CameraPosition (com.yandex.mapkit.map.CameraPosition)1 ArrayList (java.util.ArrayList)1 ReactMapObject (ru.vvdev.yamap.models.ReactMapObject)1