首页| 论坛| 消息
主题:Qt/C++地图组件在视频监控系统中的应用/显示设备点/弹出视频画面/调整设备位置
liudianwu发表于 2025-03-04 10:01
## 一、前言说明
监控系统中一般有很多的摄像头点位,除了在平面图中展示位置以外,有些工地和集团,在集中管理的地方,还希望在电子地图中展示,电子地图可以缩放和拖动,切换设备点自动放大高亮,地图自动移动到设备居中的位置,双击设备可以预览实时画面。设备的经纬度信息,在添加设备的时候有个默认的位置,真实的位置需要到电子地图这边调整,先选中设备,然后鼠标在地图上按下选择新的位置,新的经纬度坐标会显示在文本框中,然后单击更新设备按钮,此时会将最新的经纬度值更新到数据库,并重新加载设备。整个过程立即应用,无需重启。
地图最开始用的百度地图,用的是百度地图自家的坐标系,这个坐标系不是国家标准的火星坐标系,也不是国际标准的地球坐标系,导致很多设备接入不准确,所以后面花了半年时间,全部把整个地图组件重写,发挥多态继承的特性,子类父类方式,实现了百度地图、天地图、高德地图、谷歌地图、腾讯地图等地图的接入支持,用户根据实际需要选择哪一种地图,个人推荐用天地图,用的是大地坐标系,和地球坐标系几乎无偏差,省的反复的坐标转换。
## 二、相关代码
```cpp
#include "frmmapdevice.h"
#include "ui_frmmapdevice.h"
#include "qthelper.h"
#include "dbquery.h"
#include "deviceutil.h"
#include "maphelper.h"
frmMapDevice::frmMapDevice(QWidget *parent) : QWidget(parent), ui(new Ui::frmMapDevice)
{
ui->setupUi(this);
this->initForm();
this->initConfig();
}
frmMapDevice::~frmMapDevice()
{
delete ui;
}
void frmMapDevice::initForm()
{
ui->frameRight->setFixedWidth(AppData::RightWidth);
ui->txtMapZoom->setText(QString::number(OtherConfig::MapZoom));
//摄像头信息变更后重新加载设备位置
lastTime = QDateTime::currentDateTime();
connect(AppEvent::Instance(), SIGNAL(saveIpcInfo()), this, SLOT(on_btnLoadDevice_clicked()));
//关联地图相关信号槽
ui->widgetMap->setProperty("mapControl", 3);
connect(ui->widgetMap, SIGNAL(loadSuccess()), this, SLOT(on_btnLoadDevice_clicked()));
connect(ui->widgetMap, SIGNAL(receiveDataFromJs(QString, QVariant)), this, SLOT(receiveDataFromJs(QString, QVariant)));
//关联设备节点按下信号
connect(ui->widgetTree->getTreeWidget(), SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, SLOT(itemPressed(QTreeWidgetItem *)));
}
void frmMapDevice::initConfig()
{
MapHelper::loadMapCore(ui->cboxMapCore, OtherConfig::MapCore);
connect(ui->cboxMapCore, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
connect(ui->cboxMapCore, SIGNAL(currentIndexChanged(int)), ui->widgetMap, SLOT(loadMap()));
ui->cboxMapLocal->setCurrentIndex(OtherConfig::MapLocal ? 1 : 0);
connect(ui->cboxMapLocal, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
connect(ui->cboxMapLocal, SIGNAL(currentIndexChanged(int)), ui->widgetMap, SLOT(loadMap()));
ui->txtMapZoom->setText(QString::number(OtherConfig::MapZoom));
connect(ui->txtMapZoom, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtCenterPoint->setText(OtherConfig::MapCenterPoint);
ui->txtIpcPosition->setText(OtherConfig::MapCenterPoint);
connect(ui->txtCenterPoint, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
ui->txtVersionKey->setText(OtherConfig::MapVersionKey);
connect(ui->txtVersionKey, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
}
void frmMapDevice::saveConfig()
{
OtherConfig::MapCore = ui->cboxMapCore->itemData(ui->cboxMapCore->currentIndex()).toInt();
OtherConfig::MapLocal = (ui->cboxMapLocal->currentIndex() == 1);
OtherConfig::MapZoom = ui->txtMapZoom->text().toInt();
OtherConfig::MapCenterPoint = ui->txtCenterPoint->text().trimmed();
OtherConfig::MapVersionKey = ui->txtVersionKey->text().trimmed();
OtherConfig::writeConfig();
}
void frmMapDevice::runJs(const QString &js)
{
ui->widgetMap->runJs(js);
}
void frmMapDevice::receiveDataFromJs(const QString &type, const QVariant &data)
{
//qDebug() = 0) {
QString url = DbData::getRtspAddr(index);

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

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