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