首页| 论坛| 消息
主题:Qt实现行政区划轮廓图下载/一键批量下载/可编辑/天地图高德地图百度地图
liudianwu发表于 2026-01-31 16:54
## 一、前言说明
之前就已经实现过这个功能,近期用户反馈某些区域下载不正确,仔细检查原来是因为行政区域同名的原因,比如北京有个朝阳区,长春市也有个朝阳区,在高德地图和天地图的行政区划查询参数中,必须指定朝阳区关键字,而不支持北京市朝阳区这种,要么就是指定唯一地区编码的方式查询才是准确的,之前是按照名字作为关键字模糊查找,于是需要一个地名和编码的对照表,现在AI超级发达,直接叫他生成一个就可以,或者直接从天地图官网下载。
之前下载不正确还有一个问题,那就是省市县行政区划的对照表信息陈旧,大概是二三十年前的,毕竟每年都可能有更新,很多地方是撤县并区,比如卢湾区就合并到了黄浦区,有些是县变成了区,比如崇明县就变成了崇明区,旧的地名就很可能找不到或者找不准。之前对照表是通过一个json文件来读取解析的,这个其实性能较低,现在从天地图官网下载的,直接转csv格式,二维数据表格,性能最佳,而且还带了唯一编码,这下就好办多了,每个省市县都有对应的唯一编码,找到后传入这个编码查询就肯定是准的了。
之前还存在一个问题就是只提供了县的下载,并不支持指定某个省或者某个省下面的某个区这种,索性这次一步到位,做的完善,提供的省市县下拉框后面加个单选框,当单选框选中的省,则只下载下拉框中选择的省,同理市县都是这个机制,同时还支持文本框中输入地名模糊查找,这样可以快速的填入。全部完成试下来,效果非常棒。
## 二、效果图

## 三、相关代码
```cpp
#include "frmmapboundary.h"
#include "ui_frmmapboundary.h"
#include "qthelper.h"
#include "webview.h"
#include "maphelper.h"
#include "cityhelper.h"
frmMapBoundary::frmMapBoundary(QWidget *parent) : QWidget(parent), ui(new Ui::frmMapBoundary)
{
ui->setupUi(this);
this->initForm();
this->initConfig();
}
frmMapBoundary::~frmMapBoundary()
{
on_btnStop_clicked();
delete ui;
}
void frmMapBoundary::showEvent(QShowEvent *)
{
//只需要加载一次/避免重复初始化
static bool isLoad = false;
if (!isLoad) {
isLoad = true;
this->initTable();
QMetaObject::invokeMethod(this, "loadMap", Qt::QueuedConnection);
}
}
void frmMapBoundary::initForm()
{
//设置右侧固定宽度
ui->widgetRight->setFixedWidth(AppData::RightWidth);
indexMain = indexSub = 0;
ui->tabWidget->setCurrentIndex(0);
//下载定时器
timerDown = new QTimer(this);
connect(timerDown, SIGNAL(timeout()), this, SLOT(getBoundary()));
timerDown->setInterval(AppConfig::BoundaryInterval);
//实例化浏览器控件并加入到布局
mapObj = NULL;
webView = new WebView(this);
webView->setLayout(ui->gridLayout);
//关联浏览器控件信号
connect(webView, SIGNAL(receiveDataFromJs(QString, QVariant)), this, SLOT(receiveDataFromJs(QString, QVariant)));
}
void frmMapBoundary::initConfig()
{
MapHelper::loadMapCore(ui->cboxMapCore, AppConfig::BoundaryCore);
connect(ui->cboxMapCore, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
connect(ui->cboxMapCore, SIGNAL(currentIndexChanged(int)), this, SLOT(loadMap()));
connect(ui->cboxMapCore, SIGNAL(currentIndexChanged(int)), this, SLOT(initTable()));
QStringList listInterval;
listInterval setCurrentIndex(ui->cboxInterval->findText(QString::number(AppConfig::BoundaryInterval)));
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
ui->cboxFileType->setCurrentIndex(AppConfig::BoundaryFileType);
connect(ui->cboxFileType, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
}
void frmMapBoundary::saveConfig()
{
AppConfig::BoundaryCore = ui->cboxMapCore->itemData(ui->cboxMapCore->currentIndex()).toInt();
AppConfig::BoundaryInterval = ui->cboxInterval->currentText().toInt();
AppConfig::BoundaryFileType = ui->cboxFileType->currentIndex();
AppConfig::writeConfig();
}
void frmMapBoundary::initTable()
{
cks.clear();
labs.clear();
bars.clear();
flags.clear();
ui->tableWidget->setRowCount(0);
//添加省份到下拉框/市区和县城会自动联动
QList ids;
QStringList province

浏览大图
下一页 (1/8)
回帖(0):

全部回帖(0)»
最新回帖
收藏本帖
发新帖