Search in sources :

Example 6 with TransportRouteResultSegment

use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment in project Osmand by osmandapp.

the class RouteDetailsFragment method buildTransportRouteRow.

private void buildTransportRouteRow(@NonNull ViewGroup parent, TransportRouteResult routeResult, boolean showDivider) {
    OsmandApplication app = requireMyApplication();
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    TargetPoint startPoint = targetPointsHelper.getPointToStart();
    TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
    int[] startTime = { 0 };
    List<TransportRouteResultSegment> segments = routeResult.getSegments();
    for (int i = 0; i < segments.size(); i++) {
        boolean first = i == 0;
        boolean last = i == segments.size() - 1;
        final TransportRouteResultSegment segment = segments.get(i);
        if (first) {
            buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed());
        }
        buildSegmentItem(parent, segment, !last ? segments.get(i + 1) : null, startTime, routeResult.getWalkSpeed(), routeResult.getBoardingTime());
        if (last) {
            buildDestinationItem(parent, endPoint, startTime, segment, routeResult.getWalkSpeed());
        }
        if (showDivider && !last) {
            buildRowDivider(parent, true);
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) TransportRouteResultSegment(net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) SuppressLint(android.annotation.SuppressLint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)

Example 7 with TransportRouteResultSegment

use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment in project Osmand by osmandapp.

the class PublicTransportGeometryWayDrawer method drawArrowsOverPath.

@Override
public void drawArrowsOverPath(Canvas canvas, RotatedTileBox tb, List<Float> tx, List<Float> ty, List<Double> angles, List<Double> distances, double distPixToFinish, List<GeometryWayStyle<?>> styles) {
    PublicTransportGeometryWayContext context = getContext();
    List<PathPoint> arrows = new ArrayList<>();
    List<PathAnchor> anchors = new ArrayList<>();
    List<PathTransportStop> stops = new ArrayList<>();
    Set<GeometryTransportWayStyle> transportWaysStyles = new HashSet<>();
    GeometryAnchorWayStyle anchorWayStyle = new GeometryAnchorWayStyle(context);
    int h = tb.getPixHeight();
    int w = tb.getPixWidth();
    int left = -w / 4;
    int right = w + w / 4;
    int top = -h / 4;
    int bottom = h + h / 4;
    boolean hasStyles = styles != null && styles.size() == tx.size();
    double zoomCoef = tb.getZoomAnimation() > 0 ? (Math.pow(2, tb.getZoomAnimation() + tb.getZoomFloatPart())) : 1f;
    Bitmap arrow = context.getArrowBitmap();
    int arrowHeight = arrow.getHeight();
    double pxStep = arrowHeight * 4f * zoomCoef;
    double pxStepRegular = arrowHeight * 4f * zoomCoef;
    double dist = 0;
    if (distPixToFinish != 0) {
        // dist < 1
        dist = distPixToFinish - pxStep * ((int) (distPixToFinish / pxStep));
    }
    GeometryWayStyle<?> prevStyle = null;
    for (int i = tx.size() - 2; i >= 0; i--) {
        GeometryWayStyle<?> style = hasStyles ? styles.get(i) : null;
        float px = tx.get(i);
        float py = ty.get(i);
        float x = tx.get(i + 1);
        float y = ty.get(i + 1);
        double distSegment = distances.get(i + 1);
        double angle = angles.get(i + 1);
        if (distSegment == 0) {
            continue;
        }
        pxStep = style != null ? style.getPointStepPx(zoomCoef) : pxStepRegular;
        boolean transportStyle = style instanceof GeometryTransportWayStyle;
        if (style != null && !style.equals(prevStyle) && (prevStyle != null || transportStyle)) {
            prevStyle = style;
            anchors.add(new PathAnchor(x, y, anchorWayStyle));
            dist = 0;
        }
        if (transportStyle) {
            transportWaysStyles.add((GeometryTransportWayStyle) style);
        }
        if (dist >= pxStep) {
            dist = 0;
        }
        double percent = 1 - (pxStep - dist) / distSegment;
        dist += distSegment;
        while (dist >= pxStep) {
            double pdx = (x - px) * percent;
            double pdy = (y - py) * percent;
            float iconx = (float) (px + pdx);
            float icony = (float) (py + pdy);
            if (GeometryWay.isIn(iconx, icony, left, top, right, bottom)) {
                arrows.add(new PathPoint(iconx, icony, angle, style));
            }
            dist -= pxStep;
            percent -= pxStep / distSegment;
        }
    }
    List<TransportStop> routeTransportStops = new ArrayList<>();
    for (GeometryTransportWayStyle style : transportWaysStyles) {
        List<TransportStop> transportStops = style.getRoute().getForwardStops();
        TransportRouteResultSegment segment = style.getSegment();
        int start = segment.start;
        int end = segment.end;
        for (int i = start; i <= end; i++) {
            TransportStop stop = transportStops.get(i);
            double lat = stop.getLocation().getLatitude();
            double lon = stop.getLocation().getLongitude();
            float x = tb.getPixXFromLatLon(lat, lon);
            float y = tb.getPixYFromLatLon(lat, lon);
            if (GeometryWay.isIn(x, y, left, top, right, bottom)) {
                if (i != start && i != end) {
                    stops.add(new PathTransportStop(x, y, style));
                }
                routeTransportStops.add(transportStops.get(i));
            }
        }
    }
    this.routeTransportStops = routeTransportStops;
    for (int i = arrows.size() - 1; i >= 0; i--) {
        PathPoint a = arrows.get(i);
        if (!tb.isZoomAnimated() || a.style.isVisibleWhileZooming()) {
            a.draw(canvas, context);
        }
    }
    for (int i = anchors.size() - 1; i >= 0; i--) {
        PathAnchor anchor = anchors.get(i);
        anchor.draw(canvas, context);
    }
    if (stops.size() > 0) {
        QuadTree<QuadRect> boundIntersections = OsmandMapLayer.initBoundIntersections(tb);
        List<PathTransportStop> fullObjects = new ArrayList<>();
        Bitmap stopBitmap = null;
        float iconSize = 1f;
        for (int i = stops.size() - 1; i >= 0; i--) {
            PathTransportStop stop = stops.get(i);
            if (stopBitmap == null) {
                stopBitmap = stop.getTransportWayStyle().getStopBitmap();
                iconSize = stopBitmap.getWidth() * 3 / 2.5f;
            }
            float x = stop.x;
            float y = stop.y;
            if (OsmandMapLayer.intersects(boundIntersections, x, y, iconSize, iconSize)) {
                stop.setSmallPoint(true);
                stop.draw(canvas, context);
            } else {
                stop.setSmallPoint(false);
                fullObjects.add(stop);
            }
        }
        for (PathTransportStop stop : fullObjects) {
            stop.draw(canvas, context);
        }
    }
}
Also used : TransportRouteResultSegment(net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment) ArrayList(java.util.ArrayList) GeometryTransportWayStyle(net.osmand.plus.views.layers.geometry.PublicTransportGeometryWay.GeometryTransportWayStyle) QuadRect(net.osmand.data.QuadRect) GeometryAnchorWayStyle(net.osmand.plus.views.layers.geometry.PublicTransportGeometryWay.GeometryAnchorWayStyle) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) TransportStop(net.osmand.data.TransportStop) HashSet(java.util.HashSet)

