调整下载地图相关

This commit is contained in:
2022-10-27 14:27:14 +08:00
parent 0bbee4580d
commit 3c0cdc1978
10 changed files with 258 additions and 237 deletions
@@ -530,6 +530,18 @@ void GlobalSetting::setDefaultMapSource(const QString &mapName)
}
}
void GlobalSetting::cleanDownloadInfo()
{
ui->lab_image_num->setText(QString(u8"下载图片数:") );
ui->progressBar->setValue(0);
ui->labMapGrade->setText(QString(u8"地图级别:") );
}
void GlobalSetting::showDownloadImageNum(int total, int actual)
{
ui->lab_image_num->setText(QString(u8"下载图片数:%1/%2").arg(actual).arg(total) );
}
void GlobalSetting::setLngLatRectRange(double lng1, double lat1, double lng2, double lat2)
{
ui->dSpinStartLng->setValue(lng1);
@@ -546,6 +558,8 @@ void GlobalSetting::setProgressBarValue(int value)
void GlobalSetting::setMapSaveGrade(int zoom)
{
ui->labMapGrade->setText(QString("地图级别:%1").arg(zoom) );
ui->progressBar->setValue(0);
ui->lab_image_num->setText(QString(u8"下载图片数:?") );
}
void GlobalSetting::on_pushButton_readVirtualMargin_clicked()
+10
View File
@@ -55,6 +55,16 @@ public:
QMap<int, Config::_latlng> drop2;
public slots:
/**
* @brief 清空地图下载提示信息
*/
void cleanDownloadInfo();
/**
* @brief 显示当前已下载的图片数
* @param total 当前级别的图片总数
* @param actual 当前下载的图片数
*/
void showDownloadImageNum(int total, int actual);
/**
* @brief 设置需要缓存的经纬度范围
* @param lng1 左上角经度
+131 -124
View File
@@ -553,20 +553,37 @@
<string>地图设置</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="6" column="1" colspan="2">
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="labMapGrade">
<property name="text">
<string>地图级别:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="comboMapSource">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>地图源:</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
@@ -680,108 +697,6 @@
</layout>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>区域选择</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLng">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>起点经度:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>起点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>终点经度:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="btnRectRange">
<property name="text">
<string>鼠标框选范围</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLat">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>终点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLng">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLat">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QGroupBox" name="groupMapGrade">
<property name="title">
@@ -966,21 +881,106 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>地图源:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="comboMapSource">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
<item row="4" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>区域选择</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLng">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>起点经度:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>起点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>终点经度:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="btnRectRange">
<property name="text">
<string>鼠标框选范围</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="dSpinStartLat">
<property name="suffix">
<string>°</string>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>终点纬度:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLng">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="dSpinEndLat">
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="3">
@@ -990,6 +990,13 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QLabel" name="lab_image_num">
<property name="text">
<string>下载图片数:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
+2
View File
@@ -421,6 +421,8 @@ MainWindow::MainWindow(QWidget *parent)
connect(map, SIGNAL(rectRange(double, double, double, double) ),
setting->index0->globalsetting, SLOT(setLngLatRectRange(double, double, double, double) ) );
connect(map, SIGNAL(mapSaveGradeChanged(int) ), setting->index0->globalsetting, SLOT(setMapSaveGrade(int) ) );
connect(map, SIGNAL(numberOfTilesChanged(int,int) ), setting->index0->globalsetting, SLOT(showDownloadImageNum(int,int)) );
// connect(map, SIGNAL(downloadMapFinished() ), setting->index0->globalsetting, SLOT(cleanDownloadInfo() ) );
//setting -------menuBar
connect(setting->index0->globalsetting, SIGNAL(goToBase() ),
+8 -5
View File
@@ -85,15 +85,18 @@ QList<Point> PureProjection::GetAreaTileList(const RectLatLng &rect, const int &
Point topLeft = FromPixelToTileXY(FromLatLngToPixel(rect.LocationTopLeft(), zoom));
Point rightBottom = FromPixelToTileXY(FromLatLngToPixel(rect.Bottom(), rect.Right(), zoom));
for (int x = (topLeft.X() - padding); x <= (rightBottom.X() + padding); x++) {
for (int y = (topLeft.Y() - padding); y <= (rightBottom.Y() + padding); y++) {
qDebug() << "topLeft: " << topLeft.X() << " " << topLeft.Y();
qDebug() << "rightBottom: " << rightBottom.X() << " " << rightBottom.Y();
for (int x = (topLeft.X() - padding); x <= (rightBottom.X() + padding); x++)
{
for (int y = (topLeft.Y() - padding); y <= (rightBottom.Y() + padding); y++)
{
Point p = Point(x, y);
if (!ret.contains(p) && p.X() >= 0 && p.Y() >= 0) {
if (!ret.contains(p) && p.X() >= 0 && p.Y() >= 0)
{
ret.append(p);
}
}
}
+23 -87
View File
@@ -26,16 +26,16 @@
*/
#include "mapripper.h"
namespace mapcontrol {
MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng & rect,int const & maxz) : sleep(1), cancel(false), core(core), yesToAll(true)
MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng & rect,int const & maxz) : sleep(1), cancel(true), core(core), yesToAll(true)
{
if (!rect.IsEmpty()) {
type = core->GetMapType();
//progressForm = new MapRipForm;
//connect(progressForm, SIGNAL(cancelRequest()), this, SLOT(stopFetching()));
_area = rect;
area = rect;
zoom = core->Zoom();
setMaxZoom(maxz);
points = core->Projection()->GetAreaTileList(_area, zoom, 0);
points = core->Projection()->GetAreaTileList(area, maxz, 0);
this->start();
cancel = false;
//progressForm->show();
@@ -51,91 +51,50 @@ MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng & rect,i
{ QMessageBox::information(new QWidget(), tr("No valid selection"), tr("This pre-caches map data.\n\nPlease first select the area of the map to rip with <CTRL>+Left mouse click")); }
#endif
}
MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng &area, const QList<int> &grades):
sleep(0), cancel(false), core(core), yesToAll(true), _area(area), zoom(0), _grades(grades)
{
qDebug() << "缓存级别:";
foreach(int v, _grades)
{
qDebug() << v;
}
if(!_grades.isEmpty() )
{
qDebug() << u8"开始获取1";
type = core->GetMapType();
qDebug() << u8"开始获取2";
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
qDebug() << u8"获取完成";
cancel = false;
connect(this, SIGNAL(finished()), this, SLOT(finish()));
emit numberOfTilesChanged(0, 0);
}
}
MapRipper::~MapRipper()
{
qDebug() << u8"MapRipper: 析构函数";
}
void MapRipper::finish()
{
if (zoom < (_grades.size() -1) && !cancel)
{
if (zoom < maxzoom && !cancel) {
++zoom;
int ret = QMessageBox::Yes;
if (!yesToAll)
{
if (!yesToAll) {
QMessageBox msgBox;
msgBox.setText(QString(tr("Continue Ripping at zoom level %1?")).arg(_grades[zoom]) );
msgBox.setText(QString(tr("Continue Ripping at zoom level %1?")).arg(zoom));
// msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::YesAll);
msgBox.setDefaultButton(QMessageBox::Yes);
ret = msgBox.exec();
}
else
{
} else {
ret = QMessageBox::Yes;
}
if (ret == QMessageBox::Yes)
{
if (ret == QMessageBox::Yes) {
points.clear();
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
points = core->Projection()->GetAreaTileList(area, zoom, 0);
//qDebug() << zoom << maxzoom << ret;
this->start();
}
else if (ret == QMessageBox::YesAll)
{
} else if (ret == QMessageBox::YesAll) {
yesToAll = true;
points.clear();
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
points = core->Projection()->GetAreaTileList(area, zoom, 0);
this->start();
}
else
{
} else {
//progressForm->close();
//delete progressForm;
emit ripfinished();
this->deleteLater();
}
}
else
{
} else {
//yesToAll = false;
//progressForm->close();
//delete progressForm;
emit ripfinished();
this->quit();
this->deleteLater();
}
}
@@ -143,70 +102,47 @@ void MapRipper::finish()
void MapRipper::run()
{
qDebug() << u8"mapripper: running";
int countOk = 0;
bool goodtile = false;
// Stuff.Shuffle<Point>(ref list);
QVector<core::MapType::Types> types = OPMaps::Instance()->GetAllLayersOfType(type);
int all = points.count();
emit zoomChanged(_grades[zoom]);
qDebug() << "mapripper: run的次数: " << zoom;
for (int i = 0; i < all; i++)
{
qDebug() << u8"mappripperrunning" ;
for (int i = 0; i < all; i++) {
emit numberOfTilesChanged(all, i + 1);
if (cancel)
{
if (cancel) {
break;
}
core::Point p = points[i];
{
//qDebug()<<"offline fetching:"<<p.ToString();
foreach(core::MapType::Types type, types)
{
foreach(core::MapType::Types type, types) {
emit providerChanged(core::MapType::StrByType(type), zoom);
QByteArray img = OPMaps::Instance()->GetImageFrom(type, p, zoom);
emit providerChanged(core::MapType::StrByType(type), _grades[zoom]);
//qDebug() << img;
QByteArray img = OPMaps::Instance()->GetImageFrom(type, p, _grades[zoom]);
qDebug() << u8"img" << img;
if (img.length() != 0)
{
if (img.length() != 0) {
goodtile = true;
img = NULL;
}
else
{
} else {
goodtile = false;
}
}
if (goodtile)
{
if (goodtile) {
countOk++;
}
else
{
} else {
i--;
QThread::msleep(1);
continue;
}
}
qDebug() << u8"mapripper:发出信号";
emit percentageChanged((int)((i + 1) * 100 / all)); // , i+1);
// worker.ReportProgress((int) ((i+1)*100/all), i+1);
QThread::msleep(sleep);
}
}
void MapRipper::stopFetching()
+2 -7
View File
@@ -44,29 +44,24 @@ class MapRipper : public QThread {
Q_OBJECT
public:
MapRipper(internals::Core *, internals::RectLatLng const &,int const & maxz);
MapRipper(internals::Core *core, internals::RectLatLng const &area, QList<int> const &grades);
~MapRipper();
void run() override;
void run();
private:
QList<core::Point> points;
int zoom;
int gradeIndex;
core::MapType::Types type;
int sleep;
internals::RectLatLng _area;
internals::RectLatLng area;
bool cancel;
MapRipForm *progressForm;
int maxzoom;
internals::Core *core;
bool yesToAll;
QMutex mutex;
QList<int> _grades; //需要缓存的地图级别
signals:
void percentageChanged(int const & perc);
void numberOfTilesChanged(int const & total, int const & actual);
void providerChanged(QString const & prov, int const & zoom);
void zoomChanged(int zoom);
void ripfinished();
+3 -1
View File
@@ -51,9 +51,10 @@ SOURCES += $$PWD/mapgraphicitem.cpp \
$$PWD/AltitudeItem.cpp \
$$PWD/waypointbutton.cpp \
$$PWD/waypointsetting.cpp \
$$PWD/mapripper.cpp \
geoFencecircle.cpp \
geoFenceitem.cpp \
geoFenceitemline.cpp \
geoFenceitemline.cpp \
measureline.cpp
HEADERS += $$PWD/mapgraphicitem.h \
@@ -75,6 +76,7 @@ HEADERS += $$PWD/mapgraphicitem.h \
$$PWD/AltitudeItem.h \
$$PWD/waypointbutton.h \
$$PWD/waypointsetting.h \
$$PWD/mapripper.h \
geoFencecircle.h \
geoFenceitem.h \
geoFenceitemline.h \
+46 -12
View File
@@ -1537,6 +1537,31 @@ void OPMapWidget::ConnectWP(WayPointItem *item)
setSelectedWP(item);
}
void OPMapWidget::createMapRipper()
{
if(mapGrades.empty() ) //已经缓存完就退出
{
emit downloadMapFinished();
return;
}
emit mapSaveGradeChanged(mapGrades[0]);
MapRipper *ripper = new MapRipper(core, mapArea, mapGrades[0]);
connect(ripper, SIGNAL(percentageChanged(int)), this, SIGNAL(mapSaveProgressValue(int)) );
connect(ripper, &MapRipper::numberOfTilesChanged, this, &OPMapWidget::numberOfTilesChanged);
connect(ripper, &MapRipper::finished, this,
[this]()
{
if(!mapGrades.empty() )
{
mapGrades.removeFirst();
}
createMapRipper();
});
}
@@ -1639,18 +1664,27 @@ void OPMapWidget::userRipMap(bool start, qreal lat_l, qreal lng_l, qreal lat_r,
void OPMapWidget::RipMap(internals::RectLatLng const &area, QList<int> const &grades)
{
qDebug() << u8"地图开始缓存";
MapRipper *ripper = new MapRipper(core, area, grades);
connect(ripper, SIGNAL(zoomChanged(int) ), this, SIGNAL(mapSaveGradeChanged(int) ) );
connect(ripper, SIGNAL(percentageChanged(int)), this, SIGNAL(mapSaveProgressValue(int)) );
connect(ripper, &MapRipper::percentageChanged, this,
[this](int value)
{
qDebug() << u8"保存进度百分比:" << value;
});
qDebug() << u8"地图开始缓存";
ripper->start();
{
if(grades.empty() ) //如果没有选择级别,直接return
{
return;
}
mapGrades = grades;
mapArea = area;
createMapRipper();
// qDebug() << u8"地图开始缓存";
// MapRipper *ripper = new MapRipper(core, area, grades);
// connect(ripper, SIGNAL(zoomChanged(int) ), this, SIGNAL(mapSaveGradeChanged(int) ) );
// connect(ripper, SIGNAL(percentageChanged(int)), this, SIGNAL(mapSaveProgressValue(int)) );
// connect(ripper, &MapRipper::percentageChanged, this,
// [this](int value)
// {
// qDebug() << u8"保存进度百分比:" << value;
// });
// qDebug() << u8"地图开始缓存";
// ripper->start();
qDebug() << "opmapwidget: RipMap";
}
+19 -1
View File
@@ -471,6 +471,10 @@ public:
private:
//保存需要缓存的地图级别
QList<int> mapGrades;
//需要缓存的范围
internals::RectLatLng mapArea;
internals::Core *core;
MapGraphicItem *map;
QGraphicsScene mscene;
@@ -516,6 +520,10 @@ private:
int fenceCount = 1;
private slots:
/**
* @brief 创建缓存线程缓存地图
*/
void createMapRipper();
void diagRefresh();
// WayPointItem* item;//apagar
@@ -535,6 +543,16 @@ protected:
// private slots:
signals:
/**
* @brief 所有选择的地图级别下载完成后发出信号
*/
void downloadMapFinished();
/**
* @brief 当前地图级别下载图片进度的信号
* @param total 全部图片数
* @param actual 当前已下载的图片数
*/
void numberOfTilesChanged(int const & total, int const & actual);
/**
* @brief 清除航线信息的信号
*/
@@ -556,7 +574,7 @@ signals:
void rectRange(double lng1, double lat1, double lng2, double lat2);
void cancelRequest();
void percentageChanged(int const & perc);
void numberOfTilesChanged(int const & total, int const & actual);
// void numberOfTilesChanged(int const & total, int const & actual);
void providerChanged(QString const & prov, int const & zoom);
void ripfinished();