[转]WorldWind开发中WorldWindowGLCanvas .setPreferredSize()函数找不到

值高温假期,无意翻到了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运行结果:

代码:

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  extends JFrame
{
    protected WorldWindowGLCanvas worldWindowGLCanvas; 
    protected StatusBar statusBar;                    
    protected Model modelEarth;
    protected LayerPanel layerPanel; 
    
    public  ()
    {
        
        Dimension canvasSize = new Dimension(850, 650);
        this.worldWindowGLCanvas = new WorldWindowGLCanvas();
        this.worldWindowGLCanvas.setPreferredSize(canvasSize);

        //创建Earth模型,并与画面绑定
        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);
    }
}

原文链接:https://www.dazhuanlan.com/2019/10/17/5da7cbfb15f5a/

猜你喜欢

转载自www.cnblogs.com/rainbow70626/p/12310181.html
今日推荐