root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayers.java @ 10679
History | View | Annotate | Download (42.9 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.Graphics2D; |
44 |
import java.awt.Point; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.awt.image.WritableRaster; |
48 |
import java.io.File; |
49 |
import java.util.ArrayList; |
50 |
import java.util.Collections; |
51 |
import java.util.Iterator; |
52 |
import java.util.List; |
53 |
import java.util.Vector; |
54 |
|
55 |
import javax.print.attribute.PrintRequestAttributeSet; |
56 |
import javax.swing.ImageIcon; |
57 |
|
58 |
import org.apache.log4j.Logger; |
59 |
import org.cresques.cts.ICoordTrans; |
60 |
import org.cresques.cts.IProjection; |
61 |
|
62 |
import com.hardcode.driverManager.Driver; |
63 |
import com.hardcode.driverManager.DriverLoadException; |
64 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
65 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
66 |
import com.iver.cit.gvsig.exceptions.layers.DriverLayerException; |
67 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
68 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
69 |
import com.iver.cit.gvsig.fmap.MapContext; |
70 |
import com.iver.cit.gvsig.fmap.MapControl; |
71 |
import com.iver.cit.gvsig.fmap.ViewPort; |
72 |
import com.iver.cit.gvsig.fmap.core.ILabelable; |
73 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
74 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
75 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
76 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
77 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
78 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
79 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection; |
80 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
82 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
83 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
84 |
import com.iver.utiles.IPersistance; |
85 |
import com.iver.utiles.XMLEntity; |
86 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
87 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
88 |
import com.iver.utiles.swing.threads.Cancellable; |
89 |
|
90 |
/**
|
91 |
* Representa un nodo interno en el ?rbol de capas
|
92 |
*/
|
93 |
public class FLayers extends FLyrDefault implements VectorialData, LayerCollection, InfoByPoint |
94 |
{ |
95 |
//ArrayList de Listener registrados.
|
96 |
protected ArrayList layerCollectionListeners = new ArrayList(); |
97 |
|
98 |
|
99 |
protected List layers = Collections.synchronizedList(new ArrayList()); |
100 |
protected MapContext fmap;
|
101 |
protected static Logger logger = Logger.getLogger(FLayers.class.getName()); |
102 |
/**
|
103 |
* Crea un nuevo FLayers.
|
104 |
*
|
105 |
* @param fmap
|
106 |
* @param parent
|
107 |
*/
|
108 |
public FLayers(MapContext fmap, FLayers parent) {
|
109 |
setParentLayer(parent); |
110 |
this.fmap = fmap;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* A?ade un listener de los eventos de la colecci?n de capas
|
115 |
*
|
116 |
* @param listener
|
117 |
*/
|
118 |
public void addLayerCollectionListener(LayerCollectionListener listener) { |
119 |
if (!layerCollectionListeners.contains(listener))
|
120 |
layerCollectionListeners.add(listener); |
121 |
} |
122 |
|
123 |
|
124 |
/**
|
125 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllVisibles(boolean)
|
126 |
*/
|
127 |
public void setAllVisibles(boolean visible) { |
128 |
FLayer lyr; |
129 |
|
130 |
for (int i = 0; i < layers.size(); i++) { |
131 |
lyr = ((FLayer) layers.get(i)); |
132 |
lyr.setVisible(visible); |
133 |
|
134 |
if (lyr instanceof LayerCollection) { |
135 |
((LayerCollection) lyr).setAllVisibles(visible); |
136 |
} |
137 |
} |
138 |
} |
139 |
|
140 |
/**
|
141 |
* Elimina un listener de los eventos de la colecci?n de capas
|
142 |
*
|
143 |
* @param listener
|
144 |
*/
|
145 |
public void removeLayerCollectionListener(LayerCollectionListener listener) { |
146 |
layerCollectionListeners.remove(listener); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* A?ade una capa.
|
151 |
*
|
152 |
* @param layer
|
153 |
*/
|
154 |
// private void doAddLayer(FLayer layer) {
|
155 |
// layers.add(layer);
|
156 |
// layer.setParentLayer(this);
|
157 |
// }
|
158 |
private void doAddLayer(int pos,FLayer layer) { |
159 |
layers.add(pos,layer); |
160 |
layer.setParentLayer(this);
|
161 |
} |
162 |
public void addLayer(FLayer layer) { |
163 |
addLayer(layers.size(),layer); |
164 |
} |
165 |
/**
|
166 |
* A?ade una capa al final de la lista de subcapas
|
167 |
*
|
168 |
* @param layer
|
169 |
*
|
170 |
* @throws CancelationException
|
171 |
* @throws LoadLayerException
|
172 |
*/
|
173 |
public void addLayer(int pos,FLayer layer) { |
174 |
try {
|
175 |
//Notificamos a la capa que va a ser a?adida
|
176 |
//FLyrDefault layerDef = (FLyrDefault)layer;
|
177 |
//if (!layerDef.isUnavailable()) {
|
178 |
if (layer instanceof FLyrDefault) |
179 |
((FLyrDefault)layer).wakeUp(); |
180 |
|
181 |
if (layer instanceof FLayers){ |
182 |
FLayers layers=(FLayers)layer; |
183 |
fmap.addAsCollectionListener(layers); |
184 |
} |
185 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
186 |
//}
|
187 |
|
188 |
doAddLayer(pos,layer); |
189 |
|
190 |
//if (!layerDef.isUnavailable()) {
|
191 |
callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer)); |
192 |
//}
|
193 |
} catch (CancelationException e) {
|
194 |
// TODO Auto-generated catch block
|
195 |
e.printStackTrace(); |
196 |
} catch (LoadLayerException e) {
|
197 |
layer.setAvailable(false);
|
198 |
layer.addError(e); |
199 |
} |
200 |
} |
201 |
|
202 |
/**
|
203 |
* Mueve una capa de la posici?n from a la posici?n to. (Se supone que
|
204 |
* est?n dentro del mismo nivel). Para mover entre niveles, usar otro
|
205 |
* m?todo (por hacer)
|
206 |
*
|
207 |
* @param from origen.
|
208 |
* @param to destino.
|
209 |
*
|
210 |
* @throws CancelationException
|
211 |
*/
|
212 |
public void moveTo(int from, int to) throws CancelationException { |
213 |
int newfrom=layers.size()-from-1; |
214 |
int newto=layers.size()-to-1; |
215 |
if ( newfrom < 0 || newfrom >=layers.size() || newto < 0 || newto >= layers.size()) return; |
216 |
FLayer aux = (FLayer) layers.get(newfrom); |
217 |
callLayerMoving(LayerPositionEvent.createLayerMovingEvent(aux, newfrom, newto)); |
218 |
layers.remove(newfrom); |
219 |
layers.add(newto, aux); |
220 |
callLayerMoved(LayerPositionEvent.createLayerMovedEvent(aux, newfrom, newto)); |
221 |
} |
222 |
|
223 |
/**
|
224 |
* Borra una capa del ArrayList que contiene a las capas.
|
225 |
*
|
226 |
* @param lyr FLayer.
|
227 |
*/
|
228 |
private void doRemoveLayer(FLayer lyr) { |
229 |
layers.remove(lyr); |
230 |
} |
231 |
|
232 |
/**
|
233 |
* Borra una capa de la colecci?n de capas.
|
234 |
*
|
235 |
* @param lyr FLayer
|
236 |
*
|
237 |
* @throws CancelationException
|
238 |
*/
|
239 |
public void removeLayer(FLayer lyr) throws CancelationException { |
240 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
241 |
doRemoveLayer(lyr); |
242 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
243 |
} |
244 |
|
245 |
/**
|
246 |
* Borra una FLayer del vector a partir del identificador.
|
247 |
*
|
248 |
* @param idLayer
|
249 |
*/
|
250 |
public void removeLayer(int idLayer) { |
251 |
FLayer lyr = (FLayer) layers.get(idLayer); |
252 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
253 |
layers.remove(idLayer); |
254 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
255 |
} |
256 |
|
257 |
/**
|
258 |
* M?todo de conveniencia para borrar una capa con ese nombre
|
259 |
*
|
260 |
* @param layerName
|
261 |
*/
|
262 |
public void removeLayer(String layerName) { |
263 |
FLayer lyr; |
264 |
|
265 |
for (int i = 0; i < layers.size(); i++) { |
266 |
lyr = ((FLayer) layers.get(i)); |
267 |
|
268 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
269 |
removeLayer(i); |
270 |
|
271 |
break;
|
272 |
} |
273 |
} |
274 |
} |
275 |
/**
|
276 |
* M?todo de conveniencia para reemplazar una capa con ese nombre
|
277 |
*
|
278 |
* @param layerName
|
279 |
* @throws LoadLayerException
|
280 |
*/
|
281 |
public void replaceLayer(String layerName, FLayer layer) throws LoadLayerException |
282 |
{ |
283 |
FLayer lyr; |
284 |
FLayer parent; |
285 |
for (int i = 0; i < layers.size(); i++) { |
286 |
lyr = ((FLayer) layers.get(i)); |
287 |
|
288 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
289 |
parent = lyr.getParentLayer(); |
290 |
removeLayer(i); |
291 |
if (parent != null) |
292 |
//Notificamos a la capa que va a ser a?adida
|
293 |
if (layer instanceof FLyrDefault) |
294 |
((FLyrDefault)layer).wakeUp(); |
295 |
|
296 |
if (layer instanceof FLayers){ |
297 |
FLayers layers=(FLayers)layer; |
298 |
fmap.addAsCollectionListener(layers); |
299 |
} |
300 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
301 |
|
302 |
layers.add(i,layer); |
303 |
layer.setParentLayer(this);
|
304 |
|
305 |
callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer)); |
306 |
break;
|
307 |
} |
308 |
} |
309 |
} |
310 |
|
311 |
|
312 |
/**
|
313 |
* Obtiene el array de capas visibles que penden del arbol cuya ra?z es
|
314 |
* este nodo
|
315 |
*
|
316 |
* @return Vector de FLayer.
|
317 |
*/
|
318 |
public FLayer[] getVisibles() { |
319 |
ArrayList array = new ArrayList(); |
320 |
LayersIterator iter = new LayersIterator(this) { |
321 |
public boolean evaluate(FLayer layer) { |
322 |
return layer.isVisible();
|
323 |
} |
324 |
|
325 |
}; |
326 |
|
327 |
while (iter.hasNext()) {
|
328 |
array.add(iter.nextLayer()); |
329 |
} |
330 |
|
331 |
return (FLayer[]) array.toArray(new FLayer[0]); |
332 |
} |
333 |
|
334 |
/**
|
335 |
* Obtiene el hijo i-?simo (de abajo a arriba) directo de esta colecci?n.
|
336 |
*
|
337 |
* @param index ?ndice.
|
338 |
*
|
339 |
* @return capa seleccionada.
|
340 |
*/
|
341 |
public FLayer getLayer(int index) { |
342 |
return (FLayer) layers.get(index);
|
343 |
} |
344 |
|
345 |
/**
|
346 |
* M?todo de conveniencia para buscar una capa por su nombre Es conveniente
|
347 |
* usar getLayer(int) siempre que se pueda, es m?s directo.
|
348 |
*
|
349 |
* @param layerName nombre.
|
350 |
*
|
351 |
* @return capa seleccionada.
|
352 |
*/
|
353 |
public FLayer getLayer(String layerName) { |
354 |
FLayer lyr; |
355 |
FLayer lyr2; |
356 |
ArrayList layerList;
|
357 |
|
358 |
for (int i = 0; i < layers.size(); i++) { |
359 |
lyr = ((FLayer) layers.get(i)); |
360 |
|
361 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
362 |
return lyr;
|
363 |
} |
364 |
|
365 |
layerList = new ArrayList(); |
366 |
splitLayerGroup(lyr,layerList); |
367 |
for(int j = 0; j<layerList.size(); j++ ) |
368 |
{ |
369 |
lyr2 = ((FLayer)layerList.get(j)); |
370 |
if (lyr2.getName().compareToIgnoreCase(layerName) == 0) { |
371 |
return lyr2;
|
372 |
} |
373 |
} |
374 |
} |
375 |
|
376 |
return null; |
377 |
} |
378 |
|
379 |
// added by Laura
|
380 |
// this is to to split up a layer group in order to get a layer by name
|
381 |
// when there are layergroups.
|
382 |
private void splitLayerGroup(FLayer layer, ArrayList result) |
383 |
{ |
384 |
int i;
|
385 |
FLayers layerGroup; |
386 |
if (layer instanceof FLayers) |
387 |
{ |
388 |
layerGroup = (FLayers)layer; |
389 |
for (i=0; i < layerGroup.getLayersCount(); i++ ) |
390 |
{ |
391 |
splitLayerGroup(layerGroup.getLayer(i),result); |
392 |
} |
393 |
} |
394 |
else
|
395 |
{ |
396 |
result.add(layer); |
397 |
} |
398 |
} |
399 |
|
400 |
/**
|
401 |
* Obtiene el n?mero de capas que hay en su mismo nivel Es decir, no cuenta
|
402 |
* las subcapas de un FLayers
|
403 |
*
|
404 |
* @return n?mero de capas.
|
405 |
*/
|
406 |
public int getLayersCount() { |
407 |
return layers.size();
|
408 |
} |
409 |
|
410 |
/**
|
411 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
412 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
413 |
*/
|
414 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
415 |
Cancellable cancel,double scale) throws ReadDriverException { |
416 |
//double scale = getFMap().getScaleView();
|
417 |
// Iterator iter = layers.iterator();
|
418 |
// try
|
419 |
// {
|
420 |
boolean bNeedRecalculateCache = false; |
421 |
// while (iter.hasNext())
|
422 |
// {
|
423 |
for (int i=0; i < layers.size(); i++) { |
424 |
if (cancel.isCanceled())
|
425 |
break; // M?s que nada porque las capas raster no son interrumpibles por ahora. |
426 |
// FLayer lyr = (FLayer) iter.next();
|
427 |
FLayer lyr = (FLayer) layers.get(i); |
428 |
/* if (lyr instanceof FLyrVect && ((FLyrVect)lyr).isBroken()){
|
429 |
continue;
|
430 |
}
|
431 |
*/
|
432 |
LayerDrawEvent beforeEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW);
|
433 |
fmap.fireLayerDrawingEvent(beforeEvent); |
434 |
if ((lyr.isDirty()) || (lyr.isCachingDrawnLayers() == false)) |
435 |
bNeedRecalculateCache = true;
|
436 |
|
437 |
if (lyr.isVisible()) {
|
438 |
|
439 |
long t1 = System.currentTimeMillis(); |
440 |
System.err.println("Layer " + lyr.getName() + " dirty=" + lyr.isDirty()); |
441 |
// synchronized (this) {
|
442 |
//Sincronizaci?n del m?todo dibujar de cada Layer, esto es posible hacerlo de otra forma,
|
443 |
//pero de momento se queda as?, para solucionar el refresco de una misma vista que est? a?adida en el Layout.
|
444 |
try{
|
445 |
/* if (lyr instanceof IComposedDrawing)
|
446 |
{
|
447 |
// Acumulamos las peticiones hasta que sea
|
448 |
// otro servidor o otro tipo de capa o la ?ltima
|
449 |
// Si hay que dibujar:
|
450 |
lyr.draw(image, g, viewPort, cancel,scale);
|
451 |
// Si hay que acumlar:
|
452 |
lyr.acumulateDrawing(antLayer);
|
453 |
|
454 |
}
|
455 |
else */
|
456 |
|
457 |
if (lyr.isCachingDrawnLayers())
|
458 |
{ |
459 |
if ((bNeedRecalculateCache) || (lyr.getCacheImageDrawnLayers()==null)) |
460 |
{ |
461 |
//if (bNeedRecalculateCache)
|
462 |
// {
|
463 |
// Copiamos la imagen actual
|
464 |
BufferedImage buff = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
465 |
WritableRaster w = buff.getRaster();
|
466 |
image.copyData(w); |
467 |
lyr.setCacheImageDrawnLayers(buff); |
468 |
System.err.println("RECALCULO LA CACHE CON LO QUE HABIA ANTES DE " + lyr.getName()); |
469 |
} |
470 |
// }
|
471 |
// else
|
472 |
// {
|
473 |
if (lyr.getCacheImageDrawnLayers() != null) |
474 |
{ |
475 |
// Previo a esto hemos tenido que fijar
|
476 |
// la imagen que queremos usar, en el
|
477 |
// prepareDrawing de FMap.
|
478 |
if (lyr.isDirty())
|
479 |
{ |
480 |
g.drawImage(lyr.getCacheImageDrawnLayers(), 0, 0, null); |
481 |
System.err.println("Pinto con acelerado lo que hab?a antes de " + lyr.getName()); |
482 |
} |
483 |
} |
484 |
// }
|
485 |
} |
486 |
// Si la capa est? "sucia" o alguna de las de abajo est? sucia
|
487 |
// hay que volver a dibujar.
|
488 |
if (lyr.isDirty() || bNeedRecalculateCache)
|
489 |
{ |
490 |
lyr.draw(image, g, viewPort, cancel,scale); |
491 |
|
492 |
/*
|
493 |
* (Jaume)
|
494 |
* If the layer is instance of ILabelable then it may have labels.
|
495 |
*/
|
496 |
if (lyr instanceof ILabelable && ((ILabelable) lyr).isLabeled()) { |
497 |
((ILabelable) lyr).drawLabels(image, g, viewPort, cancel, scale); |
498 |
} |
499 |
bNeedRecalculateCache = true;
|
500 |
} |
501 |
} catch (ReadDriverException e){
|
502 |
// fmap.callNewErrorEvent(new ErrorEvent(lyr.getName(), e));
|
503 |
fmap.addLayerError("La capa " + lyr.getName() + " es err?nea."); |
504 |
lyr.addError(e); |
505 |
e.printStackTrace(); |
506 |
lyr.setAvailable(false);
|
507 |
// this.removeLayer(lyr);
|
508 |
} catch (Exception e) { |
509 |
fmap.addLayerError("La capa " + lyr.getName() + " es err?nea."); |
510 |
e.printStackTrace(); |
511 |
lyr.setAvailable(false);
|
512 |
} |
513 |
// }
|
514 |
long t2 = System.currentTimeMillis(); |
515 |
System.out.println("Layer " + lyr.getName() + " " |
516 |
+ (t2-t1) + " milisecs.");
|
517 |
lyr.setDirty(false);
|
518 |
} |
519 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
|
520 |
fmap.fireLayerDrawingEvent(afterEvent); |
521 |
|
522 |
} |
523 |
if (getVirtualLayers() != null) { |
524 |
getVirtualLayers().draw(image, g, viewPort, cancel,scale); |
525 |
} |
526 |
// }
|
527 |
// catch (ConcurrentModificationException e)
|
528 |
// {
|
529 |
// System.err.println(e.getMessage());
|
530 |
// }
|
531 |
} |
532 |
|
533 |
/**
|
534 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
535 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
536 |
* com.iver.utiles.swing.threads.Cancellable)
|
537 |
*/
|
538 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) |
539 |
throws ReadDriverException {
|
540 |
|
541 |
// TODO: A la hora de imprimir, isWithinScale falla, porque est?
|
542 |
// calculando la escala en pantalla, no para el layout.
|
543 |
// Revisar esto.
|
544 |
for (int i=0; i < layers.size(); i++) { |
545 |
FLayer lyr = (FLayer) layers.get(i); |
546 |
lyr.print(g, viewPort, cancel, scale, properties); |
547 |
|
548 |
} |
549 |
if (getVirtualLayers() != null) { |
550 |
getVirtualLayers().print( g, viewPort, cancel,scale, properties); |
551 |
} |
552 |
} |
553 |
|
554 |
/**
|
555 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
556 |
*/
|
557 |
public Rectangle2D getFullExtent() { |
558 |
Rectangle2D rAux = null; |
559 |
boolean first = true; |
560 |
|
561 |
|
562 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
563 |
FLayer capa = (FLayer) iter.next(); |
564 |
try{
|
565 |
if (first) {
|
566 |
rAux = capa.getFullExtent(); |
567 |
first=false;
|
568 |
} else {
|
569 |
rAux.add(capa.getFullExtent()); |
570 |
} |
571 |
}catch (Exception e) { |
572 |
e.printStackTrace();//TODO hay que revisar para determinar el comportamiento que espera el usuario.
|
573 |
} |
574 |
} |
575 |
|
576 |
return rAux;
|
577 |
} |
578 |
|
579 |
/**
|
580 |
* Llama al m?todo layerAdding de los listeners dados de alta.
|
581 |
*
|
582 |
* @param event
|
583 |
*
|
584 |
* @throws CancelationException
|
585 |
*/
|
586 |
protected void callLayerAdding(LayerCollectionEvent event) |
587 |
throws CancelationException {
|
588 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
589 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
590 |
((LayerCollectionListener) iter.next()).layerAdding(event); |
591 |
} |
592 |
} |
593 |
|
594 |
/**
|
595 |
* Llama al m?todo layerRemoving de los listeners dados de alta.
|
596 |
*
|
597 |
* @param event
|
598 |
*
|
599 |
* @throws CancelationException
|
600 |
*/
|
601 |
protected void callLayerRemoving(LayerCollectionEvent event) |
602 |
throws CancelationException {
|
603 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
604 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
605 |
((LayerCollectionListener) iter.next()).layerRemoving(event); |
606 |
} |
607 |
} |
608 |
|
609 |
|
610 |
/**
|
611 |
* Llama al m?todo layerMoving de los listeners dados de alta.
|
612 |
*
|
613 |
* @param event
|
614 |
*
|
615 |
* @throws CancelationException
|
616 |
*/
|
617 |
protected void callLayerMoving(LayerPositionEvent event) |
618 |
throws CancelationException {
|
619 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
620 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
621 |
((LayerCollectionListener) iter.next()).layerMoving(event); |
622 |
} |
623 |
} |
624 |
|
625 |
/**
|
626 |
* Llama al m?todo layerAdded de los listeners dados de alta.
|
627 |
*
|
628 |
* @param event
|
629 |
*/
|
630 |
protected void callLayerAdded(LayerCollectionEvent event) { |
631 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
632 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
633 |
((LayerCollectionListener) iter.next()).layerAdded(event); |
634 |
} |
635 |
} |
636 |
|
637 |
/**
|
638 |
* Llama al m?todo layerRemoved de los listeners dados de alta.
|
639 |
*
|
640 |
* @param event
|
641 |
*/
|
642 |
protected void callLayerRemoved(LayerCollectionEvent event) { |
643 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
644 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
645 |
((LayerCollectionListener) iter.next()).layerRemoved(event); |
646 |
} |
647 |
} |
648 |
|
649 |
/**
|
650 |
* Llama al m?todo layerMoved de los listeners dados de alta.
|
651 |
*
|
652 |
* @param event
|
653 |
*/
|
654 |
protected void callLayerMoved(LayerPositionEvent event) { |
655 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
656 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
657 |
((LayerCollectionListener) iter.next()).layerMoved(event); |
658 |
} |
659 |
} |
660 |
|
661 |
/**
|
662 |
* @throws XMLException
|
663 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
664 |
*/
|
665 |
public XMLEntity getXMLEntity() throws XMLException { |
666 |
XMLEntity xml = super.getXMLEntity();
|
667 |
xml.putProperty("numLayers", layers.size());
|
668 |
|
669 |
String[] s = new String[layers.size()]; |
670 |
|
671 |
for (int i = 0; i < layers.size(); i++) { |
672 |
s[i] = ((FLayer) layers.get(i)).getName(); |
673 |
} |
674 |
|
675 |
xml.putProperty("LayerNames", s);
|
676 |
|
677 |
for (int i = 0; i < layers.size(); i++) { |
678 |
xml.addChild(((FLayer) layers.get(i)).getXMLEntity()); |
679 |
} |
680 |
|
681 |
return xml;
|
682 |
} |
683 |
|
684 |
/**
|
685 |
* DOCUMENT ME!
|
686 |
*
|
687 |
* @param xml DOCUMENT ME!
|
688 |
*
|
689 |
* @throws XMLException
|
690 |
*
|
691 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
692 |
*/
|
693 |
public void setXMLEntity03(XMLEntity xml) throws XMLException{ |
694 |
super.setXMLEntity03(xml);
|
695 |
int numLayers = xml.getIntProperty("numLayers"); |
696 |
|
697 |
String[] s = xml.getStringArrayProperty("LayerNames"); |
698 |
try {
|
699 |
for (int i = 0; i < numLayers; i++) { |
700 |
FLayer layer = null;
|
701 |
|
702 |
String className = xml.getChild(i).getStringProperty("className"); |
703 |
|
704 |
if (className.equals(FLyrVect.class.getName())) {
|
705 |
if (xml.getChild(i).contains("file")) { |
706 |
|
707 |
layer = LayerFactory.createLayer(s[i], |
708 |
(VectorialFileDriver)LayerFactory.getDM().getDriver(xml.getChild(i).getStringProperty("driverName")),
|
709 |
new File(xml.getChild(i).getStringProperty("file")), |
710 |
this.getMapContext().getViewPort().getProjection());
|
711 |
|
712 |
} else if (true) { |
713 |
//TODO falta por implementar
|
714 |
} else if (true) { |
715 |
//TODO falta por implementar
|
716 |
} |
717 |
|
718 |
layer.setXMLEntity03(xml.getChild(i)); |
719 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
720 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
721 |
IProjection proj = layer.getProjection(); |
722 |
if (proj != null) |
723 |
if (proj != fmap.getProjection())
|
724 |
{ |
725 |
ICoordTrans ct = proj.getCT(fmap.getProjection()); |
726 |
layer.setCoordTrans(ct); |
727 |
System.err.println("coordTrans = " + |
728 |
proj.getAbrev() + " " +
|
729 |
fmap.getProjection().getAbrev()); |
730 |
} |
731 |
|
732 |
// } else if (className.equals(FLyrWMS.class.getName())) {
|
733 |
// try {
|
734 |
// layer = LayerFactory.createLayer(s[i],
|
735 |
// StringUtilities.string2Rect(
|
736 |
// xml.getChild(i).getStringProperty("fullExtent")),
|
737 |
// new URL(xml.getChild(i).getStringProperty("host")),
|
738 |
// xml.getChild(i).getStringProperty("format"),
|
739 |
// xml.getChild(i).getStringProperty("layerQuery"),
|
740 |
// xml.getChild(i).getStringProperty("infoLayerQuery"),
|
741 |
// xml.getChild(i).getStringProperty("srs"));
|
742 |
// } catch (MalformedURLException e) {
|
743 |
// throw new XMLException(e);
|
744 |
// }
|
745 |
} else if (className.equals((FLyrRaster.class.getName()))) { |
746 |
//if (xml.getChild(i).contains("file")) {
|
747 |
/*layer = LayerFactory.createLayer(s[i],
|
748 |
xml.getChild(i).getStringProperty("driverName"),
|
749 |
new File(xml.getChild(i).getStringProperty("file")),
|
750 |
this.getFMap().getViewPort().getProjection());*/
|
751 |
layer = new FLyrRaster();
|
752 |
layer.setName(s[i]); |
753 |
if (!xml.getChild(i).contains("proj")) |
754 |
((FLyrRaster)layer).setProjection(this.getMapContext().getViewPort().getProjection());
|
755 |
layer.setXMLEntity03(xml.getChild(i)); |
756 |
layer.load(); |
757 |
|
758 |
}else if (className.equals((FLayers.class.getName()))) { |
759 |
layer = new FLayers(getMapContext(),this); |
760 |
layer.setXMLEntity(xml.getChild(i)); |
761 |
} else {
|
762 |
// Capas Nuevas (externas)
|
763 |
try {
|
764 |
Class clase = Class.forName(className); |
765 |
layer = (FLayer) clase.newInstance(); |
766 |
layer.setName(s[i]); |
767 |
layer.setXMLEntity03(xml.getChild(i)); |
768 |
layer.load(); |
769 |
} catch (Exception e) { |
770 |
//e.printStackTrace();
|
771 |
throw new XMLException(e); |
772 |
} |
773 |
} |
774 |
|
775 |
this.addLayer(layer);
|
776 |
} |
777 |
} /*azabala-modificaciones en layerfactory-
|
778 |
catch (DriverException e) {
|
779 |
throw new XMLException(e);
|
780 |
}*/
|
781 |
catch (DriverLoadException e) {
|
782 |
throw new XMLException(e); |
783 |
} catch (LoadLayerException e) {
|
784 |
throw new XMLException(e); |
785 |
} |
786 |
|
787 |
} |
788 |
|
789 |
/**
|
790 |
* DOCUMENT ME!
|
791 |
*
|
792 |
* @param xml DOCUMENT ME!
|
793 |
*
|
794 |
* @throws XMLException
|
795 |
*
|
796 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
797 |
*/
|
798 |
public void setXMLEntity(XMLEntity xml) throws XMLException{ |
799 |
super.setXMLEntity(xml);
|
800 |
//LoadLayerException loadLayerException=new LoadLayerException();
|
801 |
int numLayers = xml.getIntProperty("numLayers"); |
802 |
|
803 |
String[] s = xml.getStringArrayProperty("LayerNames"); |
804 |
// try {
|
805 |
fmap.clearErrors(); |
806 |
for (int i = 0; i < numLayers; i++) { |
807 |
try {
|
808 |
this.addLayerFromXML(xml.getChild(i),s[i]);
|
809 |
} catch (LoadLayerException e) {
|
810 |
throw new XMLException(e); |
811 |
} |
812 |
|
813 |
|
814 |
} |
815 |
/* } catch (DriverException e) {
|
816 |
throw new XMLException(e);
|
817 |
} */
|
818 |
/*if (loadLayerException.getExceptions().size()>0){
|
819 |
throw loadLayerException;
|
820 |
}*/
|
821 |
} |
822 |
|
823 |
/**
|
824 |
* @throws ExpansionFileReadException
|
825 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
826 |
* FBitSet)
|
827 |
*/
|
828 |
public void process(FeatureVisitor visitor, FBitSet subset) |
829 |
throws ReadDriverException, ExpansionFileReadException, VisitorException {
|
830 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
831 |
FLayer layer = (FLayer) iter.next(); |
832 |
|
833 |
if (layer instanceof VectorialData) { |
834 |
((VectorialData) layer).process(visitor, subset); |
835 |
} |
836 |
} |
837 |
} |
838 |
|
839 |
/**
|
840 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
841 |
*/
|
842 |
public void process(FeatureVisitor visitor) |
843 |
throws ReadDriverException, VisitorException {
|
844 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
845 |
FLayer layer = (FLayer) iter.next(); |
846 |
|
847 |
if (layer instanceof FLayers){ |
848 |
FLayers lyrs=(FLayers)layer; |
849 |
for (int i=0;i<lyrs.getLayersCount();i++){ |
850 |
FLayer lyr=lyrs.getLayer(i); |
851 |
if (lyr.isActive()) {
|
852 |
if (lyr instanceof VectorialData) { |
853 |
((VectorialData) lyr).process(visitor); |
854 |
} |
855 |
} |
856 |
} |
857 |
} |
858 |
if (layer.isActive()) {
|
859 |
if (layer instanceof VectorialData) { |
860 |
((VectorialData) layer).process(visitor); |
861 |
} |
862 |
} |
863 |
} |
864 |
} |
865 |
/**
|
866 |
* @throws ExpansionFileReadException
|
867 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor, Rectangle2D)
|
868 |
*/
|
869 |
public void process(FeatureVisitor visitor, Rectangle2D rect) throws ReadDriverException, ExpansionFileReadException, VisitorException { |
870 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
871 |
FLayer layer = (FLayer) iter.next(); |
872 |
|
873 |
if (layer.isActive()) {
|
874 |
if (layer instanceof VectorialData) { |
875 |
((VectorialData) layer).process(visitor, rect); |
876 |
} |
877 |
} |
878 |
} |
879 |
|
880 |
} |
881 |
|
882 |
/**
|
883 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
|
884 |
*/
|
885 |
public MapContext getMapContext() {
|
886 |
return fmap;
|
887 |
} |
888 |
|
889 |
/* (non-Javadoc)
|
890 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setCoordTrans(org.cresques.cts.ICoordTrans)
|
891 |
*/
|
892 |
public void setCoordTrans(ICoordTrans ct) { |
893 |
super.setCoordTrans(ct);
|
894 |
|
895 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
896 |
FLayer layer = (FLayer) iter.next(); |
897 |
layer.setCoordTrans(ct); |
898 |
} |
899 |
} |
900 |
|
901 |
/**
|
902 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllActives(boolean)
|
903 |
*/
|
904 |
public void setAllActives(boolean active) { |
905 |
FLayer lyr; |
906 |
|
907 |
for (int i = 0; i < layers.size(); i++) { |
908 |
lyr = ((FLayer) layers.get(i)); |
909 |
lyr.setActive(active); |
910 |
|
911 |
if (lyr instanceof LayerCollection) { |
912 |
((LayerCollection) lyr).setAllActives(active); |
913 |
} |
914 |
} |
915 |
} |
916 |
|
917 |
/**
|
918 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getActives()
|
919 |
*/
|
920 |
public FLayer[] getActives() { |
921 |
ArrayList ret = new ArrayList(); |
922 |
LayersIterator it = new LayersIterator(this) { |
923 |
|
924 |
public boolean evaluate(FLayer layer) { |
925 |
return layer.isActive();
|
926 |
} |
927 |
|
928 |
}; |
929 |
|
930 |
while (it.hasNext())
|
931 |
{ |
932 |
ret.add(it.next()); |
933 |
} |
934 |
return (FLayer[]) ret.toArray(new FLayer[0]); |
935 |
} |
936 |
|
937 |
/* (non-Javadoc)
|
938 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMinScale()
|
939 |
*/
|
940 |
public double getMinScale() { |
941 |
return -1; // La visibilidad o no la controla cada capa |
942 |
// dentro de una colecci?n
|
943 |
} |
944 |
|
945 |
/* (non-Javadoc)
|
946 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
|
947 |
*/
|
948 |
public double getMaxScale() { |
949 |
return -1; |
950 |
} |
951 |
public void setMinScale(double minScale) |
952 |
{ |
953 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
954 |
FLayer lyr = (FLayer) iter.next(); |
955 |
lyr.setMinScale(minScale); |
956 |
} |
957 |
} |
958 |
public void setMaxScale(double maxScale) |
959 |
{ |
960 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
961 |
FLayer lyr = (FLayer) iter.next(); |
962 |
lyr.setMinScale(maxScale); |
963 |
} |
964 |
} |
965 |
public void setActive(boolean b){ |
966 |
super.setActive(b);
|
967 |
for (int i=0;i<layers.size();i++){ |
968 |
((FLayer)layers.get(i)).setActive(b); |
969 |
} |
970 |
} |
971 |
|
972 |
/* (non-Javadoc)
|
973 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
|
974 |
*/
|
975 |
public boolean addLayerListener(LayerListener o) { |
976 |
for (int i = 0; i < layers.size(); i++) |
977 |
((FLayer) layers.get(i)).addLayerListener(o); |
978 |
return true; |
979 |
} |
980 |
|
981 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException, LoadLayerException { |
982 |
int i;
|
983 |
Vector items = new Vector(); |
984 |
FLayer layer; |
985 |
XMLItem[] aux;
|
986 |
for (i = 0; i < this.layers.size(); i++){ |
987 |
layer = (FLayer)layers.get(i); |
988 |
if (layer instanceof InfoByPoint){ |
989 |
InfoByPoint queryable_layer = (InfoByPoint) layer; |
990 |
aux = queryable_layer.getInfo(p, tolerance, null);
|
991 |
if (!(queryable_layer instanceof FLayers)){ |
992 |
for(int j = 0; j < aux.length; j++){ |
993 |
items.add(aux[j]); |
994 |
} |
995 |
} |
996 |
} |
997 |
} |
998 |
return (XMLItem[])items.toArray(new XMLItem[0]); |
999 |
|
1000 |
// for (i = 0; i < this.layers.size(); i++){
|
1001 |
// FLayer laCapa = (FLayer) layers.get(i);
|
1002 |
// if (laCapa instanceof FLyrVect){
|
1003 |
// }
|
1004 |
// else if (laCapa instanceof RasterOperations) {
|
1005 |
// try {
|
1006 |
// RasterOperations layer = (RasterOperations) laCapa;
|
1007 |
// sb.append(layer.getInfo(p, tolerance));
|
1008 |
// } catch (DriverException e) {
|
1009 |
// e.printStackTrace();
|
1010 |
// }
|
1011 |
// }
|
1012 |
// else if (laCapa instanceof InfoByPoint) {
|
1013 |
// try {
|
1014 |
// InfoByPoint layer = (InfoByPoint) laCapa;
|
1015 |
// sb.append(layer.getInfo(p, tolerance));
|
1016 |
// } catch (DriverException e) {
|
1017 |
// e.printStackTrace();
|
1018 |
// }
|
1019 |
// }
|
1020 |
// }
|
1021 |
|
1022 |
} |
1023 |
|
1024 |
public ImageIcon getTocImageIcon() { |
1025 |
return new ImageIcon(MapControl.class.getResource("images/layerGroup.png")); |
1026 |
} |
1027 |
|
1028 |
public boolean isDirty() { |
1029 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1030 |
FLayer lyr = (FLayer) iter.next(); |
1031 |
if (lyr.isDirty())
|
1032 |
return true; |
1033 |
} |
1034 |
return false; |
1035 |
} |
1036 |
|
1037 |
public void setDirty(boolean dirty) { |
1038 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1039 |
FLayer lyr = (FLayer) iter.next(); |
1040 |
lyr.setDirty(dirty); |
1041 |
} |
1042 |
|
1043 |
} |
1044 |
|
1045 |
public boolean addLayerFromXMLEntity(XMLEntity xml, String name) throws LoadLayerException { |
1046 |
fmap.clearErrors(); |
1047 |
this.addLayerFromXML(xml,name);
|
1048 |
|
1049 |
return (fmap.getLayersError().size() == 0); |
1050 |
|
1051 |
} |
1052 |
|
1053 |
private void addLayerFromXML(XMLEntity xml, String name) throws LoadLayerException { |
1054 |
FLayer layer = null;
|
1055 |
|
1056 |
try {
|
1057 |
if (name == null) name = xml.getName(); |
1058 |
|
1059 |
|
1060 |
String className = xml.getStringProperty("className"); |
1061 |
|
1062 |
if (className.equals(FLyrVect.class.getName())) {
|
1063 |
String type = xml.getStringProperty("type"); |
1064 |
if ("vectorial".equals(type)){ |
1065 |
//String recordsetName = xml.getChild(i).getStringProperty("recordset-name");
|
1066 |
IProjection proj = null;
|
1067 |
if (xml.contains("proj")) { |
1068 |
proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
1069 |
} |
1070 |
else
|
1071 |
{ |
1072 |
proj = this.getMapContext().getViewPort().getProjection();
|
1073 |
} |
1074 |
if (xml.contains("file")) { |
1075 |
Driver d;
|
1076 |
try {
|
1077 |
d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
|
1078 |
} catch (DriverLoadException e1) {
|
1079 |
throw new DriverLayerException(name,e1); |
1080 |
} |
1081 |
layer = LayerFactory.createLayer(name, (VectorialFileDriver) d, |
1082 |
new File(xml.getStringProperty("file")), |
1083 |
proj); |
1084 |
|
1085 |
|
1086 |
} |
1087 |
if (xml.contains("db")) { |
1088 |
|
1089 |
String driverName = xml.getStringProperty("db"); |
1090 |
VectorialDatabaseDriver driver; |
1091 |
try {
|
1092 |
driver = (VectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName); |
1093 |
//Hay que separar la carga de los datos del XMLEntity del load.
|
1094 |
driver.setXMLEntity(xml.getChild(2));
|
1095 |
|
1096 |
boolean loadOk = false; |
1097 |
((DefaultDBDriver)driver).load(); |
1098 |
if (((DefaultDBDriver)driver).getConnection() != null) { |
1099 |
loadOk = true;
|
1100 |
} |
1101 |
layer = LayerFactory.createDBLayer(driver, name, proj); |
1102 |
if (!loadOk) {
|
1103 |
layer.setAvailable(false);
|
1104 |
} |
1105 |
|
1106 |
} catch (DriverLoadException e) {
|
1107 |
throw new DriverLayerException(name,e); |
1108 |
} catch (XMLException e) {
|
1109 |
throw new DriverLayerException(name,e); |
1110 |
} catch (ReadDriverException e) {
|
1111 |
throw new DriverLayerException(name,e); |
1112 |
} |
1113 |
|
1114 |
} |
1115 |
// Clases con algun driver gen?rico creado por otro
|
1116 |
// programador
|
1117 |
if (xml.contains("other")) { |
1118 |
|
1119 |
String driverName = xml.getStringProperty("other"); |
1120 |
VectorialDriver driver = null;
|
1121 |
try {
|
1122 |
driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName); |
1123 |
} catch (DriverLoadException e) {
|
1124 |
// Si no existe ese driver, no pasa nada.
|
1125 |
// Puede que el desarrollador no quiera que
|
1126 |
// aparezca en el cuadro de di?logo y ha metido
|
1127 |
// el jar con sus clases en nuestro directorio lib.
|
1128 |
// Intentamos cargar esa clase "a pelo".
|
1129 |
if (xml.getChild(2).contains("className")) |
1130 |
{ |
1131 |
String className2 = xml.getChild(2).getStringProperty("className"); |
1132 |
try {
|
1133 |
driver = (VectorialDriver) Class.forName(className2).newInstance();
|
1134 |
} catch (Exception e1) { |
1135 |
throw new DriverLayerException(name,e); |
1136 |
} |
1137 |
} |
1138 |
} catch (NullPointerException npe) { |
1139 |
// Si no existe ese driver, no pasa nada.
|
1140 |
// Puede que el desarrollador no quiera que
|
1141 |
// aparezca en el cuadro de di?logo y ha metido
|
1142 |
// el jar con sus clases en nuestro directorio lib.
|
1143 |
// Intentamos cargar esa clase "a pelo".
|
1144 |
if (xml.getChild(2).contains("className")) |
1145 |
{ |
1146 |
String className2 = xml.getChild(2).getStringProperty("className"); |
1147 |
try {
|
1148 |
driver = (VectorialDriver) Class.forName(className2).newInstance();
|
1149 |
} catch (Exception e1) { |
1150 |
throw new DriverLayerException(name,e1); |
1151 |
} |
1152 |
} |
1153 |
} |
1154 |
if (driver instanceof IPersistance) |
1155 |
{ |
1156 |
IPersistance persist = (IPersistance) driver; |
1157 |
persist.setXMLEntity(xml.getChild(2));
|
1158 |
} |
1159 |
layer = LayerFactory.createLayer(name, driver, proj); |
1160 |
} |
1161 |
|
1162 |
|
1163 |
} else if ("raster".equals(type)) { |
1164 |
/* if (xml.getChild(i).contains("file")) {
|
1165 |
Driver d = LayerFactory.getDM().getDriver(xml.getChild(i).getStringProperty("driverName"));
|
1166 |
layer = LayerFactory.createLayer(s[i],
|
1167 |
,
|
1168 |
new File(xml.getChild(i).getStringProperty("file")),
|
1169 |
this.getFMap().getViewPort().getProjection());
|
1170 |
|
1171 |
}
|
1172 |
*/ }
|
1173 |
|
1174 |
layer.setXMLEntity(xml); |
1175 |
|
1176 |
// } else if (className.equals(FLyrWMS.class.getName())) {
|
1177 |
// try {
|
1178 |
// layer = LayerFactory.createLayer(s[i],
|
1179 |
// StringUtilities.string2Rect(
|
1180 |
// xml.getChild(i).getStringProperty("fullExtent")),
|
1181 |
// new URL(xml.getChild(i).getStringProperty("host")),
|
1182 |
// xml.getChild(i).getStringProperty("format"),
|
1183 |
// xml.getChild(i).getStringProperty("layerQuery"),
|
1184 |
// xml.getChild(i).getStringProperty("infoLayerQuery"),
|
1185 |
// xml.getChild(i).getStringProperty("srs"));
|
1186 |
// layer.setXMLEntity(xml.getChild(i));
|
1187 |
// } catch (MalformedURLException e) {
|
1188 |
// throw new XMLException(e);
|
1189 |
// }
|
1190 |
} else if (className.equals((FLyrRaster.class.getName()))) { |
1191 |
//if (xml.getChild(i).contains("file")) {
|
1192 |
/*layer = LayerFactory.createLayer(s[i],
|
1193 |
xml.getChild(i).getStringProperty("driverName"),
|
1194 |
new File(xml.getChild(i).getStringProperty("file")),
|
1195 |
this.getFMap().getViewPort().getProjection());*/
|
1196 |
layer = new FLyrRaster();
|
1197 |
layer.setName(name); |
1198 |
if (!xml.contains("proj")) |
1199 |
((FLyrRaster)layer).setProjection(this.getMapContext().getViewPort().getProjection());
|
1200 |
layer.setXMLEntity(xml); |
1201 |
layer.load(); |
1202 |
|
1203 |
}else if (className.equals((FLayers.class.getName()))) { |
1204 |
layer = new FLayers(getMapContext(),this); |
1205 |
layer.setXMLEntity(xml); |
1206 |
} else {
|
1207 |
// Capas Nuevas (externas)
|
1208 |
Class clase = Class.forName(className); |
1209 |
layer = (FLayer) clase.newInstance(); |
1210 |
layer.setName(name); |
1211 |
layer.setXMLEntity(xml); |
1212 |
layer.load(); |
1213 |
} |
1214 |
|
1215 |
this.addLayer(layer);
|
1216 |
logger.debug("layer: "+ layer.getName() +" loaded"); |
1217 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
1218 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
1219 |
IProjection proj = layer.getProjection(); |
1220 |
if ((proj != null)) |
1221 |
if (proj != getMapContext().getProjection())
|
1222 |
{ |
1223 |
ICoordTrans ct = proj.getCT(getMapContext().getProjection()); |
1224 |
// TODO: REVISAR CON LUIS
|
1225 |
// Se lo fijamos a todas, luego cada una que se reproyecte
|
1226 |
// si puede, o que no haga nada
|
1227 |
layer.setCoordTrans(ct); |
1228 |
// NOTA: DESPU?S DE ESTO DEBER?AMOS CREAR LAS ETIQUETAS
|
1229 |
// SI ES NECESARIO.
|
1230 |
// TODO: REVISAR A FONDO ESTO, PORQUE LAS ETIQUETAS SE CREAN
|
1231 |
// 2 VECES SI HAY REPROYECC?N
|
1232 |
if (layer instanceof FLyrVect) |
1233 |
{ |
1234 |
FLyrVect lyrVect = (FLyrVect)layer; |
1235 |
VectorialLegend legend = (VectorialLegend) lyrVect.getLegend(); |
1236 |
if (legend.getLabelField() != null) { |
1237 |
lyrVect.createLabelLayer(lyrVect.getRecordset()); |
1238 |
} |
1239 |
|
1240 |
} |
1241 |
} |
1242 |
// }catch (LoadLayerException e) {
|
1243 |
// fmap.addLayerError(xml.getStringProperty("name"));
|
1244 |
// //loadLayerException.addException(e);
|
1245 |
// /*if (layer!=null){
|
1246 |
// layer.setActive(false);
|
1247 |
// layer.setVisible(false);
|
1248 |
// this.addLayer(layer);
|
1249 |
// }*/
|
1250 |
// //throw new XMLException(e);
|
1251 |
// System.err.println("No se ha podido cargar la capa : "+xml.getStringProperty("name"));
|
1252 |
// logger.debug("No se ha podido cargar la capa : "+xml.getStringProperty("name") + ". Raz?n:");
|
1253 |
// // logger.debug(e.fillInStackTrace());
|
1254 |
// e.printStackTrace();
|
1255 |
} catch (XMLException e) {
|
1256 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1257 |
throw new LoadLayerException(name,e); |
1258 |
} catch (ClassNotFoundException e) { |
1259 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1260 |
throw new LoadLayerException(name,e); |
1261 |
} catch (InstantiationException e) { |
1262 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1263 |
throw new LoadLayerException(name,e); |
1264 |
} catch (IllegalAccessException e) { |
1265 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1266 |
throw new LoadLayerException(name,e); |
1267 |
} catch (ReadDriverException e) {
|
1268 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1269 |
throw new LoadLayerException(name,e); |
1270 |
} catch (LoadLayerException e){
|
1271 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1272 |
throw e;
|
1273 |
} |
1274 |
} |
1275 |
|
1276 |
private void addLayerFromXMLNew(XMLEntity xml, String name) { |
1277 |
FLayer layer = null;
|
1278 |
|
1279 |
|
1280 |
try {
|
1281 |
String className = xml.getStringProperty("className"); |
1282 |
|
1283 |
if (className.equals((FLayers.class.getName()))){
|
1284 |
layer = new FLayers(getMapContext(),this); |
1285 |
} else {
|
1286 |
// Por compatibilidad
|
1287 |
if (className.equals(FLyrVect.class.getName())) {
|
1288 |
if (xml.contains("file")) { |
1289 |
layer = new FLayerFileVectorial();
|
1290 |
} else if (xml.contains("db")) { |
1291 |
try {
|
1292 |
layer = (FLayer)((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial"); |
1293 |
} catch (Exception e) { |
1294 |
throw new XMLException(new Exception("No se tiene registrada la capa de tipo JDBC")); |
1295 |
} |
1296 |
//className = FLayerJDBCVectorial.class.getName();
|
1297 |
} else if (xml.contains("other")){ |
1298 |
layer = new FLayerGenericVectorial();
|
1299 |
} else {
|
1300 |
throw new XMLException(new Exception("Capa vectorial de tipo no reconocido")); |
1301 |
} |
1302 |
// Fin por compatibilidad
|
1303 |
} else {
|
1304 |
try {
|
1305 |
layer = (FLayer)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create(className));
|
1306 |
} catch (Exception e) { |
1307 |
//puende que no este registrada como punto de extension
|
1308 |
Class clase = Class.forName(className); |
1309 |
layer = (FLayer) clase.newInstance(); |
1310 |
// FIXME: Hacemos algo aqui o dejamos que suba el error?
|
1311 |
} |
1312 |
} |
1313 |
|
1314 |
} |
1315 |
layer.setXMLEntity(xml); |
1316 |
if (name != null) layer.setName(name); |
1317 |
layer.load(); |
1318 |
|
1319 |
this.addLayer(layer);
|
1320 |
logger.debug("layer: "+ layer.getName() +" loaded"); |
1321 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
1322 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
1323 |
IProjection proj = layer.getProjection(); |
1324 |
if ((proj != null)) |
1325 |
if (proj != getMapContext().getProjection())
|
1326 |
{ |
1327 |
ICoordTrans ct = proj.getCT(getMapContext().getProjection()); |
1328 |
// TODO: REVISAR CON LUIS
|
1329 |
// Se lo fijamos a todas, luego cada una que se reproyecte
|
1330 |
// si puede, o que no haga nada
|
1331 |
layer.setCoordTrans(ct); |
1332 |
// NOTA: DESPU?S DE ESTO DEBER?AMOS CREAR LAS ETIQUETAS
|
1333 |
// SI ES NECESARIO.
|
1334 |
// TODO: REVISAR A FONDO ESTO, PORQUE LAS ETIQUETAS SE CREAN
|
1335 |
// 2 VECES SI HAY REPROYECC?N
|
1336 |
if (layer instanceof FLyrVect) |
1337 |
{ |
1338 |
FLyrVect lyrVect = (FLyrVect)layer; |
1339 |
VectorialLegend legend = (VectorialLegend) lyrVect.getLegend(); |
1340 |
if (legend.getLabelField() != null) { |
1341 |
lyrVect.createLabelLayer(lyrVect.getRecordset()); |
1342 |
} |
1343 |
|
1344 |
} |
1345 |
} |
1346 |
}catch (Exception e) { |
1347 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1348 |
//loadLayerException.addException(e);
|
1349 |
/*if (layer!=null){
|
1350 |
layer.setActive(false);
|
1351 |
layer.setVisible(false);
|
1352 |
this.addLayer(layer);
|
1353 |
}*/
|
1354 |
//throw new XMLException(e);
|
1355 |
System.err.println("No se ha podido cargar la capa : "+xml.getStringProperty("name")); |
1356 |
logger.debug("No se ha podido cargar la capa : "+xml.getStringProperty("name") + ". Raz?n:"); |
1357 |
// logger.debug(e.fillInStackTrace());
|
1358 |
e.printStackTrace(); |
1359 |
} |
1360 |
} |
1361 |
|
1362 |
} |