您的位置:首页 > 编程语言

Archie osgEarth Step By Step ⑤OsgEarth开发指南——使用osgearth API编程动态建立地图

2014-02-17 11:30 477 查看
转自:http://blog.csdn.net/archielau/article/details/8493674

一种是使用earth文件,前面已经说过,还可以您使用osgearth API的时候以编程方式动态建立一个地图。

Osgearth也提供一个API供您动态创建地图。如果您的应用程序允许在运行时从不同层中选择一个层显示,那么这种方式就显得很有用。

建立一个地图对象
加入您认为合适的影像和高程地图
建立将渲染地图对象的地图节点
向场景加入你的地图节点

你可以在任何时候加入图层。但是,一旦向地图加入了一个图层,这张地图就有了选项的副本,你不能再改变它了。

[cpp] view
plaincopy

#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 );
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: