Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 2993

History | View | Annotate | Download (7.17 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
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel;
56

    
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
        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
        private ArrayList pointList = new ArrayList();
76
        private final int DIAM_CIRCLE = 18;
77
        private String lastTool = null;
78
        
79
        /**
80
         * Obtiene el array de puntos
81
         * @return
82
         */
83
        public ArrayList getListPoint(){
84
                return pointList;
85
        }
86
        
87
        /**
88
         * Asigna el array de puntos 
89
         * @param list
90
         */
91
        public void setListPoint(ArrayList list){
92
                pointList = list;
93
        }
94
        
95
        /**
96
         * Dibujado de la capa de raster georeferenciado aplicando la 
97
         * transformaci?n del viewPort.
98
         */
99
        public void draw(BufferedImage image, Graphics2D g, ViewPort vp,
100
                        Cancellable cancel,double scale) throws DriverException {
101
                View theView = (View) PluginServices.getMDIManager().getActiveView();
102
                //BufferedImage img = theView.getMapControl().getImage();
103
                //g.drawImage(img, 0, 0, null);
104
                int dpto = (DIAM_CIRCLE >> 1);
105
                int incr = 5;
106
                Point2D pto = null;
107
                FLyrGeoRaster lyrGeoRaster = null;
108
                //Obtenemos la capa de puntos y la capa de georaster
109
                
110
                for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
111
                        FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
112
                        if(        lyr instanceof FLyrGeoRaster && 
113
                                lyr.getName().startsWith("*") &&
114
                                lyr.isActive())
115
                                lyrGeoRaster = (FLyrGeoRaster)lyr;
116
                }
117
                
118
                for(int i=0; i<pointList.size();i++){
119
                        
120
                        //Punto de la imagen
121
                        pto = ((GeoPoint)pointList.get(i)).pixelPoint;
122
                        
123
                        if(pto != null){
124
                                g.setColor(Color.red);
125
                                Point2D p = lyrGeoRaster.img2World(pto);
126
                                p = vp.fromMapPoint(p);
127
                                g.drawOval(        (int)p.getX() - dpto, 
128
                                                        (int)p.getY() - dpto, 
129
                                                        DIAM_CIRCLE, 
130
                                                        DIAM_CIRCLE);
131
                                g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
132
                                g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
133
                        }
134
                        
135
                        //Punto de la vista
136
                        pto = ((GeoPoint)pointList.get(i)).mapPoint;
137
                        if(pto != null){
138
                                Point2D p = vp.fromMapPoint(pto);
139
                                g.setColor(Color.green);
140
                                g.drawOval(        (int)p.getX() - dpto, 
141
                                                        (int)p.getY() - dpto, 
142
                                                        DIAM_CIRCLE, 
143
                                                        DIAM_CIRCLE);
144
                                g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
145
                                g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
146
                        }
147
                }
148
        }
149
        
150
        /* (non-Javadoc)
151
         * @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)
152
         */
153
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
154
                        double scale) throws DriverException {
155
                // TODO Auto-generated method stub
156

    
157
        }
158
        
159
        /**
160
         * A?ade un punto a la lista
161
         * @param point punto para la lista
162
         */
163
        public void addPoint(Point2D pixel, Point2D map){
164
                pointList.add(new GeoPoint(pixel, map));
165
        }
166
        
167
        /**
168
         * Obtiene el punto de la posici?n pos 
169
         */
170
        public GeoPoint getPoint(int pos){
171
                return (GeoPoint)pointList.get(pos);
172
        }
173
        
174
        /**
175
         * Elimina la lista de puntos almacenada
176
         */
177
        public void clear(){
178
                pointList = new ArrayList();
179
        }
180
        
181
        /**
182
         * Elimina el punto de la posici?n indicada por el par?metro pos
183
         * @param pos        Posici?n del punto a eliminar
184
         */
185
        public void remove(int pos){
186
                pointList.remove(pos);
187
        }
188
        
189
        /**
190
         *Elimina el ?ltimo punto de la lista.
191
         */
192
        public void delLastPoint(){
193
                pointList.remove(pointList.size() - 1);
194
        }
195
        
196
        /**
197
         * Obtiene le ?ltimo punto de la lista
198
         *
199
         */
200
        public GeoPoint getLastPoint(){
201
                return (GeoPoint)pointList.get(pointList.size());
202
        }
203
        
204
        /**
205
         * Devuelve el n?mero de puntos de la capa
206
         * @return
207
         */
208
        public int length(){
209
                return pointList.size();
210
        }
211
        
212
        /**
213
         * Actualiza un punto de la lista de una posici?n determinada
214
         * @param point punto para la lista
215
         */
216
        public void updatePoint(Point2D pixel, Point2D map, int pos){
217
                GeoPoint gp = (GeoPoint)pointList.get(pos);
218
                if(pixel != null)
219
                        gp.pixelPoint = pixel;
220
                if(map != null)
221
                        gp.mapPoint = map;
222
        }
223
        
224
        /**
225
         * Devuelve el n?mero de puntos de la lista
226
         * @return
227
         */
228
        public int getCountPoints(){
229
                if(pointList != null)
230
                        return pointList.size();
231
                else 
232
                        return 0;
233
        }
234
                
235
        /**
236
         * Obtiene el extent de la capa
237
         * @return extent en Rectangle2D.
238
         */
239
        public Rectangle2D getFullExtent()throws DriverException {
240
                View theView = (View) PluginServices.getMDIManager().getActiveView();
241
                return theView.getMapControl().getMapContext().getViewPort().getExtent();
242
        }
243
        
244
        /**
245
         * @return Returns the lastTool.
246
         */
247
        public String getLastTool() {
248
                return lastTool;
249
        }
250
        
251
        /**
252
         * @param lastTool The lastTool to set.
253
         */
254
        public void setLastTool(String lastTool) {
255
                this.lastTool = lastTool;
256
        }
257
        
258
        /**
259
         * Muestra en consola los puntos de la capa
260
         */
261
        public void showPoints(){
262
                for(int i=0;i<pointList.size();i++){
263
                        if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){
264
                                System.out.println("PUNTO "+i+": ");
265
                                System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY());
266
                                System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY());
267
                        }else
268
                                System.out.println("PUNTO "+i+": NULL");
269
                }
270
        }
271
}