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 | import java.text.DecimalFormat;
|
---|
6 | import java.text.NumberFormat;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
10 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
|
---|
12 | import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
---|
13 |
|
---|
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 | public LatLon coor;
|
---|
23 | public volatile EastNorth eastNorth;
|
---|
24 |
|
---|
25 | private static CoordinateFormat mCord;
|
---|
26 |
|
---|
27 | static {
|
---|
28 | try {
|
---|
29 | mCord = LatLon.CoordinateFormat.valueOf(Main.pref.get("coordinates"));
|
---|
30 | } catch (IllegalArgumentException iae) {
|
---|
31 | mCord =LatLon.CoordinateFormat.DECIMAL_DEGREES;
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Create an incomplete Node object
|
---|
37 | */
|
---|
38 | public Node(long id) {
|
---|
39 | this.id = id;
|
---|
40 | incomplete = true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Create an identical clone of the argument (including the id)
|
---|
45 | */
|
---|
46 | public Node(Node clone) {
|
---|
47 | cloneFrom(clone);
|
---|
48 | }
|
---|
49 |
|
---|
50 | public Node(LatLon latlon) {
|
---|
51 | this.coor = latlon;
|
---|
52 | eastNorth = Main.proj.latlon2eastNorth(latlon);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override public void visit(Visitor visitor) {
|
---|
56 | visitor.visit(this);
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override public void cloneFrom(OsmPrimitive osm) {
|
---|
60 | super.cloneFrom(osm);
|
---|
61 | coor = ((Node)osm).coor;
|
---|
62 | eastNorth = ((Node)osm).eastNorth;
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override public String toString() {
|
---|
66 | if (coor == null) return "{Node id="+id+"}";
|
---|
67 | return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
|
---|
71 | if (osm instanceof Node) {
|
---|
72 | if (super.realEqual(osm, semanticOnly)) {
|
---|
73 | if ((coor == null) && ((Node)osm).coor == null)
|
---|
74 | return true;
|
---|
75 | if (coor != null)
|
---|
76 | return coor.equals(((Node)osm).coor);
|
---|
77 | }
|
---|
78 | }
|
---|
79 | return false;
|
---|
80 | }
|
---|
81 |
|
---|
82 | public int compareTo(OsmPrimitive o) {
|
---|
83 | return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public String getName() {
|
---|
87 | String name;
|
---|
88 | if (incomplete) {
|
---|
89 | name = tr("incomplete");
|
---|
90 | } else {
|
---|
91 | name = get("name");
|
---|
92 | if (name == null)
|
---|
93 | name = id == 0 ? tr("node") : ""+id;
|
---|
94 | name += " (" + coor.latToString(mCord) + ", " + coor.lonToString(mCord) + ")";
|
---|
95 | }
|
---|
96 | return name;
|
---|
97 | }
|
---|
98 | }
|
---|