值高温假期,无意翻到了csdn中三维GIS开发的专栏,讲的是worldwind Java三维GIS系统开发的东西,十分感兴趣。恰巧要求的环境已经存在,直接耍起来。将最新的Worldwind和JOGL下载回来,解压加载,然后测试Java和JOGL,一切都很顺利。然而, 将第一个demo敲入package的时候,却发现WorldWindowGLCanvas中没有setPreferredSize()函数的实现。第一想法,demo太老了,可能是worldwind最新版把这个函数遗弃了,换了新的函数。但是,搜了一下最新的worldwind样例,发现仍有该函数的使用。Google一下,关于该函数无法找到的问题 不只我一个,worldwind社区 和stackoverflow论坛 中也有不少提问,没有统一的解决办法,在论坛回复中可以看出大多数人是没遇到的。之后开始怀疑Linux之前是不是被我卸载东西搞坏了,又放到了windows系统环境下试了试,同样出现问题。晚饭过后,扒拉开worldwind api说明,发现是继承的javax.media.opengl.awt.GLCanvas里的问题。
出错原因: JOGL的引用,我是按照官方jogamp.org下载的jogamp-all-platforms.7z来的。worldwind包里gluegen-rt.jar和jogl-all.jar与官方的jar不同。因此,问题就出这里了,将worldwind包里的这两个JOGL的文件拷贝,并引用到Eclipse工程的external_lib中即可,不用官方的最新版。注意: Linux 32位,需要以下四个:gluegen-rt.jar,gluegen-rt-natives-linux-i586.jar,jogl-all.jar,jogl-all-natives-linux-i586.jar Linux 64位,需要以下四个:gluegen-rt.jar,gluegen-rt-natives-linux-amd64.jar,jogl-all.jar,jogl-all-natives-linux-amd64.jar windows 32位,需要以下四个:gluegen-rt.jar,gluegen-rt-natives-windows-i586.jar,jogl-all.jar,jogl-all-natives-windows-i586.jar windows 64位环境下,需要以下四个:gluegen-rt.jar,gluegen-rt-natives-windows-amd64.jar,jogl-all.jar,jogl-all-natives-windows-amd64.jar
Demo运行结果:
代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 package gov.nasa.worldwind.study;import gov.nasa.worldwind.Model;import gov.nasa.worldwind.WorldWind;import gov.nasa.worldwind.avlist.AVKey;import gov.nasa.worldwind.awt.WorldWindowGLCanvas;import gov.nasa.worldwind.util.StatusBar;import gov.nasa.worldwindx.examples.LayerPanel;import java.awt.BorderLayout;import java.awt.Dimension;import javax.swing.JFrame;public class AppDemo1 extends JFrame { protected WorldWindowGLCanvas worldWindowGLCanvas; protected StatusBar statusBar; protected Model modelEarth; protected LayerPanel layerPanel; public AppDemo1 () { Dimension canvasSize = new Dimension(850 , 650 ); this .worldWindowGLCanvas = new WorldWindowGLCanvas(); this .worldWindowGLCanvas.setPreferredSize(canvasSize); modelEarth = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME); this .worldWindowGLCanvas.setModel(modelEarth); this .add(this .worldWindowGLCanvas, BorderLayout.CENTER); this .statusBar = new StatusBar(); this .add(statusBar, BorderLayout.PAGE_END); this .statusBar.setEventSource(worldWindowGLCanvas); layerPanel = new LayerPanel(worldWindowGLCanvas); this .add(layerPanel, BorderLayout.WEST); this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this .setVisible(true ); this .setSize(canvasSize); } public static void main (String[] args) { String title = "系统" ; AppDemo1 app = new AppDemo1(); app.setTitle( "WorldWindDemo" +":" + title); app.setVisible(true ); } }
参考资料
1.《World wind Java三维地理信息系统开发技术指南》 机械工业出版社