You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
4.3 KiB
C++
164 lines
4.3 KiB
C++
#include "loadonlinemapdialog.h"
|
|
#include "MapEditor/UGMapEditorWnd.h"
|
|
#include "Scene/UGLayer3D.h"
|
|
#include "qdebug.h"
|
|
#include "ui_loadonlinemapdialog.h"
|
|
|
|
#include "translator.h"
|
|
|
|
//MSVC编译器界面显示乱码问题
|
|
//#if _MSC_VER >= 1600
|
|
// #pragma execution_character_set("utf-8")
|
|
//#endif
|
|
|
|
LoadOnlineMapDialog::LoadOnlineMapDialog(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::LoadOnlineMapDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
this->setWindowTitle(u8"在线地图");
|
|
this->resize(600,300);
|
|
this->setWindowFlags(Qt::WindowCloseButtonHint); //关闭右上角帮助(?)按钮。
|
|
|
|
is3DMap = false;
|
|
|
|
addMapSourceItem();
|
|
}
|
|
|
|
LoadOnlineMapDialog::~LoadOnlineMapDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void LoadOnlineMapDialog::setWorkspace(UGWorkspace *pWorkspace, UGMapEditorWnd* pEditorWnd)
|
|
{
|
|
this->pWorkspace = pWorkspace;
|
|
this->pEditorWnd = pEditorWnd;
|
|
this->is3DMap = false;
|
|
}
|
|
|
|
void LoadOnlineMapDialog::setScene(SceneControl *m_pSceneControl)
|
|
{
|
|
this->m_pSceneControl = m_pSceneControl;
|
|
this->is3DMap = true;
|
|
}
|
|
|
|
void LoadOnlineMapDialog::addMapSourceItem()
|
|
{
|
|
ui->mapSourceCbbox->addItem(u8"全球影像地图(经纬度)");
|
|
ui->mapSourceCbbox->addItem(u8"全球影像注记(经纬度)");
|
|
ui->mapSourceCbbox->addItem(u8"全球矢量地图(经纬度)");
|
|
ui->mapSourceCbbox->addItem(u8"全球矢量注记(经纬度)");
|
|
ui->mapSourceCbbox->addItem(u8"全球地形晕渲地图(经纬度)");
|
|
ui->mapSourceCbbox->addItem(u8"全球地形注记(经纬度)");
|
|
}
|
|
|
|
QString LoadOnlineMapDialog::getDataType(int item)
|
|
{
|
|
QString dataType;
|
|
switch (item) {
|
|
case 0:
|
|
dataType = "img_c"; //影像底图(经纬度)
|
|
break;
|
|
case 1:
|
|
dataType = "cia_c"; //影像注记
|
|
break;
|
|
case 2:
|
|
dataType = "vec_c"; //矢量底图(经纬度)
|
|
break;
|
|
case 3:
|
|
dataType = "cva_c"; //矢量注记
|
|
break;
|
|
case 4:
|
|
dataType = "ter_c"; //地形晕渲(经纬度)
|
|
break;
|
|
case 5:
|
|
dataType = "cta_c"; //地形注记
|
|
break;
|
|
default:
|
|
dataType = "img_c";
|
|
break;
|
|
}
|
|
return dataType;
|
|
}
|
|
|
|
bool LoadOnlineMapDialog::loadTiandituMap(int item)
|
|
{
|
|
//加载天地图在线影像
|
|
QString dataType = getDataType(item);
|
|
// QString serverAlias;
|
|
|
|
QString token = "5ff7526440d3a7dab78037697c4679fa";
|
|
QString serverName = "http://t0.tianditu.gov.cn/" + dataType + "/wmts?DPI=96&tk=" + token;
|
|
|
|
//设置连接信息
|
|
UGDsConnection dsCon;
|
|
dsCon.m_strServer = Translator::QStr2UGStr(serverName);
|
|
dsCon.m_strDriver = _U("WMTS");
|
|
dsCon.m_nType = UGEngineType::WEB;
|
|
dsCon.m_strAlias = Translator::QStr2UGStr(dataType);
|
|
|
|
//获取数据源
|
|
UGDataSource* ds_tianditu = pWorkspace->OpenDataSource(dsCon);
|
|
if(ds_tianditu==NULL) return false;
|
|
UGDatasetPtr dataset = ds_tianditu->GetDataset(0);
|
|
UGMap* pMap = &pEditorWnd->m_mapWnd.m_Map;
|
|
//添加图层
|
|
pMap->m_Layers.AddDataset(dataset,true,UGLayer::UG_Layer_Normal,Translator::QStr2UGStr(dataType));
|
|
pMap = NULL;
|
|
return true;
|
|
|
|
}
|
|
|
|
void LoadOnlineMapDialog::loadSceneTiandituMap(int item)
|
|
{
|
|
QString dataType = getDataType(item);
|
|
QString token = "5ff7526440d3a7dab78037697c4679fa";
|
|
QString serverName = "http://t0.tianditu.gov.cn/" + dataType + "/wmts?DPI=96&tk=" + token;
|
|
//url图层参数设置
|
|
UGLayerURLParameter urlParm;
|
|
urlParm.m_strServerRootUrl = Translator::QStr2UGStr(serverName);
|
|
urlParm.m_nType = UGLayer3DType::l3dWMTS;
|
|
urlParm.m_strDataLayerName = _U("img");
|
|
urlParm.m_strUserLayerName = _U("Img_tianditu");
|
|
urlParm.m_dDPI = 96;
|
|
urlParm.m_nImageType = UGFileType::JPGPNG;
|
|
urlParm.m_bAddToScene = true;
|
|
urlParm.m_bVisible = true;
|
|
//添加到场景
|
|
m_pSceneControl->GetUGLayer3Ds()->AddLayer(urlParm);
|
|
}
|
|
|
|
void LoadOnlineMapDialog::on_openMapBtn_clicked()
|
|
{
|
|
int item = ui->mapSourceCbbox->currentIndex();
|
|
if(is3DMap)
|
|
{//三维地图
|
|
loadSceneTiandituMap(item);
|
|
}
|
|
else
|
|
{//二维地图
|
|
QString dataType = getDataType(item);
|
|
if(pWorkspace->m_DataSources.IsAliasExisted(Translator::QStr2UGStr(dataType)))
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
loadTiandituMap(item);
|
|
pEditorWnd->ViewEntire();
|
|
pEditorWnd->Refresh();
|
|
|
|
}
|
|
}
|
|
this->accept();
|
|
}
|
|
|
|
|
|
void LoadOnlineMapDialog::on_cancelBtn_clicked()
|
|
{
|
|
this->close();
|
|
}
|
|
|