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