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 static org.openstreetmap.josm.tools.I18n.trn;
|
---|
6 |
|
---|
7 | import java.text.DecimalFormat;
|
---|
8 | import java.text.NumberFormat;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
13 | import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
---|
14 |
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * One node data, consisting of one world coordinate waypoint.
|
---|
18 | *
|
---|
19 | * @author imi
|
---|
20 | */
|
---|
21 | public final class Node extends OsmPrimitive {
|
---|
22 |
|
---|
23 | public LatLon coor;
|
---|
24 | public volatile EastNorth eastNorth;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Create an incomplete Node object
|
---|
28 | */
|
---|
29 | public Node(long id) {
|
---|
30 | this.id = id;
|
---|
31 | incomplete = true;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Create an identical clone of the argument (including the id)
|
---|
36 | */
|
---|
37 | public Node(Node clone) {
|
---|
38 | cloneFrom(clone);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public Node(LatLon latlon) {
|
---|
42 | this.coor = latlon;
|
---|
43 | eastNorth = Main.proj.latlon2eastNorth(latlon);
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override public void visit(Visitor visitor) {
|
---|
47 | visitor.visit(this);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override public void cloneFrom(OsmPrimitive osm) {
|
---|
51 | super.cloneFrom(osm);
|
---|
52 | coor = ((Node)osm).coor;
|
---|
53 | eastNorth = ((Node)osm).eastNorth;
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override public String toString() {
|
---|
57 | if (coor == null) return "{Node id="+id+"}";
|
---|
58 | return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
|
---|
62 | if (osm instanceof Node) {
|
---|
63 | if (super.realEqual(osm, semanticOnly)) {
|
---|
64 | if ((coor == null) && ((Node)osm).coor == null)
|
---|
65 | return true;
|
---|
66 | if (coor != null)
|
---|
67 | return coor.equals(((Node)osm).coor);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | return false;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public int compareTo(OsmPrimitive o) {
|
---|
74 | return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public String getName() {
|
---|
78 | String name;
|
---|
79 | if (incomplete) {
|
---|
80 | name = tr("incomplete");
|
---|
81 | } else {
|
---|
82 | NumberFormat latLonFormat = new DecimalFormat("###0.0000000");
|
---|
83 |
|
---|
84 | name = get("name");
|
---|
85 | if (name == null)
|
---|
86 | name = id == 0 ? "" : ""+id;
|
---|
87 | name += " ("+latLonFormat.format(coor.lat())+", "+latLonFormat.format(coor.lon())+")";
|
---|
88 | }
|
---|
89 | return name;
|
---|
90 | }
|
---|
91 | }
|
---|