1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
8 | import org.openstreetmap.josm.data.coor.CachedLatLon;
|
---|
9 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
|
---|
11 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
12 | import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * One node data, consisting of one world coordinate waypoint.
|
---|
17 | *
|
---|
18 | * @author imi
|
---|
19 | */
|
---|
20 | public final class Node extends OsmPrimitive {
|
---|
21 |
|
---|
22 | private CachedLatLon coor;
|
---|
23 |
|
---|
24 | public final void setCoor(LatLon coor) {
|
---|
25 | if(coor != null)
|
---|
26 | {
|
---|
27 | if(this.coor == null)
|
---|
28 | this.coor = new CachedLatLon(coor);
|
---|
29 | else
|
---|
30 | this.coor.setCoor(coor);
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public final LatLon getCoor() {
|
---|
35 | return coor;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public final void setEastNorth(EastNorth eastNorth) {
|
---|
39 | if(eastNorth != null)
|
---|
40 | {
|
---|
41 | if(coor != null)
|
---|
42 | coor.setEastNorth(eastNorth);
|
---|
43 | else
|
---|
44 | coor = new CachedLatLon(eastNorth);
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public final EastNorth getEastNorth() {
|
---|
49 | return coor != null ? coor.getEastNorth() : null;
|
---|
50 | }
|
---|
51 |
|
---|
52 | private static CoordinateFormat mCord;
|
---|
53 |
|
---|
54 | static public CoordinateFormat getCoordinateFormat()
|
---|
55 | {
|
---|
56 | return mCord;
|
---|
57 | }
|
---|
58 |
|
---|
59 | static public void setCoordinateFormat()
|
---|
60 | {
|
---|
61 | try {
|
---|
62 | mCord = LatLon.CoordinateFormat.valueOf(Main.pref.get("coordinates"));
|
---|
63 | } catch (IllegalArgumentException iae) {
|
---|
64 | mCord = LatLon.CoordinateFormat.DECIMAL_DEGREES;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | static {
|
---|
69 | setCoordinateFormat();
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Create an incomplete Node object
|
---|
74 | */
|
---|
75 | public Node(long id) {
|
---|
76 | this.id = id;
|
---|
77 | incomplete = true;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Create an identical clone of the argument (including the id)
|
---|
82 | */
|
---|
83 | public Node(Node clone) {
|
---|
84 | cloneFrom(clone);
|
---|
85 | }
|
---|
86 |
|
---|
87 | public Node(LatLon latlon) {
|
---|
88 | setCoor(latlon);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public Node(EastNorth eastNorth) {
|
---|
92 | setEastNorth(eastNorth);
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Override public void visit(Visitor visitor) {
|
---|
96 | visitor.visit(this);
|
---|
97 | }
|
---|
98 |
|
---|
99 | @Override public void cloneFrom(OsmPrimitive osm) {
|
---|
100 | super.cloneFrom(osm);
|
---|
101 | setCoor(((Node)osm).coor);
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Override public String toString() {
|
---|
105 | if (coor == null) return "{Node id="+id+"}";
|
---|
106 | return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * @deprecated
|
---|
111 | * @see #hasEqualSemanticAttributes(OsmPrimitive)
|
---|
112 | * @see #hasEqualTechnicalAttributes(OsmPrimitive)
|
---|
113 | */
|
---|
114 | @Deprecated
|
---|
115 | @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
|
---|
116 | if (osm instanceof Node) {
|
---|
117 | if (super.realEqual(osm, semanticOnly)) {
|
---|
118 | if ((coor == null) && ((Node)osm).coor == null)
|
---|
119 | return true;
|
---|
120 | if (coor != null)
|
---|
121 | return coor.equals(((Node)osm).coor);
|
---|
122 | }
|
---|
123 | }
|
---|
124 | return false;
|
---|
125 | }
|
---|
126 |
|
---|
127 | @Override
|
---|
128 | public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
|
---|
129 | if (other == null || ! (other instanceof Node) )
|
---|
130 | return false;
|
---|
131 | if (! super.hasEqualSemanticAttributes(other))
|
---|
132 | return false;
|
---|
133 | Node n = (Node)other;
|
---|
134 | if (coor == null && n.coor == null)
|
---|
135 | return true;
|
---|
136 | else if (coor != null && n.coor != null)
|
---|
137 | return coor.equals(n.coor);
|
---|
138 | else
|
---|
139 | return false;
|
---|
140 | }
|
---|
141 |
|
---|
142 | public int compareTo(OsmPrimitive o) {
|
---|
143 | return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
|
---|
144 | }
|
---|
145 |
|
---|
146 | @Override
|
---|
147 | public String getName() {
|
---|
148 | String name;
|
---|
149 | if (incomplete) {
|
---|
150 | name = tr("incomplete");
|
---|
151 | } else {
|
---|
152 | name = get("name");
|
---|
153 | if (name == null) {
|
---|
154 | name = id == 0 ? tr("node") : ""+id;
|
---|
155 | }
|
---|
156 | name += " (" + coor.latToString(mCord) + ", " + coor.lonToString(mCord) + ")";
|
---|
157 | }
|
---|
158 | return name;
|
---|
159 | }
|
---|
160 |
|
---|
161 | }
|
---|