You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

#include <osgEarth/Map>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/mbtiles/MBTilesOptions>
#include <osgEarthUtil/EarthManipulator>
#include <osgViewer/Viewer>
#include <QString>
#include <QtGlobal>
int main(int argc, char *argv[])
{
Q_UNUSED(argc);
Q_UNUSED(argv);
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(0, 100, 800, 600);
viewer.setReleaseContextAtEndOfFrameHint(false);
// 添加操作器
viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator());
/// 在旧版本的osgEarth中需通过options来指定使用的哪种ImageLayer
// 创建GDAL图层
osgEarth::Drivers::GDALOptions options;
options.url() = osgEarth::URI("D:/Code/freespace/JGisEngine/data/image_3d_globel.tif");
osg::ref_ptr<osgEarth::ImageLayer> imagelayer = new osgEarth::ImageLayer(
osgEarth::ImageLayerOptions("gdal", options));
// 创建MB图层
osgEarth::Drivers::MBTilesTileSourceOptions mbOpt;
mbOpt.filename()
= "D:/Share/Map/MBTiles/satellite-google-gcj02-zxy-all-9-sc-15-cd-18-3h-21.mbtiles";
mbOpt.format() = "png";
mbOpt.computeLevels() = false;
mbOpt.maxDataLevel() = 21;
mbOpt.minValidValue() = 4;
osg::ref_ptr<osgEarth::ImageLayer> MBImagelayer = new osgEarth::ImageLayer(
osgEarth::ImageLayerOptions("mb", mbOpt));
// string mbtilesFilename = "D:/codes/osgEarth-Projects/osgearth3.4/data/world_countries.mbtiles";
// osg::ref_ptr<MBTilesImageLayer> mbtLayer = new MBTilesImageLayer();
// mbtLayer->setURL(osgEarth::URI(mbtilesFilename));
// osgEarth::GeoExtent mbtExtent = mbtLayer->getExtent();
// 添加图层到Map
osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map();
// map->addImageLayer(imagelayer);
map->addImageLayer(MBImagelayer);
// 添加Map到Node
osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map);
// 添加到场景
viewer.setSceneData(mapNode);
viewer.realize();
return viewer.run();
}