在Ecplise中嵌入NASA World Wind Java SDK

【IT168 技术文章】 WWJ SDK 是一种构建在 Java OpenGL (JOGL) 扩展之上的 3D 图形地球仪。WWJ 类层次结构的核心是 GLCanvas 的子类 WorldWindowGLCanvas。而 GLCanvas 是一个 Abstract Window Toolkit (AWT) 组件。

  WWJ 对 AWT 的依赖性对于想在 Eclipse 应用程序中使用 WWJ 的 GIS 开发人员来讲是一个障碍。您可能知道,Eclipse 使用了 Standard Widget Toolkit (SWT),而 SWT 与 AWT 不兼容。而且,AWT 和 JOGL 紧密集成,这使得很难从 AWT 移植到 SWT。

  进入 SWT/AWT 桥梁

   SWT 因能够快速构建可伸缩和强大的客户端应用程序而迅速成为一种顶级窗口工具包。SWT 和 AWT/Swing 都在争当 Java 用户界面开发的权威。由于它们各有利弊,Eclipse 基金会意识到有必要构建一座允许在 SWT 中嵌入 AWT/Swing 组件的 SWT/AWT 桥梁。从 Eclipse version 3.0 开始,这座桥梁就已成为 SWT 的一部分。这个的 API 位于 org.eclipse.swt.awt 包中。

  SWT/AWT 桥梁是通过 SWT 将基于 AWT 的 World Wind 3D Globe 嵌入到 Eclipse 应用程序中所需的关键组件。

  WWJ 3D Earth 的 Eclipse 视图

  借助 SWT 中已存在的 SWT/AWT 桥梁,可以轻松地将 WWJ 3D Earth 嵌入到您的视图中。清单 1 演示执行此任务的基本 Eclipse 视图:

  清单 1. WWJ 3D Earth 的基本 Eclipse 视图

1 package org.eclipse.plugin.worldwind.views;
2 _
3
4 /**
5 * World Wind Eclipse RCP Earth View
6 * @author Vladimir Silva
7 *
8 */
9 public class EarthView extends ViewPart
10 {
11    private static final Logger logger = Logger.getLogger(EarthView. class );
12   
13    public static final String ID = EarthView. class .getName();
14    final WorldWindowGLCanvas world = new WorldWindowGLCanvas();
15   
16
17    /**
18     * Initialize the default WW layers
19      */
20    static {
21       initWorldWindLayerModel();
22    }
23
24    public EarthView() {
25       
26    }
27   
28    /**
29     * This is a callback that will allow us to create the viewer and initialize
30     * it.
31      */
32    public void createPartControl(Composite parent)
33    {
34        // GUI: an SWT composite on top
35       Composite top = new Composite(parent, SWT.EMBEDDED);
36       top.setLayoutData( new GridData(GridData.FILL_BOTH));
37         
38        // Swing Frame and Panel
39       java.awt.Frame worldFrame = SWT_AWT.new_Frame(top);
40       java.awt.Panel panel = new java.awt.Panel( new java.awt.BorderLayout());
41       
42       worldFrame.add(panel);
43
44        // Add the WWJ 3D OpenGL Canvas to the Swing Panel
45       panel.add(world, BorderLayout.CENTER);
46
47       parent.setLayoutData( new GridData(GridData.FILL_BOTH));
48         
49    }
50
51    /*
52     * Initialize WW model with default layers
53      */
54    static void initWorldWindLayerModel ()
55    {
56       Model m = (Model) WorldWind.createConfigurationComponent(
57             AVKey.MODEL_CLASS_NAME);
58
59       world.setModel(m);
60    }
61
62    /**
63     * Passing the focus request to the viewer's control.
64      */
65    public void setFocus() {
66    }
67   
68    public static void repaint() {
69       world.repaint();
70    }
71
72    @Override
73    public void dispose() {
74        super .dispose();
75    }
76   
77 }
78

 

  清单 1 首先创建一个顶层 SWT 组件,该组件使用桥梁嵌入 WWJ swing OpenGL 画布:

1 Composite top = new Composite(parent, SWT.EMBEDDED);
2 top.setLayoutData( new GridData(GridData.FILL_BOTH));
3

 

  其次,使用桥梁在顶层 SWT 组件中创建一个子 AWT 框架,用于保存 WWJ OpenGL 画布所需的 Swing panel:

1 java.awt.Frame worldFrame = SWT_AWT.new_Frame(top);
2 java.awt.Panel panel = new java.awt.Panel( new java.awt.BorderLayout());
3

 

  最后,将 WWJ GL 画布添加到 Swing panel:

1 WorldWindowGLCanvas world = new WorldWindowGLCanvas();
2 panel.add(world, BorderLayout.CENTER);
3

 

  图 1 展示了作为 Rich Client Platform (RCP) 应用程序的一部分嵌入到 Eclipse 视图中的 Earth:

  图 1. 显示为 Eclipse 视图的 WWJ Earth

  在地球仪中飞往某地

  如果想让应用程序在 Google Earth 风格下飞往特定的纬度/经度,则需要三个对象:

  View,该对象提供从模型坐标到眼睛坐标的坐标转换,转换规则遵循 OpenGL 的左手坐标系统惯例

  Globe,该对象表示您看到的世界的 3D 椭球体

  您要到达的位置的纬度/经度坐标

  可选信息包括飞行方向和倾斜的角度,以及以米为单位的海拔高度。

  清单 2 演示如何飞往指定位置:

  清单 2. 飞往指定纬度/经度坐标

1 public void flyTo (LatLon latlon)
2 {
3    View view       = world.getView();
4    Globe globe = world.getModel().getGlobe();
5   
6    view.applyStateIterator(FlyToOrbitViewStateIterator.createPanToIterator(
7            (OrbitView)view
8            , globe
9            , latlon       // bbox
10            , Angle.ZERO   // Heading
11            , Angle.ZERO   // Pitch
12            , 3e3 )       // Altitude/Zoom (m)
13            );
14 }
15

 

  View 类的 applyStateIterator() 方法移动或缩放地球仪,在地球仪的目标坐标上制造一种平稳飞行和即时缩放效果。

  除 Earth 以外,WWJ 还捆绑了其他地球仪;WWJ v0.4.1 中可用的 3D 地球仪包括:

  Earth(参见 参考资料,获取包含的数据集)。

  Moon:40xx/30xx 颜色/灰度层,使用一组来自 Clementine 任务的光谱带创建

  Mars:包括来自 Mars Orbital Camera (MOC)、Elevation Maps 等任务的高分辨率图像,使用来自 NASA 喷气推进实验室和 NASA Mars Odyssey/THEMIS 的数据创建。

  图 2 展示了以三种不同的 Eclipse 视图显示的 Earth、Moon 和 Mars:

  图 2. RCP 应用程序中的 Earth、Moon 和 Mars 视图

  结束语

   World Wind Java SDK 是使用 Java 和 OpenGL 编写的 3D 交互式地球查看工具,它允许任何用户从外太空缩放 Earth 上的任何地方。本文介绍了将 WWJ SDK 作为一个 Eclipse 视图嵌入的基本原理,获得了一组在 Eclipse 中进行 GIS 开发的强大工具。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值