Ignore:
Timestamp:
2017-05-15T15:43:30+02:00 (7 years ago)
Author:
michael2402
Message:

See #13415: Add the ILatLon interface, unify handling of Nodes and CachedLatLon

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java

    r10334 r12161  
    55
    66import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.data.projection.Projecting;
    78import org.openstreetmap.josm.data.projection.Projection;
    89
     
    2021
    2122    private EastNorth eastNorth;
    22     private transient Projection proj;
     23    private transient Object cacheKey;
    2324
    2425    /**
     
    3738    public CachedLatLon(LatLon coor) {
    3839        super(coor.lat(), coor.lon());
    39         proj = null;
     40        cacheKey = null;
    4041    }
    4142
     
    4546     */
    4647    public CachedLatLon(EastNorth eastNorth) {
    47         super(Main.getProjection().eastNorth2latlon(eastNorth));
    48         proj = Main.getProjection();
     48        this(eastNorth, Main.getProjection());
     49    }
     50
     51    private CachedLatLon(EastNorth eastNorth, Projection projection) {
     52        super(projection.eastNorth2latlon(eastNorth));
     53        cacheKey = projection.getCacheKey();
    4954        this.eastNorth = eastNorth;
    5055    }
     
    5560     * @return the internally cached east/north coordinates. null, if the globally defined projection is null
    5661     */
    57     public final EastNorth getEastNorth() {
    58         if (!Objects.equals(proj, Main.getProjection())) {
    59             proj = Main.getProjection();
    60             eastNorth = proj.latlon2eastNorth(this);
     62    @Override
     63    public final EastNorth getEastNorth(Projecting projecting) {
     64        if (!Objects.equals(cacheKey, projecting.getCacheKey())) {
     65            cacheKey = projecting.getCacheKey();
     66            eastNorth = projecting.latlon2eastNorth(this);
    6167        }
    6268        return eastNorth;
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r12131 r12161  
    4343 * @author Imi
    4444 */
    45 public class LatLon extends Coordinate {
     45public class LatLon extends Coordinate implements ILatLon {
    4646
    4747    private static final long serialVersionUID = 1L;
     
    251251    }
    252252
    253     protected LatLon(LatLon coor) {
     253    /**
     254     * Creates a new LatLon object for the given coordinate
     255     * @param coor The coordinates to copy from.
     256     */
     257    public LatLon(ILatLon coor) {
    254258        super(coor.lon(), coor.lat());
    255259    }
     
    263267    }
    264268
    265     /**
    266      * Returns the latitude, i.e., the north-south position in degrees.
    267      * @return the latitude
    268      */
     269    @Override
    269270    public double lat() {
    270271        return y;
     
    286287    }
    287288
    288     /**
    289      * Returns the longitude, i.e., the east-west position in degrees.
    290      * @return the longitude
    291      */
     289    @Override
    292290    public double lon() {
    293291        return x;
Note: See TracChangeset for help on using the changeset viewer.