svn-gvsig-desktop / tmp / trunk / cliente / WorkSpace_WPSClient / extWPSCallejero / src / es / logex / gvsig / streetsmap / core / impl_1_0_0 / StreetsMapProtocolHandlerImpl_1_0_0.java @ 26490
History | View | Annotate | Download (8.02 KB)
1 |
package es.logex.gvsig.streetsmap.core.impl_1_0_0; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.geom.Rectangle2D; |
5 |
import java.io.File; |
6 |
import java.io.IOException; |
7 |
import java.net.ConnectException; |
8 |
import java.net.MalformedURLException; |
9 |
import java.net.URL; |
10 |
import java.util.ArrayList; |
11 |
import java.util.List; |
12 |
|
13 |
import javax.swing.JOptionPane; |
14 |
|
15 |
import org.apache.log4j.Logger; |
16 |
import org.cresques.cts.IProjection; |
17 |
|
18 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
19 |
import com.iver.andami.PluginServices; |
20 |
import com.iver.cit.gvsig.ProjectExtension; |
21 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
22 |
import com.iver.cit.gvsig.fmap.DriverException; |
23 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
24 |
import com.iver.cit.gvsig.fmap.MapControl; |
25 |
import com.iver.cit.gvsig.fmap.ProjectionEvent; |
26 |
import com.iver.cit.gvsig.fmap.ViewPort; |
27 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
28 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
29 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
30 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
32 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
33 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
34 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
35 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
36 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
37 |
|
38 |
import es.logex.gvsig.fmap.drivers.WPSException; |
39 |
import es.logex.gvsig.fmap.drivers.wps.FMapWPSDriver; |
40 |
import es.logex.gvsig.fmap.drivers.wps.FMapWPSDriverFactory; |
41 |
import es.logex.gvsig.fmap.layers.FLyrWPS; |
42 |
import es.logex.gvsig.fmap.layers.FLyrWPSFactory; |
43 |
import es.logex.gvsig.streetsmap.core.StreetsMapLayerInfo; |
44 |
import es.logex.gvsig.streetsmap.core.StreetsMapLoadManager; |
45 |
import es.logex.gvsig.streetsmap.core.StreetsMapProtocolHandler; |
46 |
import es.logex.gvsig.wps.WPSCallejeroClientExtension_Old; |
47 |
import es.logex.xml.utils.LegendManager; |
48 |
|
49 |
public class StreetsMapProtocolHandlerImpl_1_0_0 implements |
50 |
StreetsMapProtocolHandler { |
51 |
|
52 |
private ViewPortListener viewPortListener;
|
53 |
private List<StreetsMapLayerInfo> listLayers = null; |
54 |
private static Logger logger = Logger |
55 |
.getLogger(StreetsMapProtocolHandlerImpl_1_0_0.class.getName()); |
56 |
private boolean lazy = true; |
57 |
private IProjection currentProjection = null; |
58 |
private boolean connectoToViewPort = false; |
59 |
private URL host = null; |
60 |
|
61 |
public StreetsMapProtocolHandlerImpl_1_0_0() {
|
62 |
|
63 |
} |
64 |
|
65 |
public void connectToViewPort(ViewPort v) { |
66 |
|
67 |
if (lazy) {
|
68 |
lazyInitialize(); |
69 |
} |
70 |
|
71 |
if (v != null) { |
72 |
|
73 |
currentProjection = v.getProjection(); |
74 |
|
75 |
viewPortListener = new ViewPortListener() {
|
76 |
public void extentChanged(ExtentEvent e) { |
77 |
logger.debug("Extent changed event");
|
78 |
redrawLayers(e.getNewExtent()); |
79 |
} |
80 |
|
81 |
public void backColorChanged(ColorEvent e) { |
82 |
} |
83 |
|
84 |
public void projectionChanged(ProjectionEvent e) { |
85 |
// TODO: Implementar
|
86 |
logger.error("projectionChanged not implemented yet");
|
87 |
|
88 |
} |
89 |
}; |
90 |
|
91 |
v.addViewPortListener(viewPortListener); |
92 |
|
93 |
this.connectoToViewPort = true; |
94 |
|
95 |
} |
96 |
|
97 |
} |
98 |
|
99 |
private void redrawLayers(Rectangle2D newExtent) { |
100 |
|
101 |
for (StreetsMapLayerInfo smlInfo : listLayers) {
|
102 |
|
103 |
smlInfo.setNewExtent(newExtent); |
104 |
|
105 |
if (smlInfo.getLayerInToc() == null) { |
106 |
logger.debug("Cargando capa " + smlInfo.getId());
|
107 |
|
108 |
smlInfo.setLastExtent(newExtent); |
109 |
loadLayer(newExtent, smlInfo, false);
|
110 |
|
111 |
} else {
|
112 |
if (StreetsMapLoadManager.mustReload(smlInfo, newExtent)) {
|
113 |
loadLayer(newExtent, smlInfo, true);
|
114 |
} |
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
private void loadLayer(Rectangle2D newExtent, StreetsMapLayerInfo smlInfo, boolean replace) { |
120 |
|
121 |
View v = (View) PluginServices.getMDIManager().getActiveWindow(); |
122 |
MapControl mapControl = v.getMapControl(); |
123 |
|
124 |
mapControl.getMapContext().beginAtomicEvent(); |
125 |
|
126 |
try {
|
127 |
FMapWPSDriver driver = FMapWPSDriverFactory |
128 |
.getFMapDriverForWPSOperation(smlInfo.getHost()); |
129 |
|
130 |
FLyrWPS flyrWPS = new FLyrWPSFactory().getFLyrWPS(
|
131 |
smlInfo, null, driver, true, true); |
132 |
|
133 |
if (flyrWPS != null) { |
134 |
flyrWPS.setVisible(true);
|
135 |
if(checkProjection(flyrWPS, mapControl.getViewPort())) {
|
136 |
if (replace)
|
137 |
mapControl.getMapContext().getLayers().replaceLayer(smlInfo.getId(), flyrWPS); |
138 |
else
|
139 |
mapControl.getMapContext().getLayers().addLayer( |
140 |
flyrWPS); |
141 |
} |
142 |
|
143 |
smlInfo.setLayerInToc(flyrWPS); |
144 |
smlInfo.setLastExtent(newExtent); |
145 |
|
146 |
LegendManager lm = new LegendManager();
|
147 |
|
148 |
lm.setLegend(flyrWPS, PluginServices.getPluginServices(this)
|
149 |
.getPluginDirectory().getAbsolutePath() |
150 |
+ File.separator
|
151 |
+ "leyendas"
|
152 |
+ File.separator
|
153 |
+ flyrWPS.getName() + ".gvl");
|
154 |
|
155 |
} |
156 |
|
157 |
} catch (ConnectException e) { |
158 |
// TODO Auto-generated catch block
|
159 |
e.printStackTrace(); |
160 |
} catch (IOException e) { |
161 |
// TODO Auto-generated catch block
|
162 |
e.printStackTrace(); |
163 |
} catch (WPSException e) {
|
164 |
// TODO Auto-generated catch block
|
165 |
e.printStackTrace(); |
166 |
} catch (FieldNotFoundException e) {
|
167 |
// TODO Auto-generated catch block
|
168 |
e.printStackTrace(); |
169 |
} finally {
|
170 |
mapControl.getMapContext().endAtomicEvent(); |
171 |
} |
172 |
} |
173 |
/**
|
174 |
* It removes the associated project table
|
175 |
* @param flayer
|
176 |
* Flayer vercorial
|
177 |
*/
|
178 |
private void removeProjectTable(FLyrVect flayer){ |
179 |
//remove it
|
180 |
ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
181 |
ArrayList tables = ext.getProject().getDocumentsByType(ProjectTableFactory.registerName);
|
182 |
for (int i=0 ; i<tables.size() ; i++){ |
183 |
ProjectTable projectTable = (ProjectTable)tables.get(i); |
184 |
try {
|
185 |
Object obj = projectTable.getAssociatedTable().getRecordset();
|
186 |
if (flayer.getRecordset().equals(projectTable.getAssociatedTable().getRecordset())){
|
187 |
ext.getProject().delDocument(projectTable); |
188 |
} |
189 |
} catch (DriverException e) {
|
190 |
//It doens't matter. The table will not deleted
|
191 |
} |
192 |
|
193 |
} |
194 |
} |
195 |
|
196 |
private boolean checkProjection(FLayer lyr, ViewPort viewPort) { |
197 |
if (lyr instanceof FLayers){ |
198 |
FLayers layers=(FLayers)lyr; |
199 |
for (int i=0;i<layers.getLayersCount();i++){ |
200 |
checkProjection(layers.getLayer(i),viewPort); |
201 |
} |
202 |
} |
203 |
|
204 |
if (lyr.isReprojectable()) {
|
205 |
boolean control = true; |
206 |
IProjection proj = lyr.getProjection(); |
207 |
// Comprobar que la projecci�n es la misma que la vista
|
208 |
if (proj == null) { |
209 |
// SUPONEMOS que la capa est� en la proyecci�n que
|
210 |
// estamos pidiendo (que ya es mucho suponer, ya).
|
211 |
lyr.setProjection(viewPort.getProjection()); |
212 |
return control;
|
213 |
} |
214 |
if (proj != viewPort.getProjection()) {
|
215 |
int option = JOptionPane.YES_OPTION; |
216 |
if (!CRSFactory.doesRigurousTransformations()) {
|
217 |
option = JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(), PluginServices |
218 |
.getText(this, "reproyectar_aviso")+"\n"+ PluginServices.getText(this,"Capa")+": "+lyr.getName(), PluginServices |
219 |
.getText(this, "reproyectar_pregunta"), |
220 |
JOptionPane.YES_NO_OPTION);
|
221 |
} |
222 |
|
223 |
if (option == JOptionPane.NO_OPTION) { |
224 |
return control;
|
225 |
} else {
|
226 |
control = lyr.reProject(((BaseView)PluginServices.getMDIManager().getActiveWindow()).getMapControl()); |
227 |
return control;
|
228 |
} |
229 |
} |
230 |
} |
231 |
return true; |
232 |
|
233 |
} |
234 |
private void lazyInitialize() { |
235 |
|
236 |
listLayers = new ArrayList<StreetsMapLayerInfo>(); |
237 |
|
238 |
listLayers.add(new StreetsMapLayerInfoImpl_1_0_0("numpolicias", |
239 |
"Números de policía",
|
240 |
"Los números de policía corregidos y verificados",
|
241 |
"numpolicias", "EPSG:23030", this.host)); |
242 |
|
243 |
listLayers.add(new StreetsMapLayerInfoImpl_1_0_0("manzanas", |
244 |
"Manzanas", "Manzanas o MASA", "manzanas", "EPSG:23030", |
245 |
this.host));
|
246 |
|
247 |
listLayers.add(new StreetsMapLayerInfoImpl_1_0_0("calles", |
248 |
"Ejes de calles", "Ejes de calles por tramos", "calles", |
249 |
"EPSG:23030", this.host)); |
250 |
|
251 |
listLayers.add(new StreetsMapLayerInfoImpl_1_0_0("textos", "Textos", |
252 |
"Textos y toponimía", "textos", "EPSG:23030", this.host)); |
253 |
|
254 |
lazy = false;
|
255 |
} |
256 |
|
257 |
public List<StreetsMapLayerInfo> getStreetsMapLayerInfo() { |
258 |
|
259 |
if (lazy) {
|
260 |
lazyInitialize(); |
261 |
} |
262 |
return listLayers;
|
263 |
} |
264 |
|
265 |
public String getVersion() { |
266 |
return "1.0.0"; |
267 |
} |
268 |
|
269 |
public URL getHost() { |
270 |
return this.host; |
271 |
} |
272 |
|
273 |
public void setHost(URL host) { |
274 |
this.host = host;
|
275 |
|
276 |
} |
277 |
|
278 |
} |