Revision 44224 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContext.java

View differences:

MapContext.java
27 27
import java.awt.Graphics2D;
28 28
import java.awt.geom.Rectangle2D;
29 29
import java.awt.image.BufferedImage;
30
import java.text.MessageFormat;
31 30
import java.util.ArrayList;
32 31
import java.util.Iterator;
32
import java.util.LinkedHashMap;
33 33
import java.util.List;
34
import java.util.Map;
34 35
import org.apache.commons.lang3.ArrayUtils;
35 36

  
36 37
import org.cresques.cts.ICoordTrans;
......
56 57
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
57 58
import org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager;
58 59
import org.gvsig.fmap.mapcontext.layers.BaseLayerCollectionListener;
59
import org.gvsig.fmap.mapcontext.layers.CancelationException;
60 60
import org.gvsig.fmap.mapcontext.layers.FLayer;
61 61
import org.gvsig.fmap.mapcontext.layers.FLayers;
62 62
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
......
76 76
import org.gvsig.timesupport.Instant;
77 77
import org.gvsig.timesupport.Interval;
78 78
import org.gvsig.timesupport.RelativeInstant;
79
import org.gvsig.timesupport.Time;
80 79
import org.gvsig.timesupport.TimeSupportLocator;
81 80
import org.gvsig.timesupport.TimeSupportManager;
82 81
import org.gvsig.tools.ToolsLocator;
......
385 384
     * @see #setGraphicsLayer(GraphicLayer)
386 385
     * @see #print(Graphics2D, double, PrintAttributes)
387 386
     */
388
    private GraphicLayer tracLayer = null;
387
//    private GraphicLayer tracLayer = null;
388
    private static final String DEFAULT_TRACTLAYER = "Default";
389
    private Map<String, GraphicLayer> tracLayers;
389 390
    //MapContextLocator.getMapContextManager().createGraphicsLayer(getProjection());
390 391

  
391 392
    /**
......
566 567
     */
567 568
    public MapContext(FLayers fLayers, ViewPort vp) {
568 569
        this.layers = fLayers;
570
        this.tracLayers = new LinkedHashMap<>();
569 571

  
570 572
        layerEventListener = new LayerEventListener();
571 573

  
......
840 842
            }
841 843
        };
842 844
        this.getMapContextDrawer().print(this.layers, g, cancel, scale, properties);
843
        if (tracLayer != null) {
844
            tracLayer.draw(null, g, viewPort, cancel, scale);
845
        for (GraphicLayer tracLayer : this.tracLayers.values()) {
846
            if (tracLayer != null) {
847
                tracLayer.draw(null, g, viewPort, cancel, scale);
848
            }
845 849
        }
846 850
    }
847 851

  
......
1281 1285
    public Envelope getFullEnvelope() throws ReadException {
1282 1286
        Envelope envelope = layers.getFullEnvelope();
1283 1287

  
1284
        if (tracLayer != null) {
1285
            Envelope graphicsEnvelope = tracLayer.getFullEnvelope();
1286
            if (envelope == null) {
1287
                return graphicsEnvelope;
1288
            } else if (graphicsEnvelope != null) {
1289
                envelope.add(graphicsEnvelope);
1288
        for (GraphicLayer tracLayer : this.tracLayers.values()) {
1289
            if (tracLayer != null) {
1290
                Envelope graphicsEnvelope = tracLayer.getFullEnvelope();
1291
                if( graphicsEnvelope==null ) {
1292
                    continue;
1293
                }
1294
                if (envelope == null) {
1295
                    try {
1296
                        envelope =  (Envelope) graphicsEnvelope.clone();
1297
                    } catch (CloneNotSupportedException ex) {
1298
                    }
1299
                } else if (graphicsEnvelope != null) {
1300
                    envelope.add(graphicsEnvelope);
1301
                }
1290 1302
            }
1291 1303
        }
1292

  
1293 1304
        return envelope;
1294 1305
    }
1295 1306

  
......
1414 1425
        layers2.addLayerCollectionListener(layerEventListener);
1415 1426
    }
1416 1427

  
1428
    public GraphicLayer getGraphicsLayer(String name) {
1429
        return this.tracLayers.get(name);
1430
    }
1431
    
1432
    public void setGraphicsLayer(String name, GraphicLayer layer) {
1433
        this.tracLayers.put(name, layer);
1434
    }
1435
    
1436
    public void removeGraphicsLayer(String name) {
1437
        this.tracLayers.remove(name);
1438
    }
1439
    
1417 1440
    /**
1418 1441
     * <p>
1419 1442
     * Returns the internal {@link GraphicLayer GraphicLayer}.</p>
......
1423 1446
     * @see #setGraphicsLayer(GraphicLayer)
1424 1447
     */
1425 1448
    public GraphicLayer getGraphicsLayer() {
1449
        GraphicLayer tracLayer = this.tracLayers.get(DEFAULT_TRACTLAYER);
1426 1450
        if (tracLayer == null) {
1427 1451
            if (getViewPort() != null) {
1428
                this.tracLayer
1452
                tracLayer
1429 1453
                        = MapContextLocator.getMapContextManager()
1430 1454
                        .createGraphicsLayer(
1431 1455
                                getViewPort().getProjection());
1432 1456
            } else {
1433
                this.tracLayer
1457
                tracLayer
1434 1458
                        = MapContextLocator.getMapContextManager()
1435 1459
                        .createGraphicsLayer(null);
1436 1460
            }
1461
            this.tracLayers.put(DEFAULT_TRACTLAYER, tracLayer);
1437 1462
        }
1438 1463
        return tracLayer;
1439 1464
    }
......
1447 1472
     * @see #getGraphicsLayer()
1448 1473
     */
1449 1474
    public void setGraphicsLayer(GraphicLayer graphicLayer) {
1450
        tracLayer = graphicLayer;
1475
        this.tracLayers.put(DEFAULT_TRACTLAYER, graphicLayer);
1451 1476
    }
1452 1477

  
1453 1478
    /**
......
1706 1731

  
1707 1732
    protected void doDispose() throws BaseException {
1708 1733
        dispose(layers);
1709
        dispose(tracLayer);
1734
        for (GraphicLayer tracLayer : this.tracLayers.values()) {
1735
            dispose(tracLayer);
1736
        }
1710 1737
    }
1711 1738

  
1712 1739
    /**
......
1859 1886
            }
1860 1887
        };
1861 1888
    }
1862
    
1889

  
1863 1890
}

Also available in: Unified diff