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 に答える