Revision 4488 branches/v05/extensions/extCatalogYNomenclator/src/es/gva/cit/gvsig/gazetteer/loaders/FeatureLoader.java
FeatureLoader.java | ||
---|---|---|
1 | 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 |
*/ |
|
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 | 41 |
package es.gva.cit.gvsig.gazetteer.loaders; |
42 | 42 |
|
43 | 43 |
|
44 | 44 |
import java.awt.Color; |
45 |
import java.awt.geom.Point2D; |
|
45 | 46 |
import java.awt.geom.Rectangle2D; |
46 | 47 |
|
48 |
import org.cresques.cts.IDatum; |
|
49 |
import org.cresques.cts.IProjection; |
|
47 | 50 |
import org.cresques.cts.ProjectionPool; |
51 |
import org.cresques.cts.gt2.CoordSys; |
|
52 |
import org.cresques.cts.gt2.CoordTrans; |
|
48 | 53 |
|
49 | 54 |
import com.iver.andami.PluginServices; |
50 | 55 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
... | ... | |
66 | 71 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
67 | 72 |
*/ |
68 | 73 |
public class FeatureLoader { |
69 |
/** |
|
70 |
* It makes a zoom in gvSIG |
|
71 |
* @param |
|
72 |
* feature |
|
73 |
* @param |
|
74 |
* query |
|
75 |
* Query that contains advanced options to search and |
|
76 |
* to show the results |
|
77 |
* @return |
|
78 |
* true or false if fail |
|
79 |
*/ |
|
80 |
public boolean load(Feature feature,Query query) { |
|
81 |
|
|
82 |
addAndDrawLabel(feature, |
|
83 |
query.getOptions().getAspect().isKeepOld(), |
|
84 |
query.getOptions().getAspect().isPaintCurrent()); |
|
85 |
|
|
86 |
if (query.getOptions().getAspect().isGoTo()){ |
|
87 |
focusCenter(feature); |
|
88 |
} |
|
89 |
|
|
74 |
/** |
|
75 |
* Coordinates Transformer |
|
76 |
*/ |
|
77 |
private CoordTrans coordTrans; |
|
78 |
|
|
79 |
/** |
|
80 |
* @param projection |
|
81 |
* Server projection |
|
82 |
*/ |
|
83 |
public FeatureLoader(String sProjection){ |
|
84 |
com.iver.cit.gvsig.gui.View activeView = |
|
85 |
(com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
|
86 |
|
|
87 |
|
|
88 |
IProjection projection = ProjectionPool.get(sProjection); |
|
89 |
if (projection == null){ |
|
90 |
projection = activeView.getMapControl().getViewPort().getProjection(); |
|
91 |
} |
|
92 |
|
|
93 |
coordTrans= new CoordTrans((CoordSys) projection, |
|
94 |
(CoordSys) activeView.getMapControl().getViewPort().getProjection()); |
|
95 |
} |
|
96 |
/** |
|
97 |
* It makes a zoom in gvSIG |
|
98 |
* @param |
|
99 |
* feature |
|
100 |
* @param |
|
101 |
* query |
|
102 |
* Query that contains advanced options to search and |
|
103 |
* to show the results |
|
104 |
* @return |
|
105 |
* true or false if fail |
|
106 |
*/ |
|
107 |
public boolean load(Feature feature,Query query) { |
|
108 |
addAndDrawLabel(feature, |
|
109 |
query.getOptions().getAspect().isKeepOld(), |
|
110 |
query.getOptions().getAspect().isPaintCurrent()); |
|
111 |
|
|
112 |
if (query.getOptions().getAspect().isGoTo()){ |
|
113 |
focusCenter(feature); |
|
114 |
} |
|
115 |
|
|
90 | 116 |
return true; |
91 | 117 |
} |
92 |
|
|
93 |
/**
|
|
94 |
* This method focus the toponim in the center of the view
|
|
95 |
* @param feature
|
|
96 |
* Feature that contains the coordinates
|
|
97 |
*/
|
|
98 |
private void focusCenter(Feature feature){
|
|
99 |
com.iver.cit.gvsig.gui.View activeView =
|
|
118 |
|
|
119 |
/**
|
|
120 |
* This method focus the toponim in the center of the view
|
|
121 |
* @param feature
|
|
122 |
* Feature that contains the coordinates
|
|
123 |
*/
|
|
124 |
private void focusCenter(Feature feature){
|
|
125 |
com.iver.cit.gvsig.gui.View activeView =
|
|
100 | 126 |
(com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
101 |
|
|
102 |
if (activeView.getProjection().getDatum().toString().indexOf("European_Datum_1950") > 0){ |
|
103 |
activeView.getMapControl().getViewPort().setExtent(new Rectangle2D.Double(feature.getCoordinates().getX() - 5000, |
|
104 |
feature.getCoordinates().getY() - 5000, |
|
105 |
10000, |
|
106 |
10000)); |
|
107 |
}else{//WGS_1984 |
|
108 |
activeView.getMapControl().getViewPort().setExtent(new Rectangle2D.Double(feature.getCoordinates().getX() - 0.05, |
|
109 |
feature.getCoordinates().getY() - 0.05, |
|
110 |
0.1, |
|
111 |
0.1)); |
|
112 |
} |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* It adds a new Label to the current view |
|
118 |
* @param feature |
|
119 |
* To obtain the coordinates and the toponim name |
|
120 |
* @param isRemoveOldClicked |
|
121 |
* To remove or keep the old searches |
|
122 |
*/ |
|
123 |
private void addAndDrawLabel(Feature feature,boolean isRemoveOldClicked,boolean isMarkedPlaceClicked){ |
|
124 |
com.iver.cit.gvsig.gui.View activeView = |
|
127 |
|
|
128 |
IDatum datum = activeView.getProjection().getDatum(); |
|
129 |
|
|
130 |
Point2D point = getReprojectedPoint(feature.getCoordinates()); |
|
131 |
Rectangle2D extent; |
|
132 |
|
|
133 |
if (datum.toString().indexOf("European_Datum_1950") > 0){ |
|
134 |
extent = new Rectangle2D.Double(point.getX() - 5000, |
|
135 |
point.getY() - 5000, |
|
136 |
10000, |
|
137 |
10000); |
|
138 |
}else{//WGS_1984 |
|
139 |
extent = new Rectangle2D.Double(point.getX() - 0.05, |
|
140 |
point.getY() - 0.05, |
|
141 |
0.1, |
|
142 |
0.1); |
|
143 |
} |
|
144 |
|
|
145 |
activeView.getMapControl().getViewPort().setExtent(extent); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* It adds a new Label to the current view |
|
150 |
* @param feature |
|
151 |
* To obtain the coordinates and the toponim name |
|
152 |
* @param isRemoveOldClicked |
|
153 |
* To remove or keep the old searches |
|
154 |
*/ |
|
155 |
private void addAndDrawLabel(Feature feature,boolean isRemoveOldClicked,boolean isMarkedPlaceClicked){ |
|
156 |
com.iver.cit.gvsig.gui.View activeView = |
|
125 | 157 |
(com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
126 |
|
|
127 |
GraphicLayer lyr = activeView.getMapControl().getMapContext().getGraphicsLayer(); |
|
128 |
//lyr.setProjection(ProjectionPool.get("EPSG:4326")); |
|
129 |
//lyr.setCoordTrans(ct); |
|
130 |
|
|
131 |
if (isRemoveOldClicked){ |
|
132 |
lyr.clearAllGraphics(); |
|
133 |
} |
|
134 |
|
|
135 |
if (isMarkedPlaceClicked){ |
|
136 |
FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT); |
|
137 |
theSymbol.setColor(Color.RED); |
|
138 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
|
139 |
theSymbol.setFontColor(Color.BLACK); |
|
140 |
theSymbol.setSizeInPixels(true); |
|
141 |
theSymbol.setSize(10); |
|
142 |
|
|
143 |
int idSymbol = lyr.addSymbol(theSymbol); |
|
144 |
|
|
145 |
IGeometry geom = ShapeFactory.createPoint2D(new FPoint2D(feature.getCoordinates())); |
|
146 |
|
|
147 |
FGraphicLabel theLabel = new FGraphicLabel(geom, idSymbol, feature.getName()); |
|
148 |
lyr.addGraphic(theLabel); |
|
149 |
|
|
150 |
DeleteSearchesModule.setVisible(); |
|
151 |
PluginServices.getMainFrame().enableControls(); |
|
152 |
} |
|
153 |
|
|
154 |
activeView.getMapControl().drawGraphics(); |
|
155 |
|
|
156 |
//This line could look stupid, but is necessary because grawGraphics does't |
|
157 |
//remove the old Graphics searched |
|
158 |
activeView.getMapControl().getViewPort().setExtent(activeView.getMapControl().getViewPort().getExtent()); |
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
} |
|
158 |
|
|
159 |
GraphicLayer lyr = activeView.getMapControl().getMapContext().getGraphicsLayer(); |
|
160 |
|
|
161 |
if (isRemoveOldClicked){ |
|
162 |
lyr.clearAllGraphics(); |
|
163 |
} |
|
164 |
|
|
165 |
if (isMarkedPlaceClicked){ |
|
166 |
int idSymbol = lyr.addSymbol(getSymbol()); |
|
167 |
|
|
168 |
IGeometry geom = ShapeFactory.createPoint2D(new FPoint2D(getReprojectedPoint(feature.getCoordinates()))); |
|
169 |
|
|
170 |
FGraphicLabel theLabel = new FGraphicLabel(geom, idSymbol, feature.getName()); |
|
171 |
lyr.addGraphic(theLabel); |
|
172 |
|
|
173 |
DeleteSearchesModule.setVisible(); |
|
174 |
PluginServices.getMainFrame().enableControls(); |
|
175 |
} |
|
176 |
|
|
177 |
activeView.getMapControl().drawGraphics(); |
|
178 |
|
|
179 |
//This line could look stupid, but is necessary because grawGraphics does't |
|
180 |
//remove the old Graphics searched |
|
181 |
activeView.getMapControl().getViewPort().setExtent(activeView.getMapControl().getViewPort().getExtent()); |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Creates a FSymbol |
|
186 |
* @return |
|
187 |
* FSymbol |
|
188 |
*/ |
|
189 |
private FSymbol getSymbol(){ |
|
190 |
FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT); |
|
191 |
theSymbol.setColor(Color.RED); |
|
192 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
|
193 |
theSymbol.setFontColor(Color.BLACK); |
|
194 |
theSymbol.setSizeInPixels(true); |
|
195 |
theSymbol.setSize(10); |
|
196 |
return theSymbol; |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Reprojects the new point |
|
201 |
* @param ptOrig |
|
202 |
* Origin point |
|
203 |
* @return |
|
204 |
* FPoint2D |
|
205 |
*/ |
|
206 |
private Point2D getReprojectedPoint(Point2D ptOrigin){ |
|
207 |
Point2D ptDest = null; |
|
208 |
return getCoordTrans().convert(ptOrigin, ptDest); |
|
209 |
} |
|
210 |
/** |
|
211 |
* @return the coordTrans |
|
212 |
*/ |
|
213 |
public CoordTrans getCoordTrans() { |
|
214 |
return coordTrans; |
|
215 |
} |
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
} |
Also available in: Unified diff