本实例演示从新编译bing驱动直接加载本地离线影像瓦片地图。git
本实例使用软件版本:osg3.3.1和osgEarth2.5 VC10编译环境(参考osgearth加载谷歌卫星地图的源码案例),vs2010,水经注万能地图下载器。网站
影像瓦片来源“水经注万能地图下载器”。若是没有安装本软件,能够百度“水经注软件”到官方网站下载。ui
启动水经注万能地图下载器,点击“个人下载”,选择“新建任务”,弹出“选择地图类型” 对话框,选择相应的地图类型,点击“确认”,以下图。url
弹出“新建任务”对话框.net
输入全球坐标,因为咱们须要导出瓦片数据,为了增长缩放效果,这里咱们从1级到8级都勾选上。选择好级别后,点击开始下载。下载完成后会弹出对话框询问是否要当即导出,选择“是”,而后显示“导出图片数据”对话框,以下图所示。debug
在该对话框中,选择导出“瓦片:Bing Map”,导出级别“1-8”,选择保存路径,点击“输出”按钮导出数据便可。orm
新建“osgdb_osgearth_bingd” 动态库项目,以下图所示。blog
点击“肯定”,弹出“应用程序向导”,以下图所示。图片
点击下一步ip
选择程序类型“DLL”,点击“完成”。
添加“包含目录”和“库目录”
包含目录设置为“D:\OSG\include”
库目录设置为“D:\OSG\lib“
以上目录路径根据OSG文件位置设定。
附加依赖项
OpenThreads.lib
osgd.lib
osgAnimationd.lib
osgDBd.lib
osgdb_osgearth_feature_ogrd.lib
osgdb_osgearth_feature_tfsd.lib
osgdb_osgearth_feature_wfsd.lib
osgEarthd.lib
osgEarthAnnotationd.lib
osgEarthFeaturesd.lib
osgEarthSymbologyd.lib
osgEarthUtild.lib
osgFXd.lib
osgGAd.lib
osgManipulatord.lib
osgParticled.lib
osgPresentationd.lib
osgShadowd.lib
osgSimd.lib
osgTerraind.lib
osgTextd.lib
osgUtild.lib
osgViewerd.lib
osgVolumed.lib
osgWidgetd.lib
点击“肯定“。
根据D:\OSG\src\osgearth_2.5\osgearth_gitgui\src\osgEarthDrivers\bing路径找到Bing驱动源代码,以下图所示。
BingTileSource.cpp中的代码复制粘贴到,刚刚新建的osgdb_osgearth_bingd.cpp中
以下图所示。
下一步改写代码
#include " BingOptions" 改为 #include"osgEarthDrivers/bing/BingOptions"
_debugDirect ( false) 默认为false改为_debugDirect ( true )
找到getDirectURI()将内容替换成:
return stringify()<<"D:/Test/tt3Bing"<<getLodKey(key)<<"/"<<getQuadKey(key)<<".jpg";
新建
td::string getLodKey(constTileKey& key)
{
unsigned int lod = key.getLevelOfDetail()+2;
std::stringstream sLod;
if(lod<10)
sLod<<"/L0"<<lod;
if(lod>=10)
sLod<<"/L"<<lod;
//OE_WARN << LC << "sLod:"<<sLod.str() << std::endl;
return sLod.str();
}
注意:其中“D:/Test/tt3Bing“为下载的瓦片存放路径。
从新生成。
生成成功后能够在osgdb_osgearth_bingd.项目Debug中查看到文件。
将拷贝到OSG的bin目录下,替换掉以前的dll文件。
新建步奏跟新建动态库相似,只是再也不选择“DLL“,选择“控制台应用程序“
设置“包含目录“,”库目录“,”依赖项“跟DLL设置同样。
这里新建了一个名为“osgearthAPI“的控制台应用程序。代码以下
#include"stdafx.h"
#include<osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include<osgGA/StateSetManipulator>
#include<osgGA/TrackballManipulator>
#include<osgEarth/Map>
#include<osgEarth/MapNode>
#include<osgEarthDrivers/gdal/GDALOptions>
#include<osgEarthDrivers/bing/BingOptions>
#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions>
#include<osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include<osgEarthDrivers/cache_filesystem/FileSystemCache>
#include<osgEarthUtil/EarthManipulator>
#include<osgEarthUtil/GeodeticGraticule>
#include<osgEarthUtil/LatLongFormatter>
#include<osgEarthUtil/Controls>
#include<osgEarthUtil/MouseCoordsTool>
#include<osgEarthUtil/AutoClipPlaneHandler>
#include<osg/PositionAttitudeTransform>
#include <osg/Group>
#include <osg/Node>
#include <osgDB/ReadFile>
#include<osgUtil\optimizer>
int _tmain(int argc,_TCHAR* argv[])
{
osgEarth::Map* map = new osgEarth::Map();
osg::ref_ptr<osgViewer::Viewer> viewer=newosgViewer::Viewer();
osg::Group* root = new osg::Group;
osg::Node* tankNode = NULL;
osg::Vec3 tankPosit;
// osgEarth::Drivers::GDALOptions gdal;
osgEarth::Drivers::BingOptions bing;
// gdal.url()="D:/Documents/Visual Studio2010/Projects/test3/test3/data/world.tif";
// map->addImageLayer(newosgEarth::ImageLayer("xx",gdal));
map->addImageLayer(newosgEarth::ImageLayer("xx",bing));
osgEarth::MapNode* mapNode = new osgEarth::MapNode(map);
viewer->setSceneData( mapNode );
viewer->realize();
return viewer->run();
}
启动程序,运行效果以下图所示。
完整文档+源码下载:http://download.csdn.net/detail/zss793648186/8404585