Search in sources :

Example 1 with GpxGeometryWay

use of net.osmand.plus.views.layers.geometry.GpxGeometryWay in project Osmand by osmandapp.

the class GPXLayer method drawSelectedFileSegments.

private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    GPXFile gpxFile = selectedGpxFile.getGpxFileToDisplay();
    QuadRect correctedQuadRect = getCorrectedQuadRect(tileBox.getLatLonBounds());
    String coloringTypeName = getAvailableOrDefaultColoringType(selectedGpxFile);
    ColoringType coloringType = ColoringType.getNonNullTrackColoringTypeByName(coloringTypeName);
    String routeIndoAttribute = ColoringType.getRouteInfoAttribute(coloringTypeName);
    boolean visible = QuadRect.trivialOverlap(tileBox.getLatLonBounds(), calculateTrackBounds(selectedGpxFile.getPointsToDisplay()));
    if (!gpxFile.hasTrkPt() && coloringType.isGradient() || !visible) {
        segmentsCache.remove(selectedGpxFile.getGpxFile().path);
        return;
    }
    List<TrkSegment> segments = new ArrayList<>();
    if (coloringType.isTrackSolid() || coloringType.isRouteInfoAttribute()) {
        segments.addAll(selectedGpxFile.getPointsToDisplay());
    } else {
        segments.addAll(getCachedSegments(selectedGpxFile, coloringType.toGradientScaleType()));
    }
    for (int segmentIdx = 0; segmentIdx < segments.size(); segmentIdx++) {
        TrkSegment ts = segments.get(segmentIdx);
        String width = getTrackWidthName(gpxFile, defaultTrackWidthPref.get());
        int color = getTrackColor(gpxFile, ts.getColor(cachedColor));
        if (ts.renderer == null && !ts.points.isEmpty()) {
            Renderable.RenderableSegment renderer;
            if (currentTrack) {
                renderer = new Renderable.CurrentTrack(ts.points);
            } else {
                renderer = new Renderable.StandardTrack(ts.points, 17.2);
            }
            ts.renderer = renderer;
            renderer.setGeometryWay(new GpxGeometryWay(wayContext));
        }
        updatePaints(color, width, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox);
        if (ts.renderer instanceof Renderable.RenderableSegment) {
            Renderable.RenderableSegment renderableSegment = (Renderable.RenderableSegment) ts.renderer;
            renderableSegment.setTrackColoringParams(coloringType, routeIndoAttribute, borderPaint);
            if (coloringType.isRouteInfoAttribute()) {
                renderableSegment.setRoute(getCachedTrack(selectedGpxFile).getCachedRouteSegments(segmentIdx));
                boolean drawArrows = isShowArrowsForTrack(selectedGpxFile.getGpxFile());
                renderableSegment.drawGeometry(canvas, tileBox, correctedQuadRect, paint.getColor(), paint.getStrokeWidth(), drawArrows);
            } else {
                renderableSegment.drawSegment(view.getZoom(), paint, canvas, tileBox);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TrkSegment(net.osmand.GPXUtilities.TrkSegment) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) SelectedGpxPoint(net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint) Renderable(net.osmand.plus.views.Renderable) ColoringType(net.osmand.plus.routing.ColoringType) GpxGeometryWay(net.osmand.plus.views.layers.geometry.GpxGeometryWay) GPXFile(net.osmand.GPXUtilities.GPXFile)

Aggregations

Paint (android.graphics.Paint)1 ArrayList (java.util.ArrayList)1 GPXFile (net.osmand.GPXUtilities.GPXFile)1 TrkSegment (net.osmand.GPXUtilities.TrkSegment)1 QuadRect (net.osmand.data.QuadRect)1 SelectedGpxPoint (net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint)1 ColoringType (net.osmand.plus.routing.ColoringType)1 Renderable (net.osmand.plus.views.Renderable)1 GpxGeometryWay (net.osmand.plus.views.layers.geometry.GpxGeometryWay)1