Changeset 25137 in osm for applications/editors/josm/plugins
- Timestamp:
- 2011-01-25T11:13:50+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java
r21307 r25137 104 104 final MeasurementDialog dlg = this; 105 105 106 DataSet.selListeners.add(new SelectionChangedListener() { 106 DataSet.addSelectionListener(new SelectionChangedListener() { 107 @Override 107 108 public void selectionChanged(Collection<? extends OsmPrimitive> arg0) { 108 109 double length = 0.0; … … 117 118 lastNode = n; 118 119 } else { 119 length += MeasurementLayer.calcDistance(lastNode.getCoor(),n.getCoor());120 length += lastNode.getCoor().greatCircleDistance(n.getCoor()); 120 121 segAngle = MeasurementLayer.angleBetween(lastNode.getCoor(), n.getCoor()); 121 122 lastNode = n; … … 126 127 for(Node n: w.getNodes()) { 127 128 if(lastN != null) { 128 length += MeasurementLayer.calcDistance(lastN.getCoor(),n.getCoor());129 length += lastN.getCoor().greatCircleDistance(n.getCoor()); 129 130 //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ 130 131 area += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor())) … … 148 149 } 149 150 151 @Override 150 152 public void actionPerformed(ActionEvent e) 151 153 { -
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java
r22547 r25137 144 144 } 145 145 146 public static double calcDistance(LatLon p1, LatLon p2){147 double lat1, lon1, lat2, lon2;148 double dlon, dlat;149 150 lat1 = p1.lat() * Math.PI / 180.0;151 lon1 = p1.lon() * Math.PI / 180.0;152 lat2 = p2.lat() * Math.PI / 180.0;153 lon2 = p2.lon() * Math.PI / 180.0;154 155 dlon = lon2 - lon1;156 dlat = lat2 - lat1;157 158 double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));159 double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));160 return 6367000 * c;161 }162 163 146 public static double calcX(LatLon p1){ 164 147 double lat1, lon1, lat2, lon2; … … 196 179 197 180 public static double calcDistance(WayPoint p1, WayPoint p2){ 198 return calcDistance(p1.getCoor(),p2.getCoor());181 return p1.getCoor().greatCircleDistance(p2.getCoor()); 199 182 } 200 183 … … 260 243 } 261 244 245 @Override 262 246 public void actionPerformed(ActionEvent e) { 263 247 Box panel = Box.createVerticalBox();
Note:
See TracChangeset
for help on using the changeset viewer.