svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / georeferencing / ui / zoom / ViewMapRequestManager.java @ 18321
History | View | Annotate | Download (5.42 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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 |
package org.gvsig.rastertools.georeferencing.ui.zoom; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.Graphics2D; |
23 |
import java.awt.geom.Point2D; |
24 |
import java.awt.geom.Rectangle2D; |
25 |
import java.awt.image.BufferedImage; |
26 |
|
27 |
import org.gvsig.rastertools.georeferencing.view.BaseZoomView; |
28 |
|
29 |
import com.iver.cit.gvsig.fmap.MapControl; |
30 |
import com.iver.cit.gvsig.fmap.ViewPort; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
32 |
import com.iver.utiles.swing.threads.Cancellable; |
33 |
|
34 |
/**
|
35 |
* Gestor de peticiones de zoom sobre el panel con el raster a georreferenciar.
|
36 |
* Implementa el interfaz IExtensionRequest para que este comunique la peticiones
|
37 |
* de zoom y ViewRasterRequestManager pueda hacer las peticiones de datos a la capa.
|
38 |
*
|
39 |
* 30/12/2007
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
41 |
*/
|
42 |
public class ViewMapRequestManager implements IExtensionRequest { |
43 |
private FLayers lyrs = null; |
44 |
private BaseZoomView view = null; |
45 |
private MapControl mapControl = null; |
46 |
|
47 |
/**
|
48 |
* Asigna la capa a georreferenciar de donde se obtienen los datos.
|
49 |
* @param lyr
|
50 |
*/
|
51 |
public ViewMapRequestManager(BaseZoomView view, MapControl mapControl) {
|
52 |
this.mapControl = mapControl;
|
53 |
this.lyrs = mapControl.getMapContext().getLayers();
|
54 |
this.view = view;
|
55 |
} |
56 |
|
57 |
/**
|
58 |
* Calcula la extensi?n que contendr? la vista a partir del extent
|
59 |
* m?ximo de la capa/s que contienen . Tienen en cuenta las distintan proporciones
|
60 |
* entre vista y petici?n
|
61 |
* @param Rectangle2D
|
62 |
*/
|
63 |
public Rectangle2D initRequest(Rectangle2D extent) throws InvalidRequestException { |
64 |
double x = extent.getX();
|
65 |
double y = extent.getY();
|
66 |
double w = extent.getWidth();
|
67 |
double h = extent.getHeight();
|
68 |
//Calculamos la extensi?n de la vista para el extent m?ximo que va a contener
|
69 |
//teniendo en cuenta las proporciones de ambos.
|
70 |
if(extent.getWidth() < extent.getHeight()) {
|
71 |
if(((double)view.getCanvasWidth() / (double)view.getCanvasHeight()) <= (extent.getWidth() / extent.getHeight())) { |
72 |
h = (view.getCanvasHeight() * w) / view.getCanvasWidth(); |
73 |
y = extent.getCenterY() - (h / 2);
|
74 |
} else { //p1 < p2 |
75 |
w = (view.getCanvasWidth() * h) / view.getCanvasHeight(); |
76 |
x = extent.getCenterX() - (w / 2);
|
77 |
} |
78 |
} else {
|
79 |
if(((double)view.getCanvasWidth() / (double)view.getCanvasHeight()) >= (extent.getWidth() / extent.getHeight())) { |
80 |
w = (view.getCanvasWidth() * h) / view.getCanvasHeight(); |
81 |
x = extent.getCenterX() - (w / 2);
|
82 |
} else { //p1 < p2 |
83 |
h = (view.getCanvasHeight() * w) / view.getCanvasWidth(); |
84 |
y = extent.getCenterY() - (h / 2);
|
85 |
} |
86 |
} |
87 |
Rectangle2D r = new Rectangle2D.Double(x, y, w, h); |
88 |
setDrawParams(null, r);
|
89 |
request(r); |
90 |
return r;
|
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
* @see org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest#request(java.awt.geom.Rectangle2D)
|
96 |
*/
|
97 |
public Rectangle2D request(Rectangle2D extent) throws InvalidRequestException { |
98 |
if(extent == null) |
99 |
return lyrs.getFullExtent();
|
100 |
|
101 |
//Obtenemos el viewport y calculamos la matriz de transformaci?n
|
102 |
ViewPort vp = new ViewPort(null); |
103 |
vp.setImageSize(new Dimension(view.getCanvasWidth(), view.getCanvasHeight())); |
104 |
vp.setExtent(extent); |
105 |
|
106 |
try {
|
107 |
//Dibujamos a trav?s del render de la capa en un graphics como el de la vista
|
108 |
BufferedImage initImg = new BufferedImage(view.getCanvasWidth(), view.getCanvasHeight(), BufferedImage.TYPE_INT_RGB); |
109 |
lyrs.draw(initImg, (Graphics2D)initImg.getGraphics(), vp, new CancellableClass(), mapControl.getMapContext().getScaleView()); |
110 |
|
111 |
setDrawParams(initImg, extent); |
112 |
|
113 |
} catch (Exception e) { |
114 |
throw new InvalidRequestException("Error en al acceso al fichero"); |
115 |
} |
116 |
return extent;
|
117 |
} |
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
* @see org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest#fullExtent(java.awt.Dimension)
|
122 |
*/
|
123 |
public void fullExtent() throws InvalidRequestException { |
124 |
this.initRequest(lyrs.getFullExtent());
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* Asigna los par?metros para el control de zoom del mapa
|
129 |
* @param img BufferedImage
|
130 |
* @param vp ViewPort
|
131 |
*/
|
132 |
public void setDrawParams(BufferedImage img, Rectangle2D extBuf) { |
133 |
if(view != null && lyrs != null) { |
134 |
if(img != null) |
135 |
view.setDrawParams(img, extBuf, extBuf.getWidth()/img.getWidth(), new Point2D.Double(extBuf.getCenterX(), extBuf.getCenterY())); |
136 |
else
|
137 |
view.setDrawParams(img, extBuf, extBuf.getWidth()/view.getCanvasWidth(), new Point2D.Double(extBuf.getCenterX(), extBuf.getCenterY())); |
138 |
} |
139 |
} |
140 |
|
141 |
class CancellableClass implements Cancellable{ |
142 |
private boolean cancel = false; |
143 |
public void setCanceled(boolean canceled) { |
144 |
this.cancel = canceled;
|
145 |
} |
146 |
|
147 |
public boolean isCanceled() { |
148 |
return this.cancel; |
149 |
} |
150 |
} |
151 |
} |