admin管理员组文章数量:1530516
2024年1月21日发(作者:)
osgEarth如何加载离线谷歌卫星地图瓦片的源码教程
说明
本实例演示重新编译bing驱动直接加载本地离线影像瓦片地图。
本实例使用软件版本:osg3.3.1和osgEarth2.5 VC10编译环境(参考osgearth加载谷歌卫星地图的源码案例),vs2010,水经注万能地图下载器。
影像瓦片来源“水经注万能地图下载器”。如果没有安装本软件,可以百度“水经注软件”到官方网站下载。
一、下载瓦片数据
启动水经注万能地图下载器,点击“我的下载”,选择“新建任务”,弹出“选择地图类型” 对话框,选择相应的地图类型,点击“确认”,如下图。
弹出“新建任务”对话框
输入全球坐标,由于我们需要导出瓦片数据,为了增加缩放效果,这里我们从1级到8级都勾选上。选择好级别后,点击开始下载。下载完成后会弹出对话框询问是否要立即导出,选择“是”,然后显示“导出图片数据”对话框,如下图所示。
在该对话框中,选择导出“瓦片:Bing Map”,导出级别“1-8”,选择保存路径,点击“输出”按钮导出数据即可。
二、重新编译Bing驱动
新建“osgdb_osgearth_bingd” 动态库项目,如下图所示。
点击“确定”,弹出“应用程序向导”,如下图所示。
点击下一步
选择程序类型“DLL”,点击“完成”。
添加“包含目录”和“库目录”
包含目录设置为“D:OSGinclude”
库目录设置为“D:OSGlib“
以上目录路径根据OSG文件位置设定。
附加依赖项
osgdb_osgearth_feature_
osgdb_osgearth_feature_
osgdb_osgearth_feature_
点击“确定“。
根据D:OSGsrcosgearth_2.5osgearth_gitguisrcosgEarthDriversbing路径找到Bing驱动源代码,如下图所示。
中的代码复制粘贴到,刚刚新建的osgdb_osgearth_中
如下图所示。
下一步改写代码
#include " BingOptions" 改成 #include "osgEarthDrivers/bing/BingOptions"
_debugDirect ( false) 默认为false 改成_debugDirect ( true )
找到getDirectURI()将内容替换成:
return
stringify()<<"D:/Test/tt3Bing"< 新建 td::string getLodKey(const TileKey& key) { unsigned int lod = elOfDetail()+2; std::stringstream sLod; if(lod<10) sLod<<"/L0"< } if(lod>=10) sLod<<"/L"< //OE_WARN << LC << "sLod: "<<() << std::endl; return (); 注意:其中“D:/Test/tt3Bing“为下载的瓦片存放路径。 重新生成。 生成成功后可以在osgdb_osgearth_bingd.项目Debug中查看到osgdb_osgearth_文件。 将文件。 osgdb_osgearth_拷贝到OSG的bin目录下,替换掉之前的dll三、新建osgearth应用程序 新建步奏跟新建动态库类似,只是不再选择“DLL“,选择“控制台应用程序“ 设置“包含目录“,”库目录“,”依赖项“跟DLL设置一样。 这里新建了一个名为“osgearthAPI“的控制台应用程序。代码如下 #include "stdafx.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int _tmain(int argc, _TCHAR* argv[]) { osgEarth::Map* map = new osgEarth::Map(); osg::ref_ptr osg::Group* root = new osg::Group; osg::Node* tankNode = NULL; osg::Vec3 tankPosit; // osgEarth::Drivers::GDALOptions gdal; osgEarth::Drivers::BingOptions bing; // ()="D:/Documents/Visual 2010/Projects/test3/test3/data/"; Studio // 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加载本地离线影像瓦片地图案例完成。
版权声明:本文标题:osgEarth如何加载离线谷歌卫星地图瓦片的源码教程 内容由热心网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:https://m.elefans.com/dianzi/1705845592a158453.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论