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


 

你可能感兴趣的:(Archie osgEarth Step By Step ⑤OsgEarth开发指南——使用osgearth API编程动态建立地图)