## 一、前言说明
现在流行无人机和机器人,未来这块的增量是巨大的,地图组件也顺势而为,之前用web版本的地图组件绘制100个无人机,还行,就是耗时比较多,而且占用内存较大,性能较低,如果是1000个,那基本上歇菜,根本都无法完成,毕竟在web的地图组件中,marker对象是一个很多参数的对象,每一个都需要分配不少的内存,不适合大量的对象,在花了巨大精力用纯QPainter实现这个widget版本的地图组件,本着百倍性能提升的目标去的,亲自验证了下,1000个无人机只需要7ms就完成,不要太好,可以说是瞬间完成,各位web程序员还把web吹上天,在很多大量绘制场景中,还是必须cs架构的软件更擅长。
## 二、效果图
## 三、相关代码
```cpp
#include "frmmarker.h"
#include "ui_frmmarker.h"
#include "qthelper.h"
#include "maphelper.h"
#include "maputil.h"
#include "overlaybase.h"
#include "overlayhelper.h"
frmMarker::frmMarker(QWidget *parent) : QWidget(parent), ui(new Ui::frmMarker)
{
ui->setupUi(this);
this->initForm();
this->initConfig();
this->loadMap();
}
frmMarker::~frmMarker()
{
delete ui;
}
void frmMarker::initForm()
{
offset = 5;
flag = "marker";
marker = NULL;
ui->mapWidget->setFlag("frmMarker");
connect(ui->mapWidget, SIGNAL(receivePoint(qreal, qreal)), this, SLOT(receivePoint(qreal, qreal)));
}
void frmMarker::initConfig()
{
MapHelper::loadTileSource(ui->cboxTileSource, AppConfig::MarkerSource);
connect(ui->cboxTileSource, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
connect(ui->cboxTileSource, SIGNAL(currentIndexChanged(int)), this, SLOT(loadMap()));
MapHelper::loadTileType(ui->cboxTileType, AppConfig::MarkerType);
connect(ui->cboxTileType, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
connect(ui->cboxTileType, SIGNAL(currentIndexChanged(int)), this, SLOT(loadMap()));
ui->cboxOffline->setCurrentIndex(AppConfig::MarkerOffline);
connect(ui->cboxOffline, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
connect(ui->cboxOffline, SIGNAL(currentIndexChanged(int)), this, SLOT(loadMap()));
ui->cboxCache->setCurrentIndex(AppConfig::MarkerCache);
connect(ui->cboxCache, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
connect(ui->cboxCache, SIGNAL(currentIndexChanged(int)), this, SLOT(loadMap()));
MapHelper::loadAlignType(ui->cboxMarkerAlign, 5);
MapHelper::loadAlignType(ui->cboxTextAlign, 4);
ui->cboxFontSize->setCurrentIndex(2);
ui->cboxNumber->setCurrentIndex(2);
ui->cboxTextColor->setColorName("red");
ui->cboxTextBgColor->setColorName("black");
ui->cboxTextBorderColor->setColorName("blue");
}
void frmMarker::saveConfig()
{
AppConfig::MarkerSource = ui->cboxTileSource->itemData(ui->cboxTileSource->currentIndex()).toInt();
AppConfig::MarkerType = ui->cboxTileType->itemData(ui->cboxTileType->currentIndex()).toInt();
AppConfig::MarkerOffline = ui->cboxOffline->currentIndex();
AppConfig::MarkerCache = ui->cboxCache->currentIndex();
AppConfig::writeConfig();
}
void frmMarker::loadMap()
{
on_btnClearMarker_clicked();
int tileSource = ui->cboxTileSource->itemData(ui->cboxTileSource->currentIndex()).toInt();
ui->mapWidget->setTileSource(TileSource(tileSource));
int tileType = ui->cboxTileType->itemData(ui->cboxTileType->currentIndex()).toInt();
ui->mapWidget->setTileType(TileType(tileType));
QString offlinePath = TileHelper::getOfflinePath(TileSource(tileSource));
ui->mapWidget->setOffline(ui->cboxOffline->currentIndex() == 1);
ui->mapWidget->setOfflinePath(offlinePath);
QString cachePath = (ui->cboxCache->currentIndex() == 1 ? QtHelper::appPath() + "/mapcache" : "");
ui->mapWidget->setCachePath(cachePath);
ui->mapWidget->load();
}
void frmMarker::receivePoint(qreal lng, qreal lat)
{
ui->txtL


