Statistics
| Revision:

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

History | View | Annotate | Download (6.88 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
        /**
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
                //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
                for(int i=0; i<pointList.size();i++){
102
                        
103
                        //Punto de la imagen
104
                        pto = ((GeoPoint)pointList.get(i)).pixelPoint;
105
                        
106
                        if(pto != null){
107
                                g.setColor(Color.red);
108
                                Point2D p = lyrGeoRaster.img2World(pto);
109
                                p = vp.fromMapPoint(p);
110
                                g.drawOval(        (int)p.getX() - dpto, 
111
                                                        (int)p.getY() - dpto, 
112
                                                        DIAM_CIRCLE, 
113
                                                        DIAM_CIRCLE);
114
                                g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
115
                                g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
116
                        }
117
                        
118
                        //Punto de la vista
119
                        pto = ((GeoPoint)pointList.get(i)).mapPoint;
120
                        if(pto != null){
121
                                Point2D p = vp.fromMapPoint(pto);
122
                                g.setColor(Color.green);
123
                                g.drawOval(        (int)p.getX() - dpto, 
124
                                                        (int)p.getY() - dpto, 
125
                                                        DIAM_CIRCLE, 
126
                                                        DIAM_CIRCLE);
127
                                g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr);
128
                                g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY());
129
                        }
130
                }
131
        }
132
        
133
        /* (non-Javadoc)
134
         * @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)
135
         */
136
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
137
                        double scale) throws DriverException {
138
                // TODO Auto-generated method stub
139

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