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

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

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

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

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

#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 );


 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值