Revision 41038 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/toolListeners/MeasureListener.java
MeasureListener.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.geom.Point2D; |
27 | 27 |
import java.text.NumberFormat; |
28 |
import java.util.Locale; |
|
28 | 29 |
|
30 |
import org.cresques.cts.IProjection; |
|
31 |
import org.geotools.measure.AngleFormat; |
|
29 | 32 |
import org.gvsig.andami.PluginServices; |
30 | 33 |
import org.gvsig.fmap.mapcontext.MapContext; |
31 | 34 |
import org.gvsig.fmap.mapcontext.ViewPort; |
... | ... | |
67 | 70 |
public void points(MeasureEvent event) { |
68 | 71 |
double dist = 0; |
69 | 72 |
double distAll = 0; |
73 |
double angle = 0; |
|
74 |
double sin = 0; |
|
75 |
double cos = 0; |
|
76 |
double dm = 0; |
|
70 | 77 |
|
71 | 78 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
72 | 79 |
|
80 |
IProjection proj = mapCtrl.getMapContext().getProjection(); |
|
81 |
|
|
73 | 82 |
Point2D p = new Point2D.Double(event.getXs()[0].doubleValue(),event.getYs()[0].doubleValue());//vp.toMapPoint(new Point(event.getXs()[0].intValue(),event.getYs()[0].intValue())); |
74 | 83 |
for (int i = 1; i < (event.getXs().length); i++) { |
75 | 84 |
Point2D p2 = new Point2D.Double(event.getXs()[i].doubleValue(), event.getYs()[i].doubleValue());// vp.toMapPoint(new Point(event.getXs()[i].intValue(),event.getYs()[i].intValue())); |
76 | 85 |
dist = vp.distanceWorld(p, p2); |
77 | 86 |
distAll += dist; |
87 |
|
|
88 |
if (proj.isProjected()) { |
|
89 |
dm = p.distance(p2); |
|
90 |
sin = (p2.getX() - p.getX()) / dm; |
|
91 |
cos = (p2.getY() - p.getY()) / dm; |
|
92 |
if (sin >= 0) { |
|
93 |
angle = Math.toDegrees(Math.acos(cos)); |
|
94 |
} else { |
|
95 |
angle = 360 - Math.toDegrees(Math.acos(cos)); |
|
96 |
} |
|
97 |
} |
|
78 | 98 |
p = p2; |
79 | 99 |
} |
80 | 100 |
|
81 |
//System.out.println("Distancia = " + dist + " Distancia Total = " + |
|
82 |
// (distAll)); |
|
83 | 101 |
NumberFormat nf = NumberFormat.getInstance(); |
102 |
AngleFormat af = AngleFormat.getInstance(Locale.getDefault()); |
|
84 | 103 |
nf.setMaximumFractionDigits(2); |
85 | 104 |
if (PluginServices.getMainFrame() != null) |
86 | 105 |
{ |
... | ... | |
89 | 108 |
"Dist:" + nf.format(dist/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + ""); |
90 | 109 |
PluginServices.getMainFrame().getStatusBar().setMessage("5", |
91 | 110 |
"Total:" + nf.format(distAll/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + ""); |
111 |
|
|
112 |
// |
|
113 |
// El calculo del azimut esta pensado para trabajar en coordenadas proyectadas (metros) |
|
114 |
// y probablemente cuando se esten usando coordenadas en lat/lang se generen resultados |
|
115 |
// erroneos, asi que solo se calcula y muestra el azimut si la proyeccion es proyectada. |
|
116 |
// |
|
117 |
if( proj.isProjected() ) { |
|
118 |
PluginServices.getMainFrame().getStatusBar().setMessage("azimut", |
|
119 |
"Azimut:" + af.format(angle) + ""); |
|
120 |
} else { |
|
121 |
PluginServices.getMainFrame().getStatusBar().setMessage("azimut", |
|
122 |
"Azimut: (not available)"); |
|
123 |
} |
|
92 | 124 |
} |
93 | 125 |
} |
94 | 126 |
} |
Also available in: Unified diff