root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 2977
History | View | Annotate | Download (6.95 KB)
1 | 2958 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.fmap.layers; |
||
42 | |||
43 | import java.awt.Color; |
||
44 | import java.awt.Graphics2D; |
||
45 | import java.awt.geom.Point2D; |
||
46 | import java.awt.geom.Rectangle2D; |
||
47 | import java.awt.image.BufferedImage; |
||
48 | import java.util.ArrayList; |
||
49 | |||
50 | import com.iver.andami.PluginServices; |
||
51 | import com.iver.cit.gvsig.fmap.DriverException; |
||
52 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
53 | import com.iver.cit.gvsig.fmap.operations.Cancellable; |
||
54 | import com.iver.cit.gvsig.gui.View; |
||
55 | 2977 | nacho | import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
56 | 2958 | nacho | |
57 | |||
58 | /**
|
||
59 | * Clase de capa de marcado de puntos sobre una vista. Dibuja un puntero sobre
|
||
60 | * cada punto en la vista.
|
||
61 | *
|
||
62 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
63 | */
|
||
64 | public class FLyrPoints extends FLyrDefault { |
||
65 | |||
66 | 2962 | nacho | public class GeoPoint{ |
67 | public Point2D pixelPoint = null; |
||
68 | public Point2D mapPoint = null; |
||
69 | public GeoPoint(Point2D p, Point2D m){ |
||
70 | this.pixelPoint = p;
|
||
71 | this.mapPoint = m;
|
||
72 | } |
||
73 | } |
||
74 | |||
75 | 2958 | nacho | private ArrayList pointList = new ArrayList(); |
76 | private final int DIAM_CIRCLE = 18; |
||
77 | private String lastTool = null; |
||
78 | 2977 | nacho | |
79 | |||
80 | 2958 | nacho | /**
|
81 | * Dibujado de la capa de raster georeferenciado aplicando la
|
||
82 | * transformaci?n del viewPort.
|
||
83 | */
|
||
84 | public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
||
85 | Cancellable cancel,double scale) throws DriverException { |
||
86 | View theView = (View) PluginServices.getMDIManager().getActiveView(); |
||
87 | 2977 | nacho | //BufferedImage img = theView.getMapControl().getImage();
|
88 | //g.drawImage(img, 0, 0, null);
|
||
89 | int dpto = (DIAM_CIRCLE >> 1); |
||
90 | int incr = 5; |
||
91 | Point2D pto = null; |
||
92 | FLyrGeoRaster lyrGeoRaster = null;
|
||
93 | //Obtenemos la capa de puntos y la capa de georaster
|
||
94 | |||
95 | for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
||
96 | FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
||
97 | if(lyr instanceof FLyrGeoRaster) |
||
98 | lyrGeoRaster = (FLyrGeoRaster)lyr; |
||
99 | } |
||
100 | |||
101 | 2958 | nacho | for(int i=0; i<pointList.size();i++){ |
102 | 2977 | nacho | |
103 | //Punto de la imagen
|
||
104 | pto = ((GeoPoint)pointList.get(i)).pixelPoint; |
||
105 | |||
106 | 2964 | nacho | if(pto != null){ |
107 | 2977 | nacho | g.setColor(Color.red);
|
108 | Point2D p = lyrGeoRaster.img2World(pto.getX(), pto.getY());
|
||
109 | p = vp.fromMapPoint(p); |
||
110 | System.out.println(" DIBUJANDO..."+p); |
||
111 | g.drawOval( (int)p.getX() - dpto,
|
||
112 | (int)p.getY() - dpto,
|
||
113 | DIAM_CIRCLE, |
||
114 | DIAM_CIRCLE); |
||
115 | g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
||
116 | g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
||
117 | } |
||
118 | |||
119 | //Punto de la vista
|
||
120 | pto = ((GeoPoint)pointList.get(i)).mapPoint; |
||
121 | if(pto != null){ |
||
122 | pto = vp.fromMapPoint(pto); |
||
123 | g.setColor(Color.green);
|
||
124 | 2964 | nacho | g.drawOval( (int)pto.getX() - dpto,
|
125 | (int)pto.getY() - dpto,
|
||
126 | DIAM_CIRCLE, |
||
127 | DIAM_CIRCLE); |
||
128 | g.drawLine((int)pto.getX(), (int)pto.getY() - dpto - incr, (int)pto.getX(), (int)pto.getY() + dpto + incr); |
||
129 | g.drawLine((int)pto.getX() - dpto - incr, (int)pto.getY(), (int)pto.getX() + dpto + incr, (int)pto.getY()); |
||
130 | } |
||
131 | 2958 | nacho | } |
132 | } |
||
133 | |||
134 | /* (non-Javadoc)
|
||
135 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double)
|
||
136 | */
|
||
137 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
138 | double scale) throws DriverException { |
||
139 | // TODO Auto-generated method stub
|
||
140 | |||
141 | } |
||
142 | |||
143 | /**
|
||
144 | * A?ade un punto a la lista
|
||
145 | * @param point punto para la lista
|
||
146 | */
|
||
147 | 2962 | nacho | public void addPoint(Point2D pixel, Point2D map){ |
148 | pointList.add(new GeoPoint(pixel, map));
|
||
149 | 2958 | nacho | } |
150 | |||
151 | /**
|
||
152 | 2963 | nacho | * Obtiene el punto de la posici?n pos
|
153 | */
|
||
154 | public GeoPoint getPoint(int pos){ |
||
155 | return (GeoPoint)pointList.get(pos);
|
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * Elimina la lista de puntos almacenada
|
||
160 | */
|
||
161 | public void clear(){ |
||
162 | pointList = new ArrayList(); |
||
163 | } |
||
164 | |||
165 | /**
|
||
166 | * Elimina el punto de la posici?n indicada por el par?metro pos
|
||
167 | * @param pos Posici?n del punto a eliminar
|
||
168 | */
|
||
169 | public void remove(int pos){ |
||
170 | pointList.remove(pos); |
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | *Elimina el ?ltimo punto de la lista.
|
||
175 | */
|
||
176 | public void delLastPoint(){ |
||
177 | pointList.remove(pointList.size() - 1);
|
||
178 | } |
||
179 | 2964 | nacho | |
180 | 2963 | nacho | /**
|
181 | 2964 | nacho | * Obtiene le ?ltimo punto de la lista
|
182 | *
|
||
183 | */
|
||
184 | public GeoPoint getLastPoint(){
|
||
185 | return (GeoPoint)pointList.get(pointList.size());
|
||
186 | } |
||
187 | |||
188 | /**
|
||
189 | 2963 | nacho | * Devuelve el n?mero de puntos de la capa
|
190 | * @return
|
||
191 | */
|
||
192 | public int length(){ |
||
193 | return pointList.size();
|
||
194 | } |
||
195 | |||
196 | /**
|
||
197 | 2962 | nacho | * Actualiza un punto de la lista de una posici?n determinada
|
198 | * @param point punto para la lista
|
||
199 | */
|
||
200 | public void updatePoint(Point2D pixel, Point2D map, int pos){ |
||
201 | GeoPoint gp = (GeoPoint)pointList.get(pos); |
||
202 | if(pixel != null) |
||
203 | gp.pixelPoint = pixel; |
||
204 | if(map != null) |
||
205 | gp.mapPoint = map; |
||
206 | } |
||
207 | |||
208 | /**
|
||
209 | 2958 | nacho | * Devuelve el n?mero de puntos de la lista
|
210 | * @return
|
||
211 | */
|
||
212 | public int getCountPoints(){ |
||
213 | 2964 | nacho | if(pointList != null) |
214 | return pointList.size();
|
||
215 | else
|
||
216 | return 0; |
||
217 | 2958 | nacho | } |
218 | |||
219 | /**
|
||
220 | * Obtiene el extent de la capa
|
||
221 | * @return extent en Rectangle2D.
|
||
222 | */
|
||
223 | public Rectangle2D getFullExtent()throws DriverException { |
||
224 | View theView = (View) PluginServices.getMDIManager().getActiveView(); |
||
225 | return theView.getMapControl().getMapContext().getViewPort().getExtent();
|
||
226 | } |
||
227 | |||
228 | /**
|
||
229 | * @return Returns the lastTool.
|
||
230 | */
|
||
231 | public String getLastTool() { |
||
232 | return lastTool;
|
||
233 | } |
||
234 | |||
235 | /**
|
||
236 | * @param lastTool The lastTool to set.
|
||
237 | */
|
||
238 | public void setLastTool(String lastTool) { |
||
239 | this.lastTool = lastTool;
|
||
240 | } |
||
241 | 2963 | nacho | |
242 | /**
|
||
243 | * Muestra en consola los puntos de la capa
|
||
244 | */
|
||
245 | public void showPoints(){ |
||
246 | for(int i=0;i<pointList.size();i++){ |
||
247 | if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){ |
||
248 | System.out.println("PUNTO "+i+": "); |
||
249 | System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY()); |
||
250 | System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY()); |
||
251 | }else
|
||
252 | System.out.println("PUNTO "+i+": NULL"); |
||
253 | } |
||
254 | } |
||
255 | 2958 | nacho | } |