1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.coor;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.Main;
|
---|
5 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * LatLon class that maintains a cache of projected EastNorth coordinates.
|
---|
9 | *
|
---|
10 | * This class is convenient to use, but has relatively high memory costs.
|
---|
11 | * It keeps a pointer to the last known projection in order to detect projection
|
---|
12 | * changes.
|
---|
13 | *
|
---|
14 | * Node and WayPoint have another, optimized, cache for projected coordinates.
|
---|
15 | */
|
---|
16 | public class CachedLatLon extends LatLon {
|
---|
17 | private EastNorth eastNorth;
|
---|
18 | private transient Projection proj;
|
---|
19 |
|
---|
20 | public CachedLatLon(double lat, double lon) {
|
---|
21 | super(lat, lon);
|
---|
22 | }
|
---|
23 |
|
---|
24 | public CachedLatLon(LatLon coor) {
|
---|
25 | super(coor.lat(), coor.lon());
|
---|
26 | proj = null;
|
---|
27 | }
|
---|
28 |
|
---|
29 | public CachedLatLon(EastNorth eastNorth) {
|
---|
30 | super(Main.getProjection().eastNorth2latlon(eastNorth));
|
---|
31 | proj = Main.getProjection();
|
---|
32 | this.eastNorth = eastNorth;
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Replies the projected east/north coordinates.
|
---|
37 | *
|
---|
38 | * @return the internally cached east/north coordinates. null, if the globally defined projection is null
|
---|
39 | */
|
---|
40 | public final EastNorth getEastNorth() {
|
---|
41 | if(proj != Main.getProjection())
|
---|
42 | {
|
---|
43 | proj = Main.getProjection();
|
---|
44 | eastNorth = proj.latlon2eastNorth(this);
|
---|
45 | }
|
---|
46 | return eastNorth;
|
---|
47 | }
|
---|
48 | @Override public String toString() {
|
---|
49 | return "CachedLatLon[lat="+lat()+",lon="+lon()+"]";
|
---|
50 | }
|
---|
51 |
|
---|
52 | // Only for Node.get3892DebugInfo()
|
---|
53 | public Projection getProjection() {
|
---|
54 | return proj;
|
---|
55 | }
|
---|
56 | }
|
---|