root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / FMap.java @ 3025
History | View | Annotate | Download (19.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.RenderingHints; |
45 |
import java.awt.Toolkit; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.awt.image.BufferedImage; |
49 |
import java.util.ArrayList; |
50 |
|
51 |
import org.cresques.cts.ICoordTrans; |
52 |
import org.cresques.cts.IProjection; |
53 |
import org.cresques.geo.Projected; |
54 |
|
55 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
56 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
59 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
60 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
61 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
62 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
63 |
import com.iver.cit.gvsig.fmap.layers.LegendListener; |
64 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
65 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
66 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
67 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
68 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
69 |
import com.iver.cit.gvsig.fmap.operations.selection.Record; |
70 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
71 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectByPointVisitor; |
72 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectByRectVisitor; |
73 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor; |
74 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
75 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
76 |
import com.iver.utiles.XMLEntity; |
77 |
|
78 |
|
79 |
/**
|
80 |
* Modelo del mapa.
|
81 |
*
|
82 |
* @author Fernando Gonz?lez Cort?s
|
83 |
*/
|
84 |
public class FMap implements Projected { |
85 |
public static final double[] CHANGEM = { |
86 |
1000, 1, 0.01, 0.001, 1609.344, 0.9144, 0.3048, 0.0254 |
87 |
}; |
88 |
public static final double[] CHANGE = { |
89 |
100000, 100, 1, 0.1, 160934.4, 91.44, 30.48, 2.54 |
90 |
}; |
91 |
public static final int EQUALS = 0; |
92 |
public static final int DISJOINT = 1; |
93 |
public static final int INTERSECTS = 2; |
94 |
public static final int TOUCHES = 3; |
95 |
public static final int CROSSES = 4; |
96 |
public static final int WITHIN = 5; |
97 |
public static final int CONTAINS = 6; |
98 |
public static final int OVERLAPS = 7; |
99 |
private FLayers layers = new FLayers(this, null); |
100 |
private GraphicLayer tracLayer = new GraphicLayer(); |
101 |
private ViewPort viewPort;
|
102 |
//private ArrayList invalidationListeners = new ArrayList();
|
103 |
private ArrayList legendListeners = new ArrayList(); |
104 |
private EventBuffer eventBuffer = new EventBuffer(); |
105 |
private LayerEventListener layerEventListener=null; |
106 |
// public static ResourceBundle myResourceBundle = ResourceBundle.getBundle("FMap");
|
107 |
|
108 |
/**
|
109 |
* Crea un nuevo FMap.
|
110 |
*
|
111 |
* @param vp ViewPort.
|
112 |
*/
|
113 |
public FMap(ViewPort vp) {
|
114 |
this.viewPort = vp;
|
115 |
layerEventListener=new LayerEventListener();
|
116 |
layers.addLayerCollectionListener(layerEventListener); |
117 |
layers.addLayerCollectionListener(eventBuffer); |
118 |
|
119 |
if (viewPort != null) { |
120 |
viewPort.addViewPortListener(eventBuffer); |
121 |
} |
122 |
} |
123 |
|
124 |
/**
|
125 |
* A?ade un LegendListener.
|
126 |
*
|
127 |
* @param listener LegendListener a a?adir.
|
128 |
*/
|
129 |
public void addLayerListener(LegendListener listener) { |
130 |
legendListeners.add(listener); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* M?todo ejecutado cuando hay un cambio de leyenda que se quiera reflejar.
|
135 |
*
|
136 |
* @param e LegendChangedEvent.
|
137 |
*/
|
138 |
public synchronized void callLegendChanged() { |
139 |
for(int i=0;i<legendListeners.size();i++){ |
140 |
((LegendListener)legendListeners.get(i)).legendChanged(null);
|
141 |
} |
142 |
// getLayers().moveTo(0,0);
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Borra un LegendListener.
|
147 |
*
|
148 |
* @param listener LegendListener a borrar.
|
149 |
*/
|
150 |
public void removeLayerListener(LegendListener listener) { |
151 |
legendListeners.remove(listener); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* Devuelve las capas que contiene el mapa.
|
156 |
*
|
157 |
* @return Capas.
|
158 |
*/
|
159 |
public FLayers getLayers() {
|
160 |
return layers;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Dibuja en la imagen que se pasa como par?metro el contenido de las capas
|
165 |
* visibles del mapa y teniendo en cuenta los datos del ViewPort contenido
|
166 |
* en este FMap
|
167 |
*
|
168 |
* @param b Imagen.
|
169 |
*/
|
170 |
public void drawLabels(BufferedImage b) { |
171 |
} |
172 |
|
173 |
/**
|
174 |
* M?todo de conveniencia que se usa provisionalmente para
|
175 |
* solicitar un refresco de todo lo que dependa del
|
176 |
* FMap (MapContext). Esto provocar? un evento de cambio
|
177 |
* de orden de capas que obligar? a redibujar todo lo que
|
178 |
* depende de FMap (TOC, MapControl, FFrameView, etc).
|
179 |
*/
|
180 |
public void invalidate() |
181 |
{ |
182 |
getLayers().moveTo(0,0); |
183 |
} |
184 |
/**
|
185 |
* Imprime el las capas que contiene el FMap sobre el Graphics2D que se
|
186 |
* pasa como par?metro, normalmente es el Graphics de la impresora.
|
187 |
*
|
188 |
* @param g Graphics2D
|
189 |
*
|
190 |
* @throws DriverException
|
191 |
*/
|
192 |
public void print(Graphics2D g,double scale) throws DriverException { |
193 |
RenderingHints renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, |
194 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
195 |
renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); |
196 |
g.setRenderingHints(renderHints); |
197 |
|
198 |
Cancellable cancel = new Cancellable() {
|
199 |
public boolean isCanceled() { |
200 |
return false; |
201 |
} |
202 |
}; |
203 |
layers.print(g, viewPort, cancel ,scale); |
204 |
tracLayer.draw(null, g, viewPort, cancel, scale);
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Crea un nuevo FMap con la informaci?n del ViewPort que se pasa como
|
209 |
* par?metro.
|
210 |
*
|
211 |
* @param vp ViewPort.
|
212 |
*
|
213 |
* @return FMap nuevo.
|
214 |
*/
|
215 |
public FMap createNewFMap(ViewPort vp) {
|
216 |
FMap ret = new FMap(vp);
|
217 |
ret.layers = this.layers;
|
218 |
|
219 |
return ret;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* Crea un nuevo FMap totalmente desligado, se replican las capas y el
|
224 |
* ViewPort
|
225 |
*
|
226 |
* @return FMap clonado.
|
227 |
*
|
228 |
* @throws XMLException
|
229 |
*/
|
230 |
public FMap cloneFMap() throws XMLException { |
231 |
return createFromXML(getXMLEntity());
|
232 |
} |
233 |
|
234 |
/**
|
235 |
* A?ade la capa que se pasa como par?metro al nodo que se pasa como
|
236 |
* parametro y lanza ProjectionMismatchException si no est?n todas las
|
237 |
* capas de este FMap en la misma proyecci?n. Lanza un
|
238 |
* ChildNotAllowedException si la capa no es un FLayers y no permite hijos
|
239 |
*
|
240 |
* @param vectorial DOCUMENT ME!
|
241 |
*/
|
242 |
|
243 |
/* public void addLayer(LayerPath parent, FLayer layer)
|
244 |
throws ProjectionMismatchException, ChildrenNotAllowedException {
|
245 |
layers.addLayer(parent, layer);
|
246 |
}
|
247 |
public void removeLayer(LayerPath parent)throws ChildrenNotAllowedException{
|
248 |
layers.removeLayer(parent);
|
249 |
}
|
250 |
*/
|
251 |
|
252 |
/**
|
253 |
* A?ade una capa al grupo de capas que se sit?a por encima de todas las
|
254 |
* otras capas
|
255 |
*
|
256 |
* @param vectorial FLayer.
|
257 |
*/
|
258 |
public void addToTrackLayer(FLayer vectorial) { |
259 |
} |
260 |
|
261 |
/**
|
262 |
* Devuelve la escala de la vista en pantalla.
|
263 |
*
|
264 |
* @return escala de la vista.
|
265 |
*/
|
266 |
public long getScaleView() { |
267 |
//TODO falta implementar un di?logo para poder especificar el usuario los pixels exactos de su pantalla.
|
268 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
269 |
double dpi = kit.getScreenResolution();
|
270 |
IProjection proj = viewPort.getProjection(); |
271 |
|
272 |
if (viewPort.getImageSize() == null) |
273 |
return -1; |
274 |
|
275 |
double w = ((viewPort.getImageSize().getWidth() / dpi) * 2.54); |
276 |
|
277 |
if (viewPort.getAdjustedExtent() == null) { |
278 |
return 0; |
279 |
} |
280 |
|
281 |
if (proj == null) { |
282 |
return (long) (viewPort.getAdjustedExtent().getWidth() / w * CHANGE[getViewPort() |
283 |
.getMapUnits()]); |
284 |
} |
285 |
|
286 |
return (long) proj.getScale(viewPort.getAdjustedExtent().getMinX(), |
287 |
viewPort.getAdjustedExtent().getMaxX(), |
288 |
viewPort.getImageSize().getWidth(), dpi); |
289 |
} |
290 |
|
291 |
/**
|
292 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#setVectorial(com.iver.cit.gvsig.fmap.VectorialAdapter)
|
293 |
*/
|
294 |
public void setVectorial(VectorialAdapter v) { |
295 |
} |
296 |
|
297 |
/**
|
298 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor)
|
299 |
*/
|
300 |
public void process(FeatureVisitor visitor) { |
301 |
} |
302 |
|
303 |
/**
|
304 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#processSelected(com.iver.cit.gvsig.fmap.FeatureVisitor)
|
305 |
*/
|
306 |
public void processSelected(FeatureVisitor visitor) { |
307 |
} |
308 |
|
309 |
/**
|
310 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#select(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor,
|
311 |
* VectorialSubSet)
|
312 |
*/
|
313 |
public void select(FeatureVisitor visitor) { |
314 |
} |
315 |
|
316 |
/**
|
317 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectFromSelection()
|
318 |
*/
|
319 |
public void selectFromSelection() { |
320 |
} |
321 |
|
322 |
/**
|
323 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
|
324 |
*/
|
325 |
public void createIndex() { |
326 |
} |
327 |
|
328 |
/**
|
329 |
* @see org.cresques.geo.Projected#getProjection()
|
330 |
*/
|
331 |
public IProjection getProjection() {
|
332 |
return getViewPort().getProjection();
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* Inserta la proyecci?n.
|
337 |
*
|
338 |
* @param proj Proyecci?n.
|
339 |
*/
|
340 |
public void setProjection(IProjection proj) { |
341 |
getViewPort().setProjection(proj); |
342 |
} |
343 |
|
344 |
/**
|
345 |
* @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
|
346 |
*/
|
347 |
public void reProject(ICoordTrans arg0) { |
348 |
// TODO implementar reprojecci?n (lo que sea eso)
|
349 |
} |
350 |
|
351 |
/**
|
352 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByPoint(java.awt.geom.Point2D,
|
353 |
* double)
|
354 |
*/
|
355 |
public void selectByPoint(Point2D p, double tolerance) |
356 |
throws DriverException {
|
357 |
Point2D mapPoint = viewPort.toMapPoint((int) p.getX(), (int) p.getY()); |
358 |
SelectByPointVisitor visitor = new SelectByPointVisitor();
|
359 |
visitor.setQueriedPoint(mapPoint); |
360 |
visitor.setTolerance(getViewPort().toMapDistance(3));
|
361 |
|
362 |
try {
|
363 |
layers.process(visitor); |
364 |
} catch (VisitException e) {
|
365 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
366 |
e); |
367 |
} |
368 |
} |
369 |
|
370 |
/**
|
371 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByRect(java.awt.geom.Rectangle2D)
|
372 |
*/
|
373 |
public void selectByRect(Rectangle2D rect) throws DriverException { |
374 |
SelectByRectVisitor visitor = new SelectByRectVisitor();
|
375 |
visitor.setRect(rect); |
376 |
|
377 |
try {
|
378 |
layers.process(visitor); |
379 |
} catch (VisitException e) {
|
380 |
throw new RuntimeException("No se espera que SelectByRectVisitor lance esta excepci?n", |
381 |
e); |
382 |
} |
383 |
} |
384 |
|
385 |
/**
|
386 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
|
387 |
* int)
|
388 |
*/
|
389 |
public void selectByShape(IGeometry g, int relationship) { |
390 |
} |
391 |
|
392 |
/**
|
393 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(Point2D,
|
394 |
* double)
|
395 |
*/
|
396 |
public Record[] queryByPoint(Point2D p, double tolerance) { |
397 |
return null; |
398 |
} |
399 |
|
400 |
/**
|
401 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
|
402 |
*/
|
403 |
public Record[] queryByRect(Rectangle2D rect) { |
404 |
return null; |
405 |
} |
406 |
|
407 |
/**
|
408 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
|
409 |
* int)
|
410 |
*/
|
411 |
public Record[] queryByShape(IGeometry g, int relationship) { |
412 |
return null; |
413 |
} |
414 |
|
415 |
/**
|
416 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
|
417 |
*/
|
418 |
public Rectangle2D getSelectionBounds() { |
419 |
SelectedZoomVisitor visitor = new SelectedZoomVisitor();
|
420 |
|
421 |
|
422 |
try {
|
423 |
layers.process(visitor); |
424 |
} catch (DriverException e1) {
|
425 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
426 |
e1); |
427 |
} catch (VisitException e) {
|
428 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
429 |
e); |
430 |
} |
431 |
|
432 |
return visitor.getSelectBound();
|
433 |
} |
434 |
|
435 |
/**
|
436 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
437 |
* java.awt.Graphics2D, FStyle2D)
|
438 |
*/
|
439 |
public void draw(BufferedImage image, Graphics2D g, Cancellable cancel,double scale) |
440 |
throws DriverException {
|
441 |
if (viewPort.getExtent() == null) { |
442 |
// System.err.println("viewPort.getExtent() = null");
|
443 |
return;
|
444 |
} |
445 |
|
446 |
// System.out.println("Viewport despues: " + viewPort);
|
447 |
/* if ((viewPort.getImageWidth() <=0) || (viewPort.getImageHeight() <= 0))
|
448 |
{
|
449 |
return;
|
450 |
} */
|
451 |
// M?s c?lidad al texto
|
452 |
RenderingHints renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, |
453 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
454 |
renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); |
455 |
renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
456 |
g.setRenderingHints(renderHints); |
457 |
|
458 |
long t1 = System.currentTimeMillis(); |
459 |
layers.draw(image, g, viewPort, cancel,scale); |
460 |
|
461 |
tracLayer.draw(image, g, viewPort, cancel, scale); |
462 |
long t2 = System.currentTimeMillis(); |
463 |
System.err.println("Tiempo de dibujado:" + (t2-t1) + " mseg."); |
464 |
/* g.setColor(Color.BLUE);
|
465 |
GeneralPath shpR = new GeneralPath(viewPort.getExtent());
|
466 |
shpR.transform(viewPort.getAffineTransform());
|
467 |
g.draw(shpR); */
|
468 |
System.gc();
|
469 |
} |
470 |
|
471 |
public void drawGraphics(BufferedImage image, Graphics2D g, Cancellable cancel,double scale) throws DriverException |
472 |
{ |
473 |
if (viewPort == null) return; |
474 |
tracLayer.draw(image, g, viewPort, cancel, scale); |
475 |
} |
476 |
|
477 |
/**
|
478 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
479 |
* java.awt.Graphics2D, FStyle2D)
|
480 |
*/
|
481 |
public void draw(BufferedImage image, Graphics2D g,double scale) |
482 |
throws DriverException {
|
483 |
draw(image, g, new Cancellable() {
|
484 |
/**
|
485 |
* @see com.iver.cit.gvsig.fmap.operations.Cancellable#isCanceled()
|
486 |
*/
|
487 |
public boolean isCanceled() { |
488 |
return false; |
489 |
} |
490 |
},scale); |
491 |
} |
492 |
|
493 |
/**
|
494 |
* Devuelve el ViewPort.
|
495 |
*
|
496 |
* @return Returns the viewPort.
|
497 |
*/
|
498 |
public ViewPort getViewPort() {
|
499 |
return viewPort;
|
500 |
} |
501 |
|
502 |
/**
|
503 |
* Inserta un ViewPort.
|
504 |
*
|
505 |
* @param viewPort The viewPort to set.
|
506 |
*/
|
507 |
public void setViewPort(ViewPort viewPort) { |
508 |
if (this.viewPort != null) { |
509 |
this.viewPort.removeViewPortListener(eventBuffer);
|
510 |
} |
511 |
|
512 |
this.viewPort = viewPort;
|
513 |
viewPort.addViewPortListener(eventBuffer); |
514 |
} |
515 |
|
516 |
/**
|
517 |
* M?todo de conveniencia. Recorre las capas y te da el fullExtent
|
518 |
*
|
519 |
* @return fullExtent de todas las capas.
|
520 |
*
|
521 |
* @throws DriverException
|
522 |
*/
|
523 |
public Rectangle2D getFullExtent() throws DriverException { |
524 |
return layers.getFullExtent();
|
525 |
} |
526 |
|
527 |
/**
|
528 |
* Devuelve el XMLEntity.
|
529 |
*
|
530 |
* @return XMLEntity.
|
531 |
* @throws XMLException
|
532 |
*/
|
533 |
public XMLEntity getXMLEntity() throws XMLException { |
534 |
XMLEntity xml = new XMLEntity();
|
535 |
xml.putProperty("className",this.getClass().getName()); |
536 |
xml.addChild(viewPort.getXMLEntity()); |
537 |
xml.addChild(layers.getXMLEntity()); |
538 |
|
539 |
return xml;
|
540 |
} |
541 |
|
542 |
/**
|
543 |
* Crea un nuevo FMAp a partir del XMLEntity.
|
544 |
*
|
545 |
* @param xml XMLEntity
|
546 |
*
|
547 |
* @return Nuevo FMap.
|
548 |
*
|
549 |
* @throws XMLException
|
550 |
*/
|
551 |
public static FMap createFromXML03(XMLEntity xml) throws XMLException { |
552 |
ViewPort vp = ViewPort.createFromXML03(xml.getChild(0));
|
553 |
FMap fmap = new FMap(vp);
|
554 |
fmap.layers.setXMLEntity03(xml.getChild(1));
|
555 |
|
556 |
return fmap;
|
557 |
} |
558 |
|
559 |
/**
|
560 |
* Crea un nuevo FMAp a partir del XMLEntity.
|
561 |
*
|
562 |
* @param xml XMLEntity
|
563 |
*
|
564 |
* @return Nuevo FMap.
|
565 |
*
|
566 |
* @throws XMLException
|
567 |
*/
|
568 |
public static FMap createFromXML(XMLEntity xml) throws XMLException { |
569 |
ViewPort vp = ViewPort.createFromXML(xml.getChild(0));
|
570 |
FMap fmap = new FMap(vp);
|
571 |
fmap.layers.setXMLEntity(xml.getChild(1));
|
572 |
|
573 |
return fmap;
|
574 |
} |
575 |
|
576 |
/**
|
577 |
* A?ade un AtomicEventListener.
|
578 |
*
|
579 |
* @param listener AtomicEventListener.
|
580 |
*
|
581 |
* @return True si se ha a?adido correctamente.
|
582 |
*/
|
583 |
public boolean addAtomicEventListener(AtomicEventListener listener) { |
584 |
return eventBuffer.addAtomicEventListener(listener);
|
585 |
} |
586 |
|
587 |
/**
|
588 |
* Borra un AtomicEventListener de la lista de listeners.
|
589 |
*
|
590 |
* @param listener AtomicEventListener a borrar.
|
591 |
*
|
592 |
* @return True si se ha borrado correctamente.
|
593 |
*/
|
594 |
public boolean removeAtomicEventListener(AtomicEventListener listener) { |
595 |
return eventBuffer.removeAtomicEventListener(listener);
|
596 |
} |
597 |
|
598 |
/**
|
599 |
* Inicializa los AtomicEvent.
|
600 |
*/
|
601 |
public void beginAtomicEvent() { |
602 |
eventBuffer.beginAtomicEvent(); |
603 |
} |
604 |
|
605 |
/**
|
606 |
* Finaliza los AtomicEvent.
|
607 |
*/
|
608 |
public void endAtomicEvent() { |
609 |
eventBuffer.endAtomicEvent(); |
610 |
} |
611 |
|
612 |
/**
|
613 |
* Evento Layer.
|
614 |
*
|
615 |
* @author Fernando Gonz?lez Cort?s
|
616 |
*/
|
617 |
public class LayerEventListener implements LayerCollectionListener { |
618 |
/**
|
619 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
620 |
*/
|
621 |
public void layerAdded(LayerCollectionEvent e) { |
622 |
// Si es la primera capa, fijamos su extent al ViewPort
|
623 |
//if (getLayers().getLayersCount() == 1) {
|
624 |
if (getViewPort().getExtent() == null) { |
625 |
FLayer lyr = e.getAffectedLayer(); |
626 |
|
627 |
try {
|
628 |
getViewPort().setExtent(lyr.getFullExtent()); |
629 |
} catch (DriverException e1) {
|
630 |
} |
631 |
} |
632 |
|
633 |
//Registramos al FMap como listener del legend de las capas
|
634 |
FLayer lyr = e.getAffectedLayer(); |
635 |
|
636 |
lyr.addLayerListener(eventBuffer); |
637 |
|
638 |
if (lyr instanceof Classifiable) { |
639 |
Classifiable c = (Classifiable) lyr; |
640 |
c.addLegendListener(eventBuffer); |
641 |
} |
642 |
|
643 |
if (lyr instanceof Selectable) { |
644 |
Selectable s = (Selectable) lyr; |
645 |
s.addSelectionListener(eventBuffer); |
646 |
} |
647 |
} |
648 |
|
649 |
/**
|
650 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
651 |
*/
|
652 |
public void layerMoved(LayerPositionEvent e) { |
653 |
} |
654 |
|
655 |
/**
|
656 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
657 |
*/
|
658 |
public void layerRemoved(LayerCollectionEvent e) { |
659 |
FLayer lyr = e.getAffectedLayer(); |
660 |
|
661 |
lyr.removeLayerListener(eventBuffer); |
662 |
|
663 |
if (lyr instanceof Classifiable) { |
664 |
Classifiable c = (Classifiable) lyr; |
665 |
c.removeLegendListener(eventBuffer); |
666 |
} |
667 |
|
668 |
if (lyr instanceof Selectable) { |
669 |
Selectable s = (Selectable) lyr; |
670 |
s.addSelectionListener(eventBuffer); |
671 |
} |
672 |
} |
673 |
|
674 |
/**
|
675 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
676 |
*/
|
677 |
public void layerAdding(LayerCollectionEvent e) |
678 |
throws CancelationException {
|
679 |
} |
680 |
|
681 |
/**
|
682 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
683 |
*/
|
684 |
public void layerMoving(LayerPositionEvent e) |
685 |
throws CancelationException {
|
686 |
} |
687 |
|
688 |
/**
|
689 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
690 |
*/
|
691 |
public void layerRemoving(LayerCollectionEvent e) |
692 |
throws CancelationException {
|
693 |
} |
694 |
|
695 |
/**
|
696 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
697 |
*/
|
698 |
public void activationChanged(LayerCollectionEvent e) |
699 |
throws CancelationException {
|
700 |
} |
701 |
|
702 |
/**
|
703 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
704 |
*/
|
705 |
public void visibilityChanged(LayerCollectionEvent e) |
706 |
throws CancelationException {
|
707 |
} |
708 |
} |
709 |
|
710 |
public void addAsCollectionListener(FLayers layers2) { |
711 |
layers2.addLayerCollectionListener(layerEventListener); |
712 |
} |
713 |
|
714 |
public GraphicLayer getGraphicsLayer()
|
715 |
{ |
716 |
return tracLayer;
|
717 |
} |
718 |
} |