svn-gvsig-desktop / trunk / extensions / extCatalogAndGazetteer / src / es / gva / cit / gvsig / gazetteer / loaders / FeatureLoader.java @ 15557
History | View | Annotate | Download (6.36 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 es.gva.cit.gvsig.gazetteer.loaders; |
42 |
|
43 |
|
44 |
import java.awt.Color; |
45 |
import java.awt.Toolkit; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
|
49 |
import org.cresques.cts.ICoordTrans; |
50 |
import org.cresques.cts.IProjection; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.cit.gvsig.fmap.MapContext; |
54 |
import com.iver.cit.gvsig.fmap.ViewPort; |
55 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
57 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
58 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
59 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
60 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
61 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
62 |
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel; |
63 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
64 |
|
65 |
import es.gva.cit.gazetteer.querys.Feature; |
66 |
import es.gva.cit.gazetteer.querys.GazetteerQuery; |
67 |
import es.gva.cit.gvsig.gazetteer.DeleteSearchesExtension; |
68 |
|
69 |
|
70 |
/**
|
71 |
* This class is used to load a new feature like a layer in gvSIG
|
72 |
*
|
73 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
74 |
*/
|
75 |
public class FeatureLoader { |
76 |
/**
|
77 |
* Coordinates Transformer
|
78 |
*/
|
79 |
private ICoordTrans coordTrans;
|
80 |
|
81 |
/**
|
82 |
* @param projection
|
83 |
* Server projection
|
84 |
*/
|
85 |
public FeatureLoader(String sProjection){ |
86 |
View activeView =
|
87 |
(View) PluginServices.getMDIManager().getActiveWindow();
|
88 |
|
89 |
|
90 |
IProjection projection = CRSFactory.getCRS(sProjection); |
91 |
if (projection == null){ |
92 |
projection = activeView.getMapControl().getViewPort().getProjection(); |
93 |
} |
94 |
|
95 |
coordTrans= projection.getCT(activeView.getMapControl().getViewPort().getProjection()); |
96 |
} |
97 |
/**
|
98 |
* It makes a zoom in gvSIG
|
99 |
* @param
|
100 |
* feature
|
101 |
* @param
|
102 |
* query
|
103 |
* Query that contains advanced options to search and
|
104 |
* to show the results
|
105 |
* @return
|
106 |
* true or false if fail
|
107 |
*/
|
108 |
public boolean load(Feature feature,GazetteerQuery query) { |
109 |
addAndDrawLabel(feature, |
110 |
query.getOptions().getAspect().isKeepOld(), |
111 |
query.getOptions().getAspect().isPaintCurrent()); |
112 |
|
113 |
if (query.getOptions().getAspect().isGoTo()){
|
114 |
focusCenter(feature); |
115 |
} |
116 |
|
117 |
return true; |
118 |
} |
119 |
|
120 |
/**
|
121 |
* This method focus the toponim in the center of the view
|
122 |
* @param feature
|
123 |
* Feature that contains the coordinates
|
124 |
*/
|
125 |
private void focusCenter(Feature feature){ |
126 |
View activeView =
|
127 |
(View) PluginServices.getMDIManager().getActiveWindow();
|
128 |
|
129 |
IProjection projection = activeView.getProjection(); |
130 |
ViewPort viewPort = activeView.getMapControl().getViewPort(); |
131 |
Point2D point = getReprojectedPoint(feature.getCoordinates());
|
132 |
|
133 |
Rectangle2D zoomExtent = null; |
134 |
if (viewPort.getAdjustedExtent() == null){ |
135 |
|
136 |
}else{
|
137 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
138 |
double dpi = kit.getScreenResolution();
|
139 |
Rectangle2D extent = projection.getExtent(viewPort.getAdjustedExtent(),
|
140 |
new Double(25000).doubleValue(), |
141 |
new Double(viewPort.getImageWidth()).doubleValue(), |
142 |
new Double(viewPort.getImageHeight()).doubleValue(), |
143 |
MapContext.CHANGE[viewPort.getMapUnits()], |
144 |
MapContext.CHANGE[viewPort.getDistanceUnits()], |
145 |
dpi); |
146 |
zoomExtent = new Rectangle2D.Double(point.getX() - extent.getWidth()/2, |
147 |
point.getY() - extent.getHeight()/2,
|
148 |
extent.getWidth(), |
149 |
extent.getHeight()); |
150 |
activeView.getMapControl().getMapContext().zoomToExtent(zoomExtent); |
151 |
} |
152 |
|
153 |
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* It adds a new Label to the current view
|
158 |
* @param feature
|
159 |
* To obtain the coordinates and the toponim name
|
160 |
* @param isRemoveOldClicked
|
161 |
* To remove or keep the old searches
|
162 |
*/
|
163 |
private void addAndDrawLabel(Feature feature,boolean isRemoveOldClicked,boolean isMarkedPlaceClicked){ |
164 |
View activeView =
|
165 |
(View) PluginServices.getMDIManager().getActiveWindow();
|
166 |
|
167 |
GraphicLayer lyr = activeView.getMapControl().getMapContext().getGraphicsLayer(); |
168 |
|
169 |
if (isRemoveOldClicked){
|
170 |
lyr.clearAllGraphics(); |
171 |
} |
172 |
|
173 |
if (isMarkedPlaceClicked){
|
174 |
int idSymbol = lyr.addSymbol(getSymbol());
|
175 |
|
176 |
IGeometry geom = ShapeFactory.createPoint2D(new FPoint2D(getReprojectedPoint(feature.getCoordinates())));
|
177 |
|
178 |
FGraphicLabel theLabel = new FGraphicLabel(geom, idSymbol, feature.getName());
|
179 |
lyr.addGraphic(theLabel); |
180 |
|
181 |
DeleteSearchesExtension.setVisible(); |
182 |
PluginServices.getMainFrame().enableControls(); |
183 |
} |
184 |
|
185 |
activeView.getMapControl().drawGraphics(); |
186 |
|
187 |
//This line could look stupid, but is necessary because grawGraphics does't
|
188 |
//remove the old Graphics searched
|
189 |
activeView.getMapControl().getViewPort().setExtent(activeView.getMapControl().getViewPort().getExtent()); |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Creates a FSymbol
|
194 |
* @return
|
195 |
* FSymbol
|
196 |
*/
|
197 |
private FSymbol getSymbol(){
|
198 |
FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
199 |
theSymbol.setColor(Color.RED);
|
200 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
201 |
theSymbol.setFontColor(Color.BLACK);
|
202 |
theSymbol.setSizeInPixels(true);
|
203 |
theSymbol.setSize(10);
|
204 |
return theSymbol;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Reprojects the new point
|
209 |
* @param ptOrig
|
210 |
* Origin point
|
211 |
* @return
|
212 |
* FPoint2D
|
213 |
*/
|
214 |
private Point2D getReprojectedPoint(Point2D ptOrigin){ |
215 |
Point2D ptDest = null; |
216 |
return getCoordTrans().convert(ptOrigin, ptDest);
|
217 |
} |
218 |
/**
|
219 |
* @return the coordTrans
|
220 |
*/
|
221 |
public ICoordTrans getCoordTrans() {
|
222 |
return coordTrans;
|
223 |
} |
224 |
|
225 |
|
226 |
|
227 |
} |