Changeset 21307 in osm for applications/editors/josm/plugins/measurement/src/org/openstreetmap
- Timestamp:
- 2010-05-16T14:19:11+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java
r18962 r21307 103 103 this.setPreferredSize(new Dimension(0, 92)); 104 104 final MeasurementDialog dlg = this; 105 //TODO: is this enough?106 105 107 DataSet.selListeners.add(new SelectionChangedListener(){ 108 106 DataSet.selListeners.add(new SelectionChangedListener() { 109 107 public void selectionChanged(Collection<? extends OsmPrimitive> arg0) { 110 108 double length = 0.0; 111 109 double segAngle = 0.0; 112 113 114 for(OsmPrimitive p:arg0) {115 116 if(p instanceof Node && !((Node)p).isIncomplete()){117 118 if(lastNode == null){119 120 }else{121 122 123 124 125 } else if(p instanceof Way){126 127 128 for(Node n: w.getNodes()){129 if(lastN != null){130 131 132 133 - (MeasurementLayer.calcY(n.getCoor()) * MeasurementLayer.calcX(lastN.getCoor()));134 }135 lastN = n;136 }137 if (lastN != null && lastN == w.getNodes().iterator().next()){138 area = Math.abs(area / 2);139 }else{140 area = 0;141 }142 110 double area = 0.0; 111 Node lastNode = null; 112 for(OsmPrimitive p:arg0) { 113 // ignore incomplete nodes 114 if(p instanceof Node && !((Node)p).isIncomplete()) { 115 Node n =(Node)p; 116 if(lastNode == null) { 117 lastNode = n; 118 } else { 119 length += MeasurementLayer.calcDistance(lastNode.getCoor(), n.getCoor()); 120 segAngle = MeasurementLayer.angleBetween(lastNode.getCoor(), n.getCoor()); 121 lastNode = n; 122 } 123 } else if(p instanceof Way) { 124 Way w = (Way)p; 125 Node lastN = null; 126 for(Node n: w.getNodes()) { 127 if(lastN != null) { 128 length += MeasurementLayer.calcDistance(lastN.getCoor(), n.getCoor()); 129 //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ 130 area += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor())) 131 - (MeasurementLayer.calcY(n.getCoor()) * MeasurementLayer.calcX(lastN.getCoor())); 132 segAngle = MeasurementLayer.angleBetween(lastN.getCoor(), n.getCoor()); 133 } 134 lastN = n; 135 } 136 if (lastN != null && lastN == w.getNodes().iterator().next()) 137 area = Math.abs(area / 2); 138 else 139 area = 0; 140 } 143 141 } 144 142 dlg.selectLengthLabel.setText(new DecimalFormat("#0.00").format(length) + " m"); … … 164 162 MeasurementPlugin.getCurrentLayer().reset(); 165 163 } 166 167 164 }
Note:
See TracChangeset
for help on using the changeset viewer.