【准备记录osgearth学习过程,欢迎各位看官留言交流评论~】
osgEarth场景显示主要有4个步骤
1、构建earth文件,EarthNode
2、创建osgViewer
3、设置Earth操作器
4、设置场景参数
一、earth文件准备
<!--
osgEarth Sample - GDAL Driver
Demonstrates the simplest possible use of the GDAL driver to load a GeoTIFF image.
-->
<map>
<image name="World GeoTIFF" driver="gdal">
<url>../data/world.tif</url>
</image>
</map>
这是一个最简单的earth文件,只有tif格式的离线地球形状,后期可以根据需要添加影像、地形、标注等数据。
二、地球节点加载
m_viewer = new osgViewer::Viewer;
m_viewer->setThreadingModel(m_viewer->SingleThreaded);
//m_viewer->setRunFrameScheme(m_viewer->ON_DEMAND);
auto earthManipulator = new osgEarth::Util::EarthManipulator();
// 修改鼠标滚轮放大缩小地图的方式
earthManipulator->getSettings()->bindScroll(osgEarth::Util::EarthManipulator::ACTION_ZOOM_IN, osgGA::GUIEventAdapter::SCROLL_UP);
earthManipulator->getSettings()->bindScroll(osgEarth::Util::EarthManipulator::ACTION_ZOOM_OUT, osgGA::GUIEventAdapter::SCROLL_DOWN);
m_viewer->setCameraManipulator(earthManipulator);
m_root = new osg::Group;
m_earthNode = osgDB::readNodeFile((QApplication::applicationDirPath() + "/data/simple.earth").toStdString().c_str());
//m_earthNode = osgDB::readNodeFile("D:/OSE/OSGEarthSDK/earthFiles/myearth.earth");
m_root->addChild(m_earthNode);
m_viewer->setSceneData(m_root);
三、结果展示