Ignore:
Timestamp:
2014-07-20T20:43:53+02:00 (5 years ago)
Author:
akks
Message:

Add colorbar for active GPX layer, big GpxLayer class refactoring, see #5662
new classes GpxDrawHelper and ColorScale responsible for GPX drawing and coloring
move data-related methods to GpxData
remove WayPoint.customColoringTransparent from memory, calculate it at paint-time

Location:
trunk/src/org/openstreetmap/josm/data/gpx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r7020 r7319  
    44import java.io.File;
    55import java.util.Collection;
     6import java.util.Date;
    67import java.util.Iterator;
    78import java.util.LinkedList;
     
    8283     *
    8384     * FIXME might perhaps use visitor pattern?
     85     * @return the bounds
    8486     */
    8587    public Bounds recalculateBounds() {
     
    116118    /**
    117119     * calculates the sum of the lengths of all track segments
     120     * @return the length in meters
    118121     */
    119122    public double length(){
     
    125128
    126129        return result;
     130    }
     131   
     132    /**
     133     * returns minimum and maximum timestamps in the track
     134     * @param trk track to analyze
     135     * @return  minimum and maximum dates in array of 2 elements
     136     */
     137    public static Date[] getMinMaxTimeForTrack(GpxTrack trk) {
     138        WayPoint earliest = null, latest = null;
     139
     140        for (GpxTrackSegment seg : trk.getSegments()) {
     141            for (WayPoint pnt : seg.getWayPoints()) {
     142                if (latest == null) {
     143                    latest = earliest = pnt;
     144                } else {
     145                    if (pnt.compareTo(earliest) < 0) {
     146                        earliest = pnt;
     147                    } else {
     148                        latest = pnt;
     149                    }
     150                }
     151            }
     152        }
     153        if (earliest==null || latest==null) return null;
     154        return new Date[]{earliest.getTime(), latest.getTime()};
     155    }
     156
     157    /**
     158    * Returns minimum and maximum timestamps for all tracks
     159    * Warning: there are lot of track with broken timestamps,
     160    * so we just ingore points from future and from year before 1970 in this method
     161    * works correctly @since 5815
     162     * @return minimum and maximum dates in array of 2 elements
     163    */
     164    public Date[] getMinMaxTimeForAllTracks() {
     165        double min=1e100, max=-1e100, t;
     166        double now = System.currentTimeMillis()/1000.0;
     167        for (GpxTrack trk: tracks) {
     168            for (GpxTrackSegment seg : trk.getSegments()) {
     169                for (WayPoint pnt : seg.getWayPoints()) {
     170                    t = pnt.time;
     171                    if (t>0 && t<=now) {
     172                        if (t>max) max=t;
     173                        if (t<min) min=t;
     174                    }
     175                }
     176            }
     177        }
     178        if (min==1e100 || max==-1e100) return null;
     179        return new Date[]{new Date((long) (min * 1000)), new Date((long) (max * 1000)), };
    127180    }
    128181
     
    258311    }
    259312
     313    public void resetEastNorthCache() {
     314        if (waypoints != null) {
     315            for (WayPoint wp : waypoints){
     316                wp.invalidateEastNorthCache();
     317            }
     318        }
     319        if (tracks != null){
     320            for (GpxTrack track: tracks) {
     321                for (GpxTrackSegment segment: track.getSegments()) {
     322                    for (WayPoint wp: segment.getWayPoints()) {
     323                        wp.invalidateEastNorthCache();
     324                    }
     325                }
     326            }
     327        }
     328        if (routes != null) {
     329            for (GpxRoute route: routes) {
     330                if (route.routePoints == null) {
     331                    continue;
     332                }
     333                for (WayPoint wp: route.routePoints) {
     334                    wp.invalidateEastNorthCache();
     335                }
     336            }
     337        }
     338    }
     339
    260340    /**
    261341     * Iterates over all track segments and then over all routes.
     
    266346        private int idxTracks;
    267347        private Iterator<GpxTrackSegment> itTrackSegments;
    268         private Iterator<GpxRoute> itRoutes;
     348        private final Iterator<GpxRoute> itRoutes;
    269349
    270350        private Collection<WayPoint> next;
    271         private boolean[] trackVisibility;
     351        private final boolean[] trackVisibility;
    272352
    273353        public LinesIterator(GpxData data, boolean[] trackVisibility) {
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r7299 r7319  
    2525    public double time;
    2626    public Color customColoring;
    27     public Color customColoringTransparent;
    2827    public boolean drawLine;
    2928    public int dir;
     
    3736        time = p.time;
    3837        customColoring = p.customColoring;
    39         customColoringTransparent = p.customColoringTransparent;
    4038        drawLine = p.drawLine;
    4139        dir = p.dir;
Note: See TracChangeset for help on using the changeset viewer.