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