3

好的,大家好,首先我将展示我所拥有的:

在此处输入图像描述

我有这个代码:

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);
}

好吧,我的目标是这样的,同一个组织:

在此处输入图像描述

但我不知道该怎么办,这对我来说有点混乱,问题是图层,我不能把它放在地图的左边......希望你能帮助我把它放在更好的地方我的代码。

4

1 回答 1

2

我想这可能能够解决你的问题。

尝试

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

您也可以直接使用以下代码直接完成您的工作。

    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);

添加光栅和形状文件使用: 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();
    }
于 2013-03-01T11:51:56.603 回答