[原][译][osgearth]API开发地球(OE官方文档翻译)

Posted 南水之源

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[原][译][osgearth]API开发地球(OE官方文档翻译)相关的知识,希望对你有一定的参考价值。

原文参考:http://docs.osgearth.org/en/latest/developer/maps.html#programmatic-map-creation

本人翻译水平有限。。。

 

加载earth地图文件

osg::Node* globe = osgDB::readNodeFile("myglobe.earth");

最简单的方式

 

API编程式的地图创建

用API创建一个地图的基本步骤是:

1.创建一个地图对象(Map object)
2.在你认为合适的地方添加图像层和高程层
3.创建一个可以绘制“地图对象”的MapNode
4.将MapNode添加进场景图。

你可以在任何时候向地图添加层:

using namespace osgEarth;
using namespace osgEarth::Drivers;

#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/tms/TMSOptions>
#include <osgEarthDrivers/gdal/GDALOptions>

using namespace osgEarth;
using namespace osgEarth::Drivers;
...

// Create a Map and set it to Geocentric to display a globe
Map* map = new Map();

// Add an imagery layer (blue marble from a TMS source)
{
    TMSOptions tms;
    tms.url() = "http://labs.metacarta.com/wms-c/Basic.py/1.0.0/satellite/";
    ImageLayer* layer = new ImageLayer( "NASA", tms );
    map->addImageLayer( layer );
}

// Add an elevationlayer (SRTM from a local GeoTiff file)
{
    GDALOptions gdal;
    gdal.url() = "c:/data/srtm.tif";
    ElevationLayer* layer = new ElevationLayer( "SRTM", gdal );
    map->addElevationLayer( layer );
}

// Create a MapNode to render this map:
MapNode* mapNode = new MapNode( map );
...

viewer->setSceneData( mapNode );

(注意:官方的文档是OE2.4的,目前的API是OE2.9喽,时间:2017年2月7日10:27:15)

 

在运行时使用MapNode

MapNode是在场景图中绘制地图的节点(node)

如果,你不是用API创建的MapNode,你需要先使用静态函数get来获取它:

// Load the map
osg::Node* loadedModel = osgDB::readNodeFile("mymap.earth");

// Find the MapNode
osgEarth::MapNode* mapNode = MapNode::get( loadedModel );

如果你有了MapNode,你就可以使用地图了:

// Add an OpenStreetMap image source
TMSOptions driverOpt;
driverOpt.url() = "http://tile.openstreetmap.org/";
driverOpt.tmsType() = "google";

ImageLayerOptions layerOpt( "OSM", driverOpt );
layerOpt.profile() = ProfileOptions( "global-mercator" );

ImageLayer* osmLayer = new ImageLayer( layerOpt );
mapNode->getMap()->addImageLayer( osmLayer );

 




以上是关于[原][译][osgearth]API开发地球(OE官方文档翻译)的主要内容,如果未能解决你的问题,请参考以下文章

[原][译]关于osgEarth::VirtualProgram

[原][译][osgearth]样式表style中参数总结(OE官方文档翻译)

[原][译][osg][osgEarth]飞行模拟软件JSBSim的操作(FGFCS类)

osgearth 只移动

出现白色的地球怎么解决osgearth

osgEarth网上资源