java - map Pane 地理工具

标签 java swing geotools

我使用 Geotools,我有一个主 Jframe,我使用 JMapPan 来显示 map 。但我对工具栏如何添加光标按钮和按钮来识别功能有问题。我刚刚添加了缩放按钮。 源代码:

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

最佳答案

最简单的方法是使用 JMapFrame 附带的 JToolbar。

JMapFrame frame = = new JMapFrame(mapContent);
frame.enableToolBar(true);
JToolBar toolBar = frame.getToolBar();

但是,如果您确实必须构建自己的,那么请快速浏览一下 JMapFrame code给出:

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

关于java - map Pane 地理工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28581568/

相关文章:

java - 如何停止 Swing EDT

java - 如何通过 ActionListener 类的 actionPerformed() 方法在 Frame 上绘制对象

java - Geotools坐标变换

geotools - 如何在 GeoTools 中获得鼠标坐标?

java - 使用单例模式的 jax-ws 客户端

java - 将 SqlRowSet 导出到文件

java - 半透明光标

java - 显示来自控制台应用程序的消息

java - 覆盖 Swing 类的 toString()

java - 使用带有范围查找的 JTS 对多边形进行矢量化