好的,大家好,首先我展示一下我有什么:
我有这个代码:
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);
}
好吧,我的目标是类似的,同一个组织:
但我不知道该怎么做,这让我有点困惑,问题是图层,我不能把它放在 map 的左边......我希望你可以帮助我以更好的方式编写我的代码。
最佳答案
我想这或许能解决您的问题。
尝试
// 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) 抛出异常{
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();
}
关于java - JMapFrame 和 GUI [Java],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13892908/