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);
}
Aggregations