osgEarth如何加载离线谷歌卫星地图瓦片的源码教程

说明
本实例演示重新编译bing驱动直接加载本地离线影像瓦片地图。
本实例使用软件版本:osg3.3.1和osgEarth2.5 VC10编译环境(参考osgearth加载谷歌卫星地图的源码案例),vs2010,水经注万能地图下载器。
 osgdb_osgearth_bingd.rar (52.96 KB, 下载次数: 786) 
 osgearthAPI.rar (31.91 KB, 下载次数: 831) 
影像瓦片来源“水经注万能地图下载器”。如果没有安装本软件,可以百度“水经注软件”到官方网站下载。

一、下载瓦片数据
启动水经注万能地图下载器,点击“我的下载”,选择“新建任务”,弹出“选择地图类型” 对话框,选择相应的地图类型,点击“确认”,如下图。



弹出“新建任务”对话框




输入全球坐标,由于我们需要导出瓦片数据,为了增加缩放效果,这里我们从1级到8级都勾选上。选择好级别后,点击开始下载。下载完成后会弹出对话框询问是否要立即导出,选择“是”,然后显示“导出图片数据”对话框,如下图所示。



在该对话框中,选择导出“瓦片:Bing Map”,导出级别“1-8”,选择保存路径,点击“输出”按钮导出数据即可。

二、重新编译Bing驱动
新建“osgdb_osgearth_bingd” 动态库项目,如下图所示。



点击“确定”,弹出“应用程序向导”,如下图所示。



点击下一步



选择程序类型“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(const TileKey& 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文件。

三、新建osgearth应用程序
新建步奏跟新建动态库类似,只是不再选择“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=new osgViewer::Viewer();
        osg::Group* root = new osg::Group;
        osg::Node* tankNode = NULL;
        osg::Vec3 tankPosit;

//        osgEarth: rivers::GDALOptions gdal;
        osgEarth: rivers::BingOptions bing;
//        gdal.url()="D:/Documents/Visual Studio 2010/Projects/test3/test3/data/world.tif";
//        map->addImageLayer(new osgEarth::ImageLayer("xx",gdal));
        map->addImageLayer(new osgEarth::ImageLayer("xx",bing));

        osgEarth::MapNode* mapNode = new osgEarth::MapNode(map);
        viewer->setSceneData( mapNode );
        viewer->realize();
        return viewer->run();
}



启动程序,运行效果如下图所示。



至此,Osgearth加载本地离线影像瓦片地图案例完成。

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值