root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 2963
History | View | Annotate | Download (5.76 KB)
1 |
/* 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 |
|
56 |
|
57 |
/**
|
58 |
* Clase de capa de marcado de puntos sobre una vista. Dibuja un puntero sobre
|
59 |
* cada punto en la vista.
|
60 |
*
|
61 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
62 |
*/
|
63 |
public class FLyrPoints extends FLyrDefault { |
64 |
|
65 |
public class GeoPoint{ |
66 |
public Point2D pixelPoint = null; |
67 |
public Point2D mapPoint = null; |
68 |
public GeoPoint(Point2D p, Point2D m){ |
69 |
this.pixelPoint = p;
|
70 |
this.mapPoint = m;
|
71 |
} |
72 |
} |
73 |
|
74 |
private ArrayList pointList = new ArrayList(); |
75 |
private final int DIAM_CIRCLE = 18; |
76 |
private String lastTool = null; |
77 |
|
78 |
/**
|
79 |
* Dibujado de la capa de raster georeferenciado aplicando la
|
80 |
* transformaci?n del viewPort.
|
81 |
*/
|
82 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
83 |
Cancellable cancel,double scale) throws DriverException { |
84 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
85 |
BufferedImage img = theView.getMapControl().getImage();
|
86 |
g.drawImage(img, 0, 0, null); |
87 |
g.setColor(Color.red);
|
88 |
|
89 |
for(int i=0; i<pointList.size();i++){ |
90 |
//Point2D pto = vp.fromMapPoint((Point2D)pointList.get(i));
|
91 |
Point2D pto = ((GeoPoint)pointList.get(i)).pixelPoint;
|
92 |
int dpto = (DIAM_CIRCLE >> 1); |
93 |
g.drawOval( (int)pto.getX() - dpto,
|
94 |
(int)pto.getY() - dpto,
|
95 |
DIAM_CIRCLE, |
96 |
DIAM_CIRCLE); |
97 |
int incr = 5; |
98 |
g.drawLine((int)pto.getX(), (int)pto.getY() - dpto - incr, (int)pto.getX(), (int)pto.getY() + dpto + incr); |
99 |
g.drawLine((int)pto.getX() - dpto - incr, (int)pto.getY(), (int)pto.getX() + dpto + incr, (int)pto.getY()); |
100 |
|
101 |
} |
102 |
} |
103 |
|
104 |
/* (non-Javadoc)
|
105 |
* @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)
|
106 |
*/
|
107 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
108 |
double scale) throws DriverException { |
109 |
// TODO Auto-generated method stub
|
110 |
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* A?ade un punto a la lista
|
115 |
* @param point punto para la lista
|
116 |
*/
|
117 |
public void addPoint(Point2D pixel, Point2D map){ |
118 |
pointList.add(new GeoPoint(pixel, map));
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* Obtiene el punto de la posici?n pos
|
123 |
*/
|
124 |
public GeoPoint getPoint(int pos){ |
125 |
return (GeoPoint)pointList.get(pos);
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Elimina la lista de puntos almacenada
|
130 |
*/
|
131 |
public void clear(){ |
132 |
pointList = new ArrayList(); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Elimina el punto de la posici?n indicada por el par?metro pos
|
137 |
* @param pos Posici?n del punto a eliminar
|
138 |
*/
|
139 |
public void remove(int pos){ |
140 |
pointList.remove(pos); |
141 |
} |
142 |
|
143 |
/**
|
144 |
*Elimina el ?ltimo punto de la lista.
|
145 |
*/
|
146 |
public void delLastPoint(){ |
147 |
pointList.remove(pointList.size() - 1);
|
148 |
} |
149 |
/**
|
150 |
* Devuelve el n?mero de puntos de la capa
|
151 |
* @return
|
152 |
*/
|
153 |
public int length(){ |
154 |
return pointList.size();
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* Actualiza un punto de la lista de una posici?n determinada
|
159 |
* @param point punto para la lista
|
160 |
*/
|
161 |
public void updatePoint(Point2D pixel, Point2D map, int pos){ |
162 |
GeoPoint gp = (GeoPoint)pointList.get(pos); |
163 |
if(pixel != null) |
164 |
gp.pixelPoint = pixel; |
165 |
if(map != null) |
166 |
gp.mapPoint = map; |
167 |
} |
168 |
|
169 |
/**
|
170 |
* Devuelve el n?mero de puntos de la lista
|
171 |
* @return
|
172 |
*/
|
173 |
public int getCountPoints(){ |
174 |
return pointList.size();
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* Obtiene el extent de la capa
|
179 |
* @return extent en Rectangle2D.
|
180 |
*/
|
181 |
public Rectangle2D getFullExtent()throws DriverException { |
182 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
183 |
return theView.getMapControl().getMapContext().getViewPort().getExtent();
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* @return Returns the lastTool.
|
188 |
*/
|
189 |
public String getLastTool() { |
190 |
return lastTool;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* @param lastTool The lastTool to set.
|
195 |
*/
|
196 |
public void setLastTool(String lastTool) { |
197 |
this.lastTool = lastTool;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* Muestra en consola los puntos de la capa
|
202 |
*/
|
203 |
public void showPoints(){ |
204 |
for(int i=0;i<pointList.size();i++){ |
205 |
if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){ |
206 |
System.out.println("PUNTO "+i+": "); |
207 |
System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY()); |
208 |
System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY()); |
209 |
}else
|
210 |
System.out.println("PUNTO "+i+": NULL"); |
211 |
} |
212 |
} |
213 |
} |