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