增加地图缓存功能
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "uavitem.h"
|
||||
#include "gpsitem.h"
|
||||
#include "homeitem.h"
|
||||
#include "mapgraphicitem.h"
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
@@ -199,6 +198,7 @@ void MapGraphicItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
SetSelectedArea(internals::RectLatLng::Empty);
|
||||
selectionEnd = internals::PointLatLng::Empty;
|
||||
selectionStart = FromLocalToLatLng(event->pos().x(), event->pos().y());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,14 +217,19 @@ void MapGraphicItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
core->SetCurrentPosition(core->LastLocationInBounds);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (!selectionEnd.IsEmpty() && !selectionStart.IsEmpty()) {
|
||||
if (!selectedArea.IsEmpty() && event->modifiers() == Qt::ShiftModifier) {
|
||||
SetZoomToFitRect(SelectedArea());
|
||||
if (!selectedArea.IsEmpty() ) {
|
||||
emit rectRange(selectedArea.Left(), selectedArea.Top(), selectedArea.Right(), selectedArea.Bottom() );
|
||||
// SetZoomToFitRect(SelectedArea());
|
||||
selectedArea = internals::RectLatLng::Empty;
|
||||
emit goToSetting();
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void MapGraphicItem::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
@@ -355,17 +360,17 @@ void MapGraphicItem::DrawMap2D(QPainter *painter)
|
||||
|
||||
// raise error
|
||||
}
|
||||
if (!SelectedArea().IsEmpty()) {
|
||||
// if (!SelectedArea().IsEmpty()) {
|
||||
core::Point p1 = FromLatLngToLocal(SelectedArea().LocationTopLeft());
|
||||
core::Point p2 = FromLatLngToLocal(SelectedArea().LocationRightBottom());
|
||||
int x1 = p1.X();
|
||||
int y1 = p1.Y();
|
||||
int x2 = p2.X();
|
||||
int y2 = p2.Y();
|
||||
painter->setPen(Qt::black);
|
||||
painter->setBrush(QBrush(QColor(50, 50, 100, 20)));
|
||||
painter->setPen(QColor(0, 208, 255, 20));
|
||||
painter->setBrush(QBrush(QColor(0, 208, 255, 5)));
|
||||
painter->drawRect(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,10 +277,15 @@ signals:
|
||||
*
|
||||
* @param zoom
|
||||
*/
|
||||
void rectRange(double lng1, double lat1, double lng2, double lat2);
|
||||
void wpdoubleclicked(WayPointItem *wp);
|
||||
void zoomChanged(double zoomtotal, double zoomreal, double zoomdigi);
|
||||
void childRefreshPosition();
|
||||
void childSetOpacity(qreal value);
|
||||
/**
|
||||
* @brief 转到setting界面的信号
|
||||
*/
|
||||
void goToSetting();
|
||||
};
|
||||
}
|
||||
#endif // MAPGRAPHICITEM_H
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file mapripper.cpp
|
||||
@@ -32,10 +32,10 @@ MapRipper::MapRipper(internals::Core *core, const internals::RectLatLng & rect,i
|
||||
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, zoom, 0);
|
||||
this->start();
|
||||
cancel = false;
|
||||
//progressForm->show();
|
||||
@@ -51,15 +51,30 @@ 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(1), cancel(false), core(core), yesToAll(true), _area(area), zoom(0), _grades(grades)
|
||||
{
|
||||
if(!_grades.isEmpty() )
|
||||
{
|
||||
type = core->GetMapType();
|
||||
points = core->Projection()->GetAreaTileList(area, _grades[zoom], 0);
|
||||
cancel = false;
|
||||
connect(this, SIGNAL(finished()), this, SLOT(finish()));
|
||||
emit numberOfTilesChanged(0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
void MapRipper::finish()
|
||||
{
|
||||
|
||||
if (zoom < maxzoom && !cancel) {
|
||||
if (zoom < _grades.size() && !cancel) {
|
||||
++zoom;
|
||||
emit zoomChanged(_grades[zoom]);
|
||||
int ret = QMessageBox::Yes;
|
||||
if (!yesToAll) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString(tr("Continue Ripping at zoom level %1?")).arg(zoom));
|
||||
msgBox.setText(QString(tr("Continue Ripping at zoom level %1?")).arg(_grades[zoom]) );
|
||||
// msgBox.setInformativeText("Do you want to save your changes?");
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::YesAll);
|
||||
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||
@@ -70,14 +85,14 @@ void MapRipper::finish()
|
||||
|
||||
if (ret == QMessageBox::Yes) {
|
||||
points.clear();
|
||||
points = core->Projection()->GetAreaTileList(area, zoom, 0);
|
||||
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
|
||||
//qDebug() << zoom << maxzoom << ret;
|
||||
|
||||
this->start();
|
||||
} else if (ret == QMessageBox::YesAll) {
|
||||
yesToAll = true;
|
||||
points.clear();
|
||||
points = core->Projection()->GetAreaTileList(area, zoom, 0);
|
||||
points = core->Projection()->GetAreaTileList(_area, _grades[zoom], 0);
|
||||
this->start();
|
||||
|
||||
|
||||
@@ -102,46 +117,66 @@ 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();
|
||||
for (int i = 0; i < all; i++) {
|
||||
for (int i = 0; i < all; i++)
|
||||
{
|
||||
qDebug() << u8"mappripper:running" ;
|
||||
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) {
|
||||
emit providerChanged(core::MapType::StrByType(type), zoom);
|
||||
QByteArray img = OPMaps::Instance()->GetImageFrom(type, p, zoom);
|
||||
foreach(core::MapType::Types type, types)
|
||||
{
|
||||
|
||||
//qDebug() << img;
|
||||
emit providerChanged(core::MapType::StrByType(type), _grades[zoom]);
|
||||
qDebug() << "type: " << type;
|
||||
qDebug() << "zoom: " << zoom;
|
||||
QByteArray img = OPMaps::Instance()->GetImageFrom(type, p, _grades[zoom]);
|
||||
|
||||
if (img.length() != 0) {
|
||||
qDebug() << u8"img:" << img;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,24 +44,27 @@ 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);
|
||||
void run();
|
||||
private:
|
||||
QList<core::Point> points;
|
||||
int zoom;
|
||||
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();
|
||||
|
||||
|
||||
@@ -186,6 +186,11 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
|
||||
|
||||
currentGroup = 3;
|
||||
|
||||
connect(map, SIGNAL(rectRange(double,double,double,double) ),
|
||||
this, SIGNAL(rectRange(double,double,double,double) ) ) ;
|
||||
|
||||
connect(map, SIGNAL(goToSetting() ), this, SIGNAL(goToSetting() ) );
|
||||
|
||||
}
|
||||
|
||||
void OPMapWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
@@ -1616,9 +1621,19 @@ void OPMapWidget::userRipMap(bool start, qreal lat_l, qreal lng_l, qreal lat_r,
|
||||
|
||||
|
||||
|
||||
void OPMapWidget::RipMap()
|
||||
void OPMapWidget::RipMap(internals::RectLatLng const &area, QList<int> const &grades)
|
||||
{
|
||||
new MapRipper(core, map->SelectedArea(),core->MaxZoom());
|
||||
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;
|
||||
});
|
||||
ripper->start();
|
||||
|
||||
qDebug() << "opmapwidget: RipMap";
|
||||
}
|
||||
|
||||
void OPMapWidget::setSelectedWP(QList<WayPointItem * >list)
|
||||
|
||||
@@ -535,7 +535,21 @@ protected:
|
||||
|
||||
// private slots:
|
||||
signals:
|
||||
|
||||
/**
|
||||
* @brief 转到setting界面的信号
|
||||
*/
|
||||
void goToSetting();
|
||||
/**
|
||||
* @brief 地图缓存时更改缓存的地图级别时发出的信号
|
||||
* @param zoom
|
||||
*/
|
||||
void mapSaveGradeChanged(int zoom);
|
||||
/**
|
||||
* @brief 地图缓存进度更改时发出信号
|
||||
* @param value
|
||||
*/
|
||||
void mapSaveProgressValue(int value);
|
||||
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);
|
||||
@@ -788,7 +802,7 @@ public slots:
|
||||
|
||||
void WPSendItemOK(uint16_t seq,bool flag);
|
||||
|
||||
void RipMap();
|
||||
void RipMap(internals::RectLatLng const &area, QList<int> const &grades);
|
||||
void OnSelectionChanged();
|
||||
|
||||
void WPShowTip(bool flag);
|
||||
|
||||
Reference in New Issue
Block a user