最近想通过osgEarth加载天地图,结果失败。通过对源码测试,总结出以下解决办法:
void AddTianDiTu(osgEarth::Map* pMap)
{
osgEarth::XYZImageLayer* TianDiTu = new osgEarth::XYZImageLayer();
std::string imgURL = "http://t2.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=";
std::string tokey = "";
//1源代码中使用libcurl请求数据时缺少请求头,导致请求失败
.........
osgEarth::URI uri(imgURL + tokey);
TianDiTu->setURL(uri);
//2源代码中对http返回的mimetype缺少支持
........
<完整代码请私信>
TianDiTu->setProfile(Profile::create("spherical-mercator"));
pMap->addLayer(TianDiTu);
}