我使用Geotools,我有一个主Jframe,我使用JMapPan来显示地图。但是我有一个带有工具栏的问题,如何添加光标按钮和按钮来识别特征,我只是添加了缩放按钮。源代码:
final MapContent map = new MapContent();
map.setTitle("The Map");
Layer rasterLayer = new GridReaderLayer(reader, rasterStyle);
map.addLayer(rasterLayer);
Layer shpLayer = new FeatureLayer(shapefileSource, shpStyle);
map.addLayer(shpLayer);
JMapPane mapPane = new JMapPane(map);
JFrame frame = new JFrame("The Map");
frame.setLayout(new BorderLayout());
frame.add(mapPane, BorderLayout.CENTER);
JPanel buttons = new JPanel();
JButton zoomInButton = new JButton(new ZoomInAction(mapPane));
buttons.add(zoomInButton);
JButton zoomOutButton = new JButton(new ZoomOutAction(mapPane));
buttons.add(zoomOutButton);
JButton pamButton = new JButton(new PanAction(mapPane));
buttons.add(pamButton);
//how to add cursor button and identify features button.
frame.add(buttons, BorderLayout.NORTH);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(600, 400);
frame.setVisible(true);发布于 2015-06-23 09:47:05
最简单的方法是使用JToolbar提供的JMapFrame。
JMapFrame frame = = new JMapFrame(mapContent);
frame.enableToolBar(true);
JToolBar toolBar = frame.getToolBar();但是,如果您真的必须构建自己的程序,那么快速查看一下JMapFrame代码:
if (toolSet.contains(Tool.PAN)) {
btn = new JButton(new PanAction(mapPane));
btn.setName(TOOLBAR_PAN_BUTTON_NAME);
toolBar.add(btn);
cursorToolGrp.add(btn);
toolBar.addSeparator();
}
if (toolSet.contains(Tool.INFO)) {
btn = new JButton(new InfoAction(mapPaneif(toolSet.contains(Tool.PAN)) {
btn = new JButton(new PanAction(mapPane));
btn.setName(TOOLBAR_PAN_BUTTON_NAME);
toolBar.add(btn);
cursorToolGrp.add(btn);
toolBar.addSeparator();
}
if (toolSet.contains(Tool.INFO)) {
btn = new JButton(new InfoAction(mapPane));
btn.setName(TOOLBAR_INFO_BUTTON_NAME);
toolBar.add(btn);
toolBar.addSeparator();
}));
btn.setName(TOOLBAR_INFO_BUTTON_NAME);
toolBar.add(btn);
toolBar.addSeparator();
}https://stackoverflow.com/questions/28581568
复制相似问题