Revision 2977 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/toolListeners/GeorefPointerListener.java
GeorefPointerListener.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
import java.awt.geom.Point2D; |
44 | 44 |
|
45 |
import javax.swing.JComboBox; |
|
46 |
|
|
47 | 45 |
import com.iver.andami.PluginServices; |
46 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
48 | 47 |
import com.iver.cit.gvsig.fmap.ViewPort; |
49 | 48 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
49 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
|
50 | 50 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
51 | 51 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
52 | 52 |
import com.iver.cit.gvsig.fmap.tools.GeorefPointerListenerImpl; |
53 | 53 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
54 | 54 |
import com.iver.cit.gvsig.gui.View; |
55 | 55 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
56 |
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
|
56 | 57 |
|
57 | 58 |
|
58 | 59 |
/** |
... | ... | |
65 | 66 |
public class GeorefPointerListener extends GeorefPointerListenerImpl { |
66 | 67 |
|
67 | 68 |
private GeoreferencingDialog dialog = null; |
69 |
private boolean firstPoint = true; |
|
70 |
private View theView = null; |
|
71 |
private FLyrPoints lyrPoints = null; |
|
72 |
private FLyrGeoRaster lyrGeoRaster = null; |
|
68 | 73 |
|
74 |
|
|
69 | 75 |
/** |
70 | 76 |
* Posici?n del punto a ser seleccionado. |
71 | 77 |
*/ |
... | ... | |
91 | 97 |
public void point(PointEvent event) throws BehaviorException { |
92 | 98 |
super.point(event); |
93 | 99 |
|
94 |
//Obtenemos la capa de puntos
|
|
95 |
View theView = (View) PluginServices.getMDIManager().getActiveView();
|
|
96 |
FLyrPoints lyrPoints = null; |
|
100 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
|
101 |
//Obtenemos la capa de puntos y la capa de georaster
|
|
102 |
|
|
97 | 103 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
98 | 104 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
99 | 105 |
if(lyr instanceof FLyrPoints) |
100 | 106 |
lyrPoints = (FLyrPoints)lyr; |
107 |
if(lyr instanceof FLyrGeoRaster) |
|
108 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
|
101 | 109 |
} |
102 | 110 |
|
103 |
//Le a?adimos un punto |
|
104 |
if(lyrPoints != null){ |
|
105 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
|
106 |
Point2D wcPoint = viewPort.toMapPoint(event.getPoint()); |
|
107 |
|
|
108 |
//lyrPoints.addPoint(event.getPoint(), wcPoint) |
|
109 |
System.out.println("Insertando pos="+GeorefPointerListener.posPoint); |
|
110 |
System.out.println("...........pixel:="+wcPoint); |
|
111 |
System.out.println("...........map="+event.getPoint()); |
|
112 |
|
|
111 |
ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
|
112 |
Point2D wcPoint = viewPort.toMapPoint(event.getPoint()); |
|
113 |
|
|
114 |
if(firstPoint){ |
|
115 |
if(lyrPoints != null){ |
|
116 |
|
|
117 |
//Hallamos pixelImg q son las coordenadas en pixeles de la imagen que corresponden |
|
118 |
//con el punto seleccionado |
|
119 |
double wcWidth = 0.0, wcHeight = 0.0, ptoWCX = 0.0, ptoWCY = 0.0; |
|
120 |
int pixelImgX = 0, pixelImgY = 0; |
|
121 |
try{ |
|
122 |
wcWidth = lyrGeoRaster.getFullExtent().getWidth(); |
|
123 |
wcHeight = lyrGeoRaster.getFullExtent().getHeight(); |
|
124 |
ptoWCX = wcPoint.getX() - lyrGeoRaster.getFullExtent().getMinX(); |
|
125 |
ptoWCY = wcPoint.getY() - lyrGeoRaster.getFullExtent().getMinY(); |
|
126 |
pixelImgX = (int)((ptoWCX * SelectFilePanel.widthPxImg) / wcWidth); |
|
127 |
pixelImgY = (int)((ptoWCY * SelectFilePanel.heightPxImg) / wcHeight); |
|
128 |
}catch(DriverException ex){} |
|
129 |
|
|
130 |
|
|
131 |
//Salvamos el primer punto pinchado en la capa. (Pixeles de la imagen) |
|
132 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint = new Point2D.Double(); |
|
133 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint.setLocation(event.getPoint()); |
|
134 |
//Cargamos en la ventana el nuevo punto |
|
135 |
dialog.getSelectPointsPanel().getTX().setText(String.valueOf(pixelImgX)); |
|
136 |
dialog.getSelectPointsPanel().getTY().setText(String.valueOf(pixelImgY)); |
|
137 |
firstPoint = false; |
|
138 |
} |
|
139 |
}else{ |
|
140 |
//Salvamos el segundo punto pinchado en la capa (Coordenadas de georreferenciaci?n) |
|
113 | 141 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).mapPoint = new Point2D.Double(); |
114 | 142 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).mapPoint.setLocation(wcPoint); |
115 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint = new Point2D.Double(); |
|
116 |
lyrPoints.getPoint(GeorefPointerListener.posPoint).pixelPoint.setLocation(event.getPoint()); |
|
117 |
|
|
118 |
lyrPoints.showPoints(); |
|
119 |
|
|
120 |
theView.getMapControl().getMapContext().invalidate(); |
|
121 |
|
|
122 |
//Deseleccionamos la herramienta de marcado de puntos |
|
123 |
theView.getMapControl().setTool(lyrPoints.getLastTool()); |
|
124 |
|
|
125 | 143 |
//Cargamos en la ventana el nuevo punto |
126 |
dialog.getSelectPointsPanel().getTX().setText(String.valueOf(event.getPoint().getX())); |
|
127 |
dialog.getSelectPointsPanel().getTY().setText(String.valueOf(event.getPoint().getY())); |
|
128 | 144 |
dialog.getSelectPointsPanel().getLongitud().setText(String.valueOf(wcPoint.getX())); |
129 | 145 |
dialog.getSelectPointsPanel().getLatitud().setText(String.valueOf(wcPoint.getY())); |
146 |
|
|
147 |
//Deseleccionamos la herramienta de marcado de puntos |
|
148 |
theView.getMapControl().setTool(lyrPoints.getLastTool()); |
|
149 |
firstPoint = true; |
|
130 | 150 |
} |
131 |
|
|
151 |
theView.getMapControl().getMapContext().invalidate(); |
|
152 |
lyrPoints.showPoints(); |
|
132 | 153 |
} |
133 | 154 |
} |
Also available in: Unified diff