osg、osgEarth加载tms瓦片数据只显示一个白球,缩放过程中图层消失

osg系列文章目录

前言

osg、osgEarth加载tms瓦片数据只显示一个白球,数据配置、路径配置都没有问题。最后发现是代码问题,把tms瓦片数据显示出来后,发现在缩放地球的时候tms数据又会消失
在这里插入图片描述

一、问题原因

1.代码

// LoadEarthFile.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

// LoadTif.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <Windows.h>
#include <iostream>
#include <string>
#include <cstdlib> // For rand() and srand()
#include <ctime>   // For time()

#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarth/ImageLayer>
#include <osgEarth/EarthManipulator>
#include <osgEarth/OGRFeatureSource>
#include <osgEarth/FeatureModelLayer>
#include <osgEarth/FeatureImageLayer>
#include <osgEarth/ECEF>
#include <osgEarth/GeoData>
#include <osgEarth/Viewpoint>
#include <osgEarth/TerrainOptions>
#include <osgGA/SphericalManipulator>
#include <osgEarth/Symbol>
#include <osgEarth/Feature>
#include <osgEarth/FeatureModelSource>
#include <osgUtil/Tessellator>
#include <osg/LineWidth> 
#include <osg/Depth>
#include <osg/PolygonMode>
#include <osgEarth/ImageOverlay>
#include <osgEarth/GDAL>
#include <osgEarth/TMS>

#include <iostream>

int main()
{
	osgEarth::initialize();
	osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
	//osg::ref_ptr<osg::Node> mp = osgDB::readNodeFile("../vs2022_64bit_3rdParty_osg365_oe32/runtime/test/earthFile/china-simple00.earth");
	osg::ref_ptr<osg::Node> mp = osgDB::readNodeFile("./tms/tms.earth");
	osg::ref_ptr<osg::Group> gpRoot = new osg::Group;
	gpRoot->addChild(mp);

	/*osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map();
	osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map);
	gpRoot->addChild(mapNode);*/


	osg::ref_ptr<osgEarth::EarthManipulator> manipulator = new osgEarth::EarthManipulator;
	manipulator->getSettings()->setMinMaxPitch(-90.0, 90.0);
	manipulator->getSettings()->setThrowingEnabled(false);
	manipulator->getSettings()->setLockAzimuthWhilePanning(false);
	viewer->setCameraManipulator(manipulator);

	// Set the initial viewpoint to look at Chengdu
	osgEarth::Viewpoint vp("Chengdu", 104.0668, 30.5728, 1000000.0, 0.0, -45.0, 25000000.0);
	manipulator->setHomeViewpoint(vp);

	//osg::DisplaySettings::instance()->setNumMultiSamples(8); // 8x MSAA

	// Run the viewer
	viewer->setUpViewInWindow(100, 100, 1600, 1200);

	viewer->setSceneData(gpRoot);
	return viewer->run();
}

2.tms.earth文件

<?xml version="1.0" ?>
<map>
  <version>2</version>
  <options />
  <image>
    <driver>tms</driver>
    <url>imagery/tms.xml</url>
    <name>imagery</name>
  </image>  
</map>

3.tms.xml文件

<?xml version="1.0" ?>
<tilemap tilemapservice="http://tms.osgeo.org/1.0.0" version="1.0.0">
  <title>imagery</title>
  <abstract></abstract>
  <srs>+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs </srs>
  <vsrs></vsrs>
  <boundingbox maxx="12801741.4412264640000000000000000" maxy="5009377.0856973119000000000000000" minx="8348961.8094955198000000000000000" miny="3896182.1777645755000000000000000" />
  <origin x="8348961.8094955198000000000000000" y="3896182.1777645755000000000000000" />
  <tileformat extension="png" height="256" mime-type="image/png" width="256" />
  <tilesets profile="local">
    <tileset href="" order="0" units-per-pixel="8696.8352182244998000000000000" />
    <tileset href="" order="1" units-per-pixel="4348.4176091122499000000000000" />
    <tileset href="" order="2" units-per-pixel="2174.2088045561250000000000000" />
    <tileset href="" order="3" units-per-pixel="1087.1044022780625000000000000" />
    <tileset href="" order="4" units-per-pixel="543.5522011390312400000000000" />
    <tileset href="" order="5" units-per-pixel="271.7761005695156200000000000" />
    <tileset href="" order="6" units-per-pixel="135.8880502847578100000000000" />
    <tileset href="" order="7" units-per-pixel="67.9440251423789050000000000" />
    <tileset href="" order="8" units-per-pixel="33.9720125711894530000000000" />
    <tileset href="" order="9" units-per-pixel="16.9860062855947260000000000" />
    <tileset href="" order="10" units-per-pixel="8.4930031427973631000000000" />
    <tileset href="" order="11" units-per-pixel="4.2465015713986816000000000" />
    <tileset href="" order="12" units-per-pixel="2.1232507856993408000000000" />
    <tileset href="" order="13" units-per-pixel="1.0616253928496704000000000" />
    <tileset href="" order="14" units-per-pixel="0.5308126964248352000000000" />
    <tileset href="" order="15" units-per-pixel="0.2654063482124176000000000" />
    <tileset href="" order="16" units-per-pixel="0.1327031741062088000000000" />
    <tileset href="" order="17" units-per-pixel="0.0663515870531043990000000" />
    <tileset href="" order="18" units-per-pixel="0.0331757935265522000000000" />
    <tileset href="" order="19" units-per-pixel="0.0165878967632761000000000" />
    <tileset href="" order="20" units-per-pixel="0.0082939483816380499000000" />
    <tileset href="" order="21" units-per-pixel="0.0041469741908190250000000" />
    <tileset href="" order="22" units-per-pixel="0.0020734870954095125000000" />
  </tilesets>
  <dataextents>
    <dataextent maxlevel="6" maxx="115.0000000000000000000000000" maxy="45.0000000000000000000000000" minlevel="0" minx="75.0000000000000000000000000" miny="35.0000000000000000000000000" />
  </dataextents>
</tilemap>

二、问题解决

1.估计是TMS瓦片数据的问题,这是我暂时能想到的问题所在,我也只是大胆猜测一下,如果各位大佬发现是其他问题引起的请告知一下小弟,万分感谢

三、工程代码

工程源码下载地址

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值