Search in sources :

Example 11 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class TrackDetailsMenu method getPoint.

private WptPt getPoint(LineChart chart, float pos) {
    WptPt wpt = null;
    List<ILineDataSet> ds = chart.getLineData().getDataSets();
    if (ds != null && ds.size() > 0) {
        TrkSegment segment = getTrackSegment(chart);
        OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
        if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
            float time = pos * 1000;
            for (WptPt p : segment.points) {
                if (p.time - gpxItem.analysis.startTime >= time) {
                    wpt = p;
                    break;
                }
            }
        } else {
            float distance = pos * dataSet.getDivX();
            double previousSplitDistance = 0;
            for (int i = 0; i < segment.points.size(); i++) {
                WptPt currentPoint = segment.points.get(i);
                if (i != 0) {
                    WptPt previousPoint = segment.points.get(i - 1);
                    if (currentPoint.distance < previousPoint.distance) {
                        previousSplitDistance += previousPoint.distance;
                    }
                }
                if (previousSplitDistance + currentPoint.distance >= distance) {
                    wpt = currentPoint;
                    break;
                }
            }
        }
    }
    return wpt;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) OrderedLineDataSet(net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment)

Example 12 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class TrackDetailsMenu method refreshChart.

private void refreshChart(LineChart chart, boolean forceFit) {
    Highlight[] highlights = chart.getHighlighted();
    LatLon location = null;
    if (trackChartPoints == null) {
        trackChartPoints = new TrackChartPoints();
        TrkSegment segment = getTrackSegment(chart);
        int segmentColor = segment != null ? segment.getColor(0) : 0;
        trackChartPoints.setSegmentColor(segmentColor);
        trackChartPoints.setGpx(getGpxItem().group.getGpx());
    }
    float minimumVisibleXValue = chart.getLowestVisibleX();
    float maximumVisibleXValue = chart.getHighestVisibleX();
    if (highlights != null && highlights.length > 0) {
        if (minimumVisibleXValue != 0 && maximumVisibleXValue != 0) {
            if (highlights[0].getX() < minimumVisibleXValue) {
                float difference = (maximumVisibleXValue - minimumVisibleXValue) * 0.1f;
                gpxItem.chartHighlightPos = minimumVisibleXValue + difference;
                chart.highlightValue(minimumVisibleXValue + difference, 0);
            } else if (highlights[0].getX() > maximumVisibleXValue) {
                float difference = (maximumVisibleXValue - minimumVisibleXValue) * 0.1f;
                gpxItem.chartHighlightPos = maximumVisibleXValue - difference;
                chart.highlightValue(maximumVisibleXValue - difference, 0);
            } else {
                gpxItem.chartHighlightPos = highlights[0].getX();
            }
        } else {
            gpxItem.chartHighlightPos = highlights[0].getX();
        }
        WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos);
        if (wpt != null) {
            location = new LatLon(wpt.lat, wpt.lon);
            trackChartPoints.setHighlightedPoint(location);
        }
    } else {
        gpxItem.chartHighlightPos = -1;
    }
    trackChartPoints.setXAxisPoints(getXAxisPoints(chart));
    if (gpxItem.route) {
        mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(trackChartPoints);
    } else {
        mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints);
    }
    fitTrackOnMap(chart, location, forceFit);
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.plus.GPXUtilities.WptPt) Highlight(com.github.mikephil.charting.highlight.Highlight) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment)

Example 13 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class SavingTrackHelper method addTrackPoint.

private void addTrackPoint(WptPt pt, boolean newSegment, long time) {
    List<TrkSegment> points = currentTrack.getModifiablePointsToDisplay();
    Track track = currentTrack.getModifiableGpxFile().tracks.get(0);
    assert track.segments.size() == points.size();
    if (points.size() == 0 || newSegment) {
        points.add(new TrkSegment());
    }
    boolean segmentAdded = false;
    if (track.segments.size() == 0 || newSegment) {
        track.segments.add(new TrkSegment());
        segmentAdded = true;
    }
    if (pt != null) {
        int ind = points.size() - 1;
        TrkSegment last = points.get(ind);
        last.points.add(pt);
        TrkSegment lt = track.segments.get(track.segments.size() - 1);
        lt.points.add(pt);
    }
    if (segmentAdded) {
        currentTrack.processPoints();
    }
    currentTrack.getModifiableGpxFile().modifiedTime = time;
}
Also used : TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) Track(net.osmand.plus.GPXUtilities.Track)

Example 14 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class SavingTrackHelper method prepareCurrentTrackForRecording.

private void prepareCurrentTrackForRecording() {
    if (currentTrack.getModifiableGpxFile().tracks.size() == 0) {
        currentTrack.getModifiableGpxFile().tracks.add(new Track());
    }
    while (currentTrack.getPointsToDisplay().size() < currentTrack.getModifiableGpxFile().tracks.size()) {
        TrkSegment trkSegment = new TrkSegment();
        currentTrack.getModifiablePointsToDisplay().add(trkSegment);
    }
}
Also used : TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) Track(net.osmand.plus.GPXUtilities.Track)

Example 15 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class ShowRouteInfoDialogFragment method makeGpx.

private void makeGpx() {
    double lastHeight = HEIGHT_UNDEFINED;
    gpx = new GPXFile();
    List<Location> locations = helper.getRoute().getRouteLocations();
    if (locations != null) {
        Track track = new Track();
        TrkSegment seg = new TrkSegment();
        for (Location l : locations) {
            WptPt point = new WptPt();
            point.lat = l.getLatitude();
            point.lon = l.getLongitude();
            if (l.hasAltitude()) {
                if (!hasHeights) {
                    hasHeights = true;
                }
                float h = (float) l.getAltitude();
                point.ele = h;
                if (lastHeight == HEIGHT_UNDEFINED && seg.points.size() > 0) {
                    for (WptPt pt : seg.points) {
                        if (Double.isNaN(pt.ele)) {
                            pt.ele = h;
                        }
                    }
                }
                lastHeight = h;
            }
            seg.points.add(point);
        }
        track.segments.add(seg);
        gpx.tracks.add(track);
        String groupName = getMyApplication().getString(R.string.current_route);
        GpxDisplayGroup group = getMyApplication().getSelectedGpxHelper().buildGpxDisplayGroup(gpx, 0, groupName);
        if (group != null && group.getModifiableList().size() > 0) {
            gpxItem = group.getModifiableList().get(0);
            if (gpxItem != null) {
                gpxItem.route = true;
            }
        }
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDisplayGroup(net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) Track(net.osmand.plus.GPXUtilities.Track) Location(net.osmand.Location)

Aggregations

TrkSegment (net.osmand.plus.GPXUtilities.TrkSegment)20 WptPt (net.osmand.plus.GPXUtilities.WptPt)12 Track (net.osmand.plus.GPXUtilities.Track)8 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)6 ArrayList (java.util.ArrayList)5 LatLon (net.osmand.data.LatLon)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 Paint (android.graphics.Paint)3 Location (net.osmand.Location)3 LocationPoint (net.osmand.data.LocationPoint)3 Route (net.osmand.plus.GPXUtilities.Route)3 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)3 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 File (java.io.File)2 List (java.util.List)2 GpxDataItem (net.osmand.plus.GPXDatabase.GpxDataItem)2 MapActivity (net.osmand.plus.activities.MapActivity)2 OrderedLineDataSet (net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet)2 Renderable (net.osmand.plus.views.Renderable)2