Example 8 with TransportRouteResultSegment

use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment in project OsmAnd-tools by osmandapp.

the class MapTransportLayer method calculateResult.

private void calculateResult(List<Way> res, TransportRouteResult r) {
    if (r != null) {
        LatLon p = start;
        for (TransportRouteResultSegment s : r.getSegments()) {
            LatLon floc = s.getStart().getLocation();
            if (DRAW_WALK_SEGMENTS) {
                addWalk(res, p, floc);
            }
            res.addAll(s.getGeometry());
            // String name = String.format("time %.2f ", s.getSegmentTime());
            // String name = String.format("%d st, %.1f m, %s", s.end - s.start, s.getTravelDist(), s.route.getName());
            // Way way = new Way(-1);
            // way.putTag(OSMTagKey.NAME.getValue(), name);
            // for (int i = s.start; i <= s.end; i++) {
            // LatLon l = s.getStop(i).getLocation();
            // Node n = new Node(l.getLatitude(), l.getLongitude(), -1);
            // way.addNode(n);
            // }
            // res.add(way);
            p = s.getEnd().getLocation();
        }
        if (DRAW_WALK_SEGMENTS) {
            addWalk(res, p, end);
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) TransportRouteResultSegment(net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment)

Example 9 with TransportRouteResultSegment

use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment in project Osmand by osmandapp.

the class PublicTransportGeometryWay method calculateTransportResult.

private void calculateTransportResult(LatLon start, LatLon end, TransportRouteResult r, List<Way> res, List<GeometryWayStyle<?>> styles) {
    if (r != null) {
        LatLon p = start;
        TransportRouteResultSegment prev = null;
        for (TransportRouteResultSegment s : r.getSegments()) {
            LatLon floc = s.getStart().getLocation();
            addRouteWalk(prev, s, p, floc, res, styles);
            List<Way> geometry = s.getGeometry();
            res.addAll(geometry);
            addStyle(s, geometry, styles);
            p = s.getEnd().getLocation();
            prev = s;
        }
        addRouteWalk(prev, null, p, end, res, styles);
    }
}
Also used : LatLon(net.osmand.data.LatLon) TransportRouteResultSegment(net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment) Way(net.osmand.osm.edit.Way)

Example 10 with TransportRouteResultSegment

use of net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment in project Osmand by osmandapp.

the class PublicTransportCard method getFirstLineDescrSpan.

private SpannableString getFirstLineDescrSpan() {
    String preferredMapLang = app.getSettings().MAP_PREFERRED_LOCALE.get();
    boolean transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
    List<TransportRouteResultSegment> segments = routeResult.getSegments();
    String name = segments.get(0).getStart().getName(preferredMapLang, transliterateNames);
    String firstLine = Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_from)) + " " + name;
    if (segments.size() > 1) {
        firstLine += "  •  " + app.getString(R.string.transfers_size, (segments.size() - 1));
    }
    SpannableString firstLineDesc = new SpannableString(firstLine);
    Typeface typeface = FontCache.getRobotoMedium(app);
    firstLineDesc.setSpan(new CustomTypefaceSpan(typeface), firstLine.indexOf(name), firstLine.indexOf(name) + name.length(), 0);
    firstLineDesc.setSpan(new ForegroundColorSpan(getMainFontColor()), firstLine.indexOf(name), firstLine.indexOf(name) + name.length(), 0);
    return firstLineDesc;
}
Also used : SpannableString(android.text.SpannableString) CustomTypefaceSpan(net.osmand.plus.widgets.style.CustomTypefaceSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TransportRouteResultSegment(net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment) Typeface(android.graphics.Typeface) SpannableString(android.text.SpannableString)

Aggregations

TransportRouteResultSegment (net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment)13 LatLon (net.osmand.data.LatLon)4 SpannableString (android.text.SpannableString)2 Pair (android.util.Pair)2 ArrayList (java.util.ArrayList)2 QuadRect (net.osmand.data.QuadRect)2 Node (net.osmand.osm.edit.Node)2 Way (net.osmand.osm.edit.Way)2 TransportRouteResult (net.osmand.router.TransportRouteResult)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 Typeface (android.graphics.Typeface)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 HashSet (java.util.HashSet)1 Location (net.osmand.Location)1