3.OsgEarth加载天地图

愿你出走半生,归来仍是少年!

        上一篇文章构建出来基础的白球,现在需要给它添加底图啦。先上最常用的天地图。

1.天地图

        天地图做过Gis开发的应该都知道,需要先申请key然后才能使用。然后天地图是基于XYZ的标准进行切片的,所以直接使用OSGEarth中的XYZImageLayer进行加载。

2.代码

        此处封装了一个静态函数,方便后期使用。

/// <summary>
/// 创建天地图图层
/// </summary>
/// <param name="key">天地图key</param>
/// <param name="isVector">是否是矢量图层</param>
/// <returns>天地图瓦片图层</returns>
osgEarth::XYZImageLayer* Cv::LayerFactory::CreateTdtTileLayer(std::string key, bool isVector)
{

	osgEarth::URIContext context;
	context.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/"
		"*;q=0.8,application/signed-exchange;v=b3;q=0.9");
	context.addHeader("Accept-Encoding", "gzip, deflate");
	context.addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
	context.addHeader("Cache-Control", "max-age=0");
	context.addHeader("Connection", "keep-alive");
	context.addHeader("Upgrade-Insecure-Requests", "1");
	context.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
		"Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39");

	std::string lySourceName = isVector ? "vec_w" : "img_w";

	std::string lyName = isVector ? "天地图矢量" : "天地图影像";

	osgEarth::URI imgUri("http://t[01234567].tianditu.com/DataServer?T="+ lySourceName +"&tk="+ key +"&l={z}&x={x}&y={y}",
		context);

	osgEarth::XYZImageLayer* imgLy = new osgEarth::XYZImageLayer();

	imgLy->setURL(imgUri);

	imgLy->setProfile(osgEarth::Profile::create("spherical-mercator"));

	imgLy->setName(lyName);

	imgLy->setOpacity(1);

	return imgLy; 
}


/// <summary>
/// 创建天地图注记瓦片图层
/// </summary>
/// <param name="key">天地图key</param>
/// <param name="isVector">是否是矢量图层</param>
/// <returns></returns>
osgEarth::XYZImageLayer* Cv::LayerFactory::CreateTdtRemarkTileLayer(std::string key, bool isVector)
{
	osgEarth::URIContext context;
	context.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/"
		"*;q=0.8,application/signed-exchange;v=b3;q=0.9");
	context.addHeader("Accept-Encoding", "gzip, deflate");
	context.addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
	context.addHeader("Cache-Control", "max-age=0");
	context.addHeader("Connection", "keep-alive");
	context.addHeader("Upgrade-Insecure-Requests", "1");
	context.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
		"Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39");

	std::string lySourceName = isVector ? "cva_w" : "cia_w";

	std::string lyName = isVector ? "天地图矢量注记" : "天地图影像注记";

	osgEarth::URI imgUri("http://t[01234567].tianditu.com/DataServer?T=" + lySourceName + "&tk=" + key + "&l={z}&x={x}&y={y}",
		context);

	osgEarth::XYZImageLayer* imgLy = new osgEarth::XYZImageLayer();

	imgLy->setURL(imgUri);

	imgLy->setName(lyName);

	imgLy->setOpacity(1);

	imgLy->setProfile(osgEarth::Profile::create("spherical-mercator"));

	return imgLy; 
}

3.效果

        通过osgEarth::Map的addLayer添加图层即可完成天地图的加载。

天地图矢量
天地图影像

4.参考

osgearth 加载天地图(亲测可行)_osgearth 天地图_祝太勇的博客-优快云博客

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

就是那个帕吉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值