3

Ok,hello everyone, First I'll show what I have:

enter image description here

I have this code:

public static void main(String[] arg) throws IOException {

    map = new DefaultMapContext();
    map.setTitle("Visualizador UD - Geotools");

    mapFrame = new JMapFrame(map);
    mapFrame.enableToolBar(true);
    mapFrame.enableStatusBar(true);//Herramientas abajo

    JToolBar toolBar = new JToolBar();

    eliminar = new JButton("Eliminar capas");
    adicionar = new JButton("Adicionar capas");
    consultar = new JButton("Consultar");

    mapFrame.getToolBar().add(adicionar);
    mapFrame.getToolBar().add(eliminar);
    mapFrame.getToolBar().add(consultar);

    listaLayers = new List();

    for (int i = 0; i < files.length; i++) {
        listaLayers.add(files[i].getName());
    }

    menu();
    mapFrame.add(listaLayers, BorderLayout.WEST);
    mapFrame.add(toolBar, BorderLayout.NORTH);

    mapFrame.setSize(800, 600);
    mapFrame.setVisible(true);
}

Well, My goal is something like that, the same organization:

enter image description here

But I don't know what to do, It's a little confusing for my, the problem is the Layers, I can't put it to the left of the map... I hope you can help me to put in a better way my code.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Castiblanco
  • 1,200
  • 4
  • 13
  • 32

1 Answers1

2

I guess this might be able to solve your problem.

try

// this will get you left pane with the layers added.
frame.enableLayerTable(true); 

you can also directly make use of the following code to directly get your work done.

    JMapFrame frame;
    MapContent map;
    frame = new JMapFrame(map);
    frame.enableLayerTable(true);
    frame.setSize(800, 600);
    frame.enableStatusBar(true);        
    frame.enableToolBar(true);                
    JMenuBar menuBar = new JMenuBar();                          
    frame.setJMenuBar(menuBar);

to add raster and shape file use: public void addshape(File shpFile) throws Exception{

    FileDataStore dataStore = FileDataStoreFinder.getDataStore(shpFile);
    SimpleFeatureSource shapefileSource = dataStore.getFeatureSource();       
    Style shpStyle = SLD.createPolygonStyle(Color.RED, null, 0.0f);
    Layer shpLayer = new FeatureLayer(shapefileSource, shpStyle);       
    map.addLayer(shpLayer);
    show();    
 }
 public void addraster(File rasterFile) throws Exception {         
    AbstractGridFormat format = GridFormatFinder.findFormat( rasterFile );
    reader = format.getReader(rasterFile);     
    Style rasterStyle = createGreyscaleStyle(1);      
    Layer rasterLayer = new GridReaderLayer(reader, rasterStyle);
    map.addLayer(rasterLayer);        
    show();
    }
Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
Leo_Nolan
  • 36
  • 3