先来看下本篇博客索要达到的效果:
找到源码下的gov.nasa.worldwind.util下的StatusBar.java文件,可以看到状态栏显示的信息主要包括视点高度以及对应空间点三维坐标以及是否使用网络等信息。在后续的开发中采用离线模式,因此不需要联网,也不显示网络状态信息。代码依次如下面几幅图所示:
修改完源代码后,将源代码文件导出为jar包,在我们的工程下引用即可。后面如果需要修改源代码,都按这种方式操作;具体操作步骤如下:
需要说明的是导出的时候可以只勾选src文件夹也可以默认。导出后将worldWind2.0.jar文件拷贝到我们的工程目录下,添加应用即可。下面是所有源码:
package cn.whu.vge;
import gov.nasa.worldwind.Model;
import gov.nasa.worldwind.WorldWind;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.util.StatusBar;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JToolBar;
/**
* @author Administrator
*
*/
public class GFScope
{
private JFrame GFScopeMainFrame; // 主窗体
private WorldWindowGLCanvas worldWindowGLCanvas; // 声明WWJ画布
private JPanel WorldWindPanel; //三维视图面板
private JPanel Layerpanel; //图层管理面板
private JPanel StatusBarpanel; //状态栏面板
private StatusBar statusBar; //状态栏
// private WorldWindow wwd;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
GFScope window = new GFScope();
window.GFScopeMainFrame.setVisible(true);
window.GFScopeMainFrame.setTitle("XXXXX子系统");
WorldWind.setOfflineMode(true); // 设置离线运行模式
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public GFScope()
{
initialize();
InitializeEarth(WorldWindPanel,StatusBarpanel);
}
/**
* Initialize the contents of the frame.
*/
/**
*
*/
private void initialize()
{
// 主窗体
GFScopeMainFrame = new JFrame();
GFScopeMainFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(
GFScope.class.getResource("/images/32x32-icon-earth.png")));
GFScopeMainFrame.setBounds(100, 100, 1000, 800);
GFScopeMainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GFScopeMainFrame.getContentPane().setLayout(null);
/**
* 菜单项
*/
JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 984, 30);
GFScopeMainFrame.getContentPane().add(menuBar);
JMenu mnf = new JMenu("\u6587\u4EF6(F)");
menuBar.add(mnf);
JMenu mnv = new JMenu("\u89C6\u56FE(V)");
menuBar.add(mnv);
JMenu mnNewMenu = new JMenu("\u5DE5\u5177(T)");
menuBar.add(mnNewMenu);
JMenu mnNewMenu_1 = new JMenu("\u5206\u6790(A)");
menuBar.add(mnNewMenu_1);
JMenu mnh = new JMenu("\u5E2E\u52A9(H)");
menuBar.add(mnh);
/**
* 工具条
*/
JToolBar toolBar = new JToolBar();
toolBar.setBounds(0, 28, 984, 30);
GFScopeMainFrame.getContentPane().add(toolBar);
JButton btnNewButton = new JButton("");
btnNewButton.setIcon(new ImageIcon(GFScope.class
.getResource("/newt/data/cross-grey-alpha-16x16.png")));
toolBar.add(btnNewButton);
/**
* 面板(图层面板、三维视图面板)
*
* @author
*/
Layerpanel = new JPanel();
Layerpanel.setBounds(0, 60, 194, 702);
GFScopeMainFrame.getContentPane().add(Layerpanel);
WorldWindPanel = new JPanel();
WorldWindPanel.setBounds(194, 60, 790, 673);
GFScopeMainFrame.getContentPane().add(WorldWindPanel);
StatusBarpanel = new JPanel();
StatusBarpanel.setBounds(194, 732, 790, 30);
GFScopeMainFrame.getContentPane().add(StatusBarpanel);
}
private void InitializeEarth(JPanel panel1,JPanel panel2)
{
// 按指定尺寸创建画布
Dimension canvasSize = new Dimension(790, 688);
this.worldWindowGLCanvas = new WorldWindowGLCanvas();
this.worldWindowGLCanvas.setPreferredSize(canvasSize);
// 创建Earth模型,并与画布绑定
Model model = (Model) WorldWind
.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);
this.worldWindowGLCanvas.setModel(model);
panel1.add(worldWindowGLCanvas);
/**
*初始化状态栏信息
* */
this.statusBar=new StatusBar();
this.statusBar.setEventSource(worldWindowGLCanvas);
panel2.add(statusBar);
}
}
欢迎大家留言交流!