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