Ignore:
Timestamp:
2017-05-15T17:13:11+02:00 (3 years ago)
Author:
michael2402
Message:

Make WayPoint implement ILatLon.

File:
1 edited

Legend:

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

    r11893 r12167  
    66import java.util.Date;
    77import java.util.List;
     8import java.util.Objects;
    89
    910import org.openstreetmap.josm.Main;
    1011import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    1112import org.openstreetmap.josm.data.coor.EastNorth;
     13import org.openstreetmap.josm.data.coor.ILatLon;
    1214import org.openstreetmap.josm.data.coor.LatLon;
    13 import org.openstreetmap.josm.data.projection.Projections;
     15import org.openstreetmap.josm.data.projection.Projecting;
    1416import org.openstreetmap.josm.tools.UncheckedParseException;
    1517import org.openstreetmap.josm.tools.date.DateUtils;
    1618import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    1719
    18 public class WayPoint extends WithAttributes implements Comparable<WayPoint>, TemplateEngineDataProvider {
     20/**
     21 * A point in the GPX data
     22 * @since 12167 implements ILatLon
     23 */
     24public class WayPoint extends WithAttributes implements Comparable<WayPoint>, TemplateEngineDataProvider, ILatLon {
    1925
    2026    /**
     
    3642        east = p.east;
    3743        north = p.north;
     44        eastNorthCacheKey = p.eastNorthCacheKey;
    3845        time = p.time;
    3946        customColoring = p.customColoring;
     
    6370    private double east = Double.NaN;
    6471    private double north = Double.NaN;
     72    private Object eastNorthCacheKey = null;
    6573
    6674    /**
     
    8088    }
    8189
    82     /**
    83      * <p>Replies the projected east/north coordinates.</p>
    84      *
    85      * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates.
    86      * Internally caches the projected coordinates.</p>
    87      *
    88      * <p><strong>Caveat:</strong> doesn't listen to projection changes. Clients must
    89      * {@link #invalidateEastNorthCache() invalidate the internal cache}.</p>
    90      *
    91      * @return the east north coordinates or {@code null}
    92      * @see #invalidateEastNorthCache()
    93      */
    94     public final EastNorth getEastNorth() {
    95         if (Double.isNaN(east) || Double.isNaN(north)) {
     90    @Override
     91    public double lon() {
     92        return lat;
     93    }
     94
     95    @Override
     96    public double lat() {
     97        return lon;
     98    }
     99
     100    @Override
     101    public final EastNorth getEastNorth(Projecting projecting) {
     102        Object newCacheKey = projecting.getCacheKey();
     103        if (Double.isNaN(east) || Double.isNaN(north) || !Objects.equals(newCacheKey, this.eastNorthCacheKey)) {
    96104            // projected coordinates haven't been calculated yet,
    97105            // so fill the cache of the projected waypoint coordinates
    98             EastNorth en = Projections.project(new LatLon(lat, lon));
     106            EastNorth en = projecting.latlon2eastNorth(this);
    99107            this.east = en.east();
    100108            this.north = en.north();
     109            this.eastNorthCacheKey = newCacheKey;
    101110        }
    102111        return new EastNorth(east, north);
Note: See TracChangeset for help on using the changeset viewer.