use of net.osmand.router.TransportRouteResult in project OsmAnd-tools by osmandapp.
the class MapTransportLayer method paintLayer.
@Override
public void paintLayer(Graphics2D g) {
TransportRouteResult r = null;
if (results.size() > currentRoute && currentRoute >= 0) {
r = results.get(currentRoute);
}
if (r != null) {
g.setColor(Color.blue);
int rad = 10;
for (TransportRouteResultSegment s : r.getSegments()) {
LatLon l = s.getStart().getLocation();
int x = map.getMapXForPoint(l.getLongitude());
int y = map.getMapYForPoint(l.getLatitude());
g.drawOval(x, y, rad, rad);
g.fillOval(x, y, rad, rad);
}
rad = 9;
g.setColor(Color.red);
for (TransportRouteResultSegment s : r.getSegments()) {
LatLon l = s.getEnd().getLocation();
int x = map.getMapXForPoint(l.getLongitude());
int y = map.getMapYForPoint(l.getLatitude());
g.drawOval(x, y, rad, rad);
g.fillOval(x, y, rad, rad);
}
}
}
use of net.osmand.router.TransportRouteResult in project OsmAnd-tools by osmandapp.
the class MapTransportLayer method redrawRoute.
private void redrawRoute() {
List<Way> ways = new ArrayList<Way>();
TransportRouteResult r = null;
if (results.size() > currentRoute && currentRoute >= 0) {
r = results.get(currentRoute);
}
calculateResult(ways, r);
DataTileManager<Entity> points = new DataTileManager<>(11);
int ind = -1;
for (Way w : ways) {
Way wl = new Way(ind--);
Node node = w.getFirstNode();
wl.addNode(node);
long tile = points.evaluateTile(node.getLatitude(), node.getLongitude());
for (int i = 1; i < w.getNodes().size(); i++) {
Node nnode = w.getNodes().get(i);
long ntile = points.evaluateTile(nnode.getLatitude(), nnode.getLongitude());
wl.addNode(nnode);
if (tile != ntile) {
points.registerObject(wl.getFirstNode().getLatitude(), wl.getFirstNode().getLongitude(), wl);
tile = ntile;
wl = new Way(ind--);
wl.addNode(nnode);
}
}
if (wl.getNodes().size() > 0) {
points.registerObject(wl.getFirstNode().getLatitude(), wl.getFirstNode().getLongitude(), wl);
}
}
map.setPoints(points);
nextRoute.setVisible(r != null);
infoButton.setVisible(r != null);
if (r != null) {
String refs = "";
for (int i = 0; i < r.getSegments().size(); i++) {
TransportRouteResultSegment res = r.getSegments().get(i);
if (i > 0) {
refs += ", ";
}
refs += res.route.getRef();
}
infoButton.setText(String.format("%d. %.1f min (T %.1f min, W %.1f min): %s", currentRoute + 1, r.getRouteTime() / 60.0, r.getTravelTime() / 60.0, r.getWalkTime() / 60.0, refs));
}
prevRoute.setVisible(r != null);
map.prepareImage();
}
use of net.osmand.router.TransportRouteResult in project Osmand by osmandapp.
the class ChooseRouteFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
MapActivity mapActivity = (MapActivity) requireActivity();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
OsmandApplication app = mapActivity.getMyApplication();
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
List<TransportRouteResult> routes = transportRoutingHelper.getRoutes();
int routeIndex = 0;
int initialMenuState = MenuState.HEADER_ONLY;
Bundle args = getArguments();
if (args == null) {
args = savedInstanceState;
}
if (args != null) {
routeIndex = args.getInt(ROUTE_INDEX_KEY);
needAdjustMap = args.getBoolean(ADJUST_MAP_KEY, false);
initialMenuState = args.getInt(INITIAL_MENU_STATE_KEY, initialMenuState);
}
routesCount = 1;
if (routes != null && !routes.isEmpty()) {
publicTransportMode = true;
routesCount = routes.size();
}
ContextThemeWrapper context = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
View view = LayoutInflater.from(context).inflate(R.layout.fragment_show_all_routes, null);
AndroidUtils.addStatusBarPadding21v(mapActivity, view);
View solidToolbarView = view.findViewById(R.id.toolbar_layout);
this.solidToolbarView = solidToolbarView;
LockableViewPager viewPager = view.findViewById(R.id.pager);
this.viewPager = viewPager;
if (!portrait) {
initialMenuState = MenuState.FULL_SCREEN;
int width = getResources().getDimensionPixelSize(R.dimen.dashboard_land_width) - getResources().getDimensionPixelSize(R.dimen.dashboard_land_shadow_width);
solidToolbarView.setLayoutParams(new FrameLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
solidToolbarView.setVisibility(View.VISIBLE);
final TypedValue typedValueAttr = new TypedValue();
int bgAttrId = AndroidUtils.isLayoutRtl(mapActivity) ? R.attr.right_menu_view_bg : R.attr.left_menu_view_bg;
mapActivity.getTheme().resolveAttribute(bgAttrId, typedValueAttr, true);
view.findViewById(R.id.pager_container).setBackgroundResource(typedValueAttr.resourceId);
view.setLayoutParams(new FrameLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.dashboard_land_width), ViewGroup.LayoutParams.MATCH_PARENT));
}
viewPager.setClipToPadding(false);
currentMenuState = initialMenuState;
final RoutesPagerAdapter pagerAdapter = new RoutesPagerAdapter(getChildFragmentManager(), routesCount);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(routeIndex);
viewPager.setOffscreenPageLimit(1);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
public void onPageScrollStateChanged(int state) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
public void onPageSelected(int position) {
MapActivity mapActivity = getMapActivity();
View view = getView();
if (mapActivity != null && view != null) {
mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(position);
mapActivity.refreshMap();
buildPagesControl(view);
List<WeakReference<RouteDetailsFragment>> routeDetailsFragments = ChooseRouteFragment.this.routeDetailsFragments;
RouteDetailsFragment current = getCurrentFragment();
for (WeakReference<RouteDetailsFragment> ref : routeDetailsFragments) {
RouteDetailsFragment f = ref.get();
if (f != null) {
PublicTransportCard card = f.getTransportCard();
if (card != null) {
card.updateButtons();
}
if (f == current) {
updateZoomButtonsPos(f, f.getViewY(), true);
updatePagesViewPos(f, f.getViewY(), true);
}
Bundle args = f.getArguments();
if (args != null) {
args.putInt(ContextMenuFragment.MENU_STATE_KEY, currentMenuState);
}
}
}
}
}
});
this.pagesView = (ViewGroup) view.findViewById(R.id.pages_control);
buildPagesControl(view);
buildZoomButtons(view);
buildMenuButtons(view);
return view;
}
use of net.osmand.router.TransportRouteResult in project Osmand by osmandapp.
the class RouteLayer method drawLocations.
public void drawLocations(RotatedTileBox tb, Canvas canvas, double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
if (helper.isPublicTransportMode()) {
int currentRoute = transportHelper.getCurrentRoute();
List<TransportRouteResult> routes = transportHelper.getRoutes();
TransportRouteResult route = routes != null && routes.size() > currentRoute ? routes.get(currentRoute) : null;
routeGeometry.clearRoute();
publicTransportRouteGeometry.updateRoute(tb, route);
if (route != null) {
LatLon start = transportHelper.getStartLocation();
Location startLocation = new Location("transport");
startLocation.setLatitude(start.getLatitude());
startLocation.setLongitude(start.getLongitude());
publicTransportRouteGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, startLocation, 0);
}
} else {
RouteCalculationResult route = helper.getRoute();
boolean directTo = route.getRouteService() == RouteService.DIRECT_TO;
boolean straight = route.getRouteService() == RouteService.STRAIGHT;
publicTransportRouteGeometry.clearRoute();
ColoringType actualColoringType = isColoringAvailable(routeColoringType, routeInfoAttribute) ? routeColoringType : ColoringType.DEFAULT;
routeGeometry.setRouteStyleParams(getRouteLineColor(), getRouteLineWidth(tb), directionArrowsColor, actualColoringType, routeInfoAttribute);
routeGeometry.updateRoute(tb, route);
if (directTo) {
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, null, 0);
} else if (straight) {
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastFixedLocation(), route.getCurrentStraightAngleRoute());
} else {
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), route.getCurrentStraightAngleRoute());
}
List<RouteDirectionInfo> rd = helper.getRouteDirections();
Iterator<RouteDirectionInfo> it = rd.iterator();
if (!directTo && tb.getZoom() >= 14 && shouldShowTurnArrows()) {
List<Location> actionPoints = calculateActionPoints(topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), helper.getRoute().getRouteLocations(), helper.getRoute().getCurrentRoute(), it, tb.getZoom());
drawAction(tb, canvas, actionPoints);
}
if (directTo) {
// add projection point on original route
double[] projectionOnRoute = calculateProjectionOnRoutePoint(helper, tb);
if (projectionOnRoute != null) {
drawProjectionPoint(canvas, projectionOnRoute);
}
}
}
}
use of net.osmand.router.TransportRouteResult in project Osmand by osmandapp.
the class MapContextMenuFragment method updateLocalRoutesBadges.
private void updateLocalRoutesBadges(List<TransportStopRoute> localTransportStopRoutes, int localColumnsPerRow) {
int localRoutesSize = localTransportStopRoutes.size();
OsmandApplication app = requireMyApplication();
TransportRouteResult activeRoute = app.getRoutingHelper().getTransportRoutingHelper().getActiveRoute();
if (localRoutesSize > 0 && activeRoute != null) {
for (int i = 0; i < localTransportStopRoutes.size(); i++) {
final TransportStopRoute stopRoute = localTransportStopRoutes.get(i);
if (activeRoute.isRouteStop(stopRoute.stop)) {
View routeBadge = createRouteBadge(stopRoute);
mainRouteBadgeContainer.addView(routeBadge);
mainRouteBadgeContainer.setVisibility(View.VISIBLE);
mainRouteBadgeContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissMenu();
ChooseRouteFragment.showInstance(requireMyActivity().getSupportFragmentManager(), requireMyApplication().getRoutingHelper().getTransportRoutingHelper().getCurrentRoute(), ContextMenuFragment.MenuState.FULL_SCREEN);
/* fit route segment on map
TransportRouteResult activeRoute = requireMyApplication().getRoutingHelper().getTransportRoutingHelper().getActiveRoute();
if (activeRoute != null) {
TransportRouteResultSegment segment = activeRoute.getRouteStopSegment(stopRoute.stop);
if (segment != null) {
QuadRect rect = segment.getSegmentRect();
if (rect != null) {
//openMenuHeaderOnly();
fitRectOnMap(rect);
}
}
}
*/
}
});
localTransportStopRoutes.remove(i);
localRoutesSize--;
break;
}
}
}
if (localRoutesSize > 0) {
int maxLocalBadges = localColumnsPerRow * 5;
TransportStopRouteAdapter adapter;
if (localRoutesSize > maxLocalBadges) {
adapter = createTransportStopRouteAdapter(localTransportStopRoutes.subList(0, maxLocalBadges), false);
localRoutesMoreTv.setVisibility(View.VISIBLE);
} else {
adapter = createTransportStopRouteAdapter(localTransportStopRoutes, false);
localRoutesMoreTv.setVisibility(View.GONE);
}
localTransportStopRoutesGrid.setAdapter(adapter);
localTransportStopRoutesGrid.setVisibility(View.VISIBLE);
} else {
localTransportStopRoutesGrid.setVisibility(View.GONE);
localRoutesMoreTv.setVisibility(View.GONE);
}
}
Aggregations