use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment 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.TransportRoutePlanner.TransportRouteResultSegment 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.TransportRoutePlanner.TransportRouteResultSegment in project Osmand by osmandapp.
the class TransportRoutingHelper method getWalkingDistance.
public int getWalkingDistance(@NonNull List<TransportRouteResultSegment> segments) {
int res = 0;
Map<Pair<TransportRouteResultSegment, TransportRouteResultSegment>, RouteCalculationResult> walkingRouteSegments = this.walkingRouteSegments;
if (walkingRouteSegments != null) {
TransportRouteResultSegment prevSegment = null;
for (TransportRouteResultSegment segment : segments) {
RouteCalculationResult walkingRouteSegment = getWalkingRouteSegment(prevSegment, segment);
if (walkingRouteSegment != null) {
res += walkingRouteSegment.getWholeDistance();
}
prevSegment = segment;
}
if (segments.size() > 0) {
RouteCalculationResult walkingRouteSegment = getWalkingRouteSegment(segments.get(segments.size() - 1), null);
if (walkingRouteSegment != null) {
res += walkingRouteSegment.getWholeDistance();
}
}
}
return res;
}
use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment in project Osmand by osmandapp.
the class PublicTransportCard method createRouteBadges.
private void createRouteBadges(List<TransportRouteResultSegment> segments, boolean badgesRowClickable) {
int itemsSpacing = AndroidUtils.dpToPx(app, 6);
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
routesBadges.removeAllViews();
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
Iterator<TransportRouteResultSegment> iterator = segments.iterator();
TransportRouteResultSegment prevSegment = null;
while (iterator.hasNext()) {
TransportRouteResultSegment s = iterator.next();
RouteCalculationResult walkingSegment = transportRoutingHelper.getWalkingRouteSegment(prevSegment, s);
if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) {
routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
} else if (s.walkDist > 0) {
double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed());
if (walkTime > MIN_WALK_TIME) {
LatLon start;
LatLon end = s.getStart().getLocation();
if (prevSegment != null) {
start = prevSegment.getEnd().getLocation();
} else {
start = this.startLocation;
}
routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
}
routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
if (iterator.hasNext()) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} else {
walkingSegment = transportRoutingHelper.getWalkingRouteSegment(s, null);
if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
} else {
double finishWalkDist = routeResult.getFinishWalkDist();
if (finishWalkDist > 0) {
double walkTime = getWalkTime(finishWalkDist, routeResult.getWalkSpeed());
if (walkTime > MIN_WALK_TIME) {
LatLon start = s.getEnd().getLocation();
LatLon end = this.endLocation;
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable));
}
}
}
}
prevSegment = s;
}
}
use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment in project Osmand by osmandapp.
the class PublicTransportCard method updateContent.
@Override
protected void updateContent() {
List<TransportRouteResultSegment> segments = routeResult.getSegments();
boolean badgesRowClickable = !routeInfoVisible && !routeButtonsVisible;
createRouteBadges(segments, badgesRowClickable);
view.findViewById(R.id.route_info).setVisibility(routeInfoVisible ? View.VISIBLE : View.GONE);
view.findViewById(R.id.route_buttons).setVisibility(routeButtonsVisible ? View.VISIBLE : View.GONE);
if (badgesRowClickable) {
view.findViewById(R.id.badges_padding).setVisibility(View.VISIBLE);
view.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), R.attr.card_and_list_background_basic));
View info = view.findViewById(R.id.routes_info_container);
int paddingLeft = info.getPaddingLeft();
int paddingTop = info.getPaddingTop();
int paddingRight = info.getPaddingRight();
int paddingBottom = info.getPaddingBottom();
info.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
info.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
info.setOnClickListener(v -> notifyCardPressed());
} else {
view.findViewById(R.id.badges_padding).setVisibility(View.GONE);
}
TextView fromLine = (TextView) view.findViewById(R.id.from_line);
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
TextView intervalLine = view.findViewById(R.id.interval_line);
fromLine.setText(getFirstLineDescrSpan());
wayLine.setText(getSecondLineDescrSpan(segments));
if (hasInterval(segments)) {
intervalLine.setText(getIntervalDescr(segments));
intervalLine.setVisibility(View.VISIBLE);
}
updateButtons();
view.findViewById(R.id.bottom_shadow).setVisibility(showBottomShadow ? View.VISIBLE : View.GONE);
view.findViewById(R.id.card_divider).setVisibility(showTopShadow ? View.VISIBLE : View.GONE);
view.findViewById(R.id.top_divider).setVisibility(!showTopShadow && showDivider ? View.VISIBLE : View.GONE);
if (transparentBackground) {
view.findViewById(R.id.routes_info_container).setBackgroundDrawable(null);
}
}
Aggregations