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