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