source: josm/trunk/src/org/openstreetmap/josm/data/osm/NodeData.java@ 11553

Last change on this file since 11553 was 9891, checked in by simon04, 8 years ago

see #12300 - Make Drag and Drop work between different JOSM instances

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.data.coor.EastNorth;
5import org.openstreetmap.josm.data.coor.LatLon;
6import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
7import org.openstreetmap.josm.data.projection.Projections;
8
9public class NodeData extends PrimitiveData implements INode {
10
11 private static final long serialVersionUID = 5626323599550908773L;
12 /*
13 * we "inline" lat/lon coordinates instead of using a LatLon => reduces memory footprint
14 */
15 private double lat = Double.NaN;
16 private double lon = Double.NaN;
17
18 /**
19 * Constructs a new {@code NodeData}.
20 */
21 public NodeData() {
22 // contents can be set later with setters
23 }
24
25 /**
26 * Constructs a new {@code NodeData}.
27 * @param data node data to copy
28 */
29 public NodeData(NodeData data) {
30 super(data);
31 setCoor(data.getCoor());
32 }
33
34 private boolean isLatLonKnown() {
35 return !Double.isNaN(lat) && !Double.isNaN(lon);
36 }
37
38 @Override
39 public LatLon getCoor() {
40 return isLatLonKnown() ? new LatLon(lat, lon) : null;
41 }
42
43 @Override
44 public final void setCoor(LatLon coor) {
45 if (coor == null) {
46 this.lat = Double.NaN;
47 this.lon = Double.NaN;
48 } else {
49 this.lat = coor.lat();
50 this.lon = coor.lon();
51 }
52 }
53
54 @Override
55 public EastNorth getEastNorth() {
56 // No internal caching of projected coordinates needed. In contrast to getEastNorth()
57 // on Node, this method is rarely used. Caching would be overkill.
58 return Projections.project(getCoor());
59 }
60
61 @Override
62 public void setEastNorth(EastNorth eastNorth) {
63 setCoor(Projections.inverseProject(eastNorth));
64 }
65
66 @Override
67 public NodeData makeCopy() {
68 return new NodeData(this);
69 }
70
71 @Override
72 public String toString() {
73 return super.toString() + " NODE " + getCoor();
74 }
75
76 @Override
77 public OsmPrimitiveType getType() {
78 return OsmPrimitiveType.NODE;
79 }
80
81 @Override
82 public void accept(PrimitiveVisitor visitor) {
83 visitor.visit(this);
84 }
85}
Note: See TracBrowser for help on using the repository browser.