4 #include <QtConcurrent>
5 #include "mapsforge/mapdata.h"
6 #include "mapsforge/rastertile.h"
7 #include "projection.h"
12 class MapsforgeMapJob
: public QObject
17 MapsforgeMapJob(const QList
<Mapsforge::RasterTile
> &tiles
)
22 connect(&_watcher
, &QFutureWatcher
<void>::finished
, this,
23 &MapsforgeMapJob::handleFinished
);
24 _future
= QtConcurrent::map(_tiles
, &Mapsforge::RasterTile::render
);
25 _watcher
.setFuture(_future
);
27 void cancel(bool wait
)
31 _future
.waitForFinished();
33 const QList
<Mapsforge::RasterTile
> &tiles() const {return _tiles
;}
36 void finished(MapsforgeMapJob
*job
);
39 void handleFinished() {emit
finished(this);}
42 QFutureWatcher
<void> _watcher
;
43 QFuture
<void> _future
;
44 QList
<Mapsforge::RasterTile
> _tiles
;
47 class MapsforgeMap
: public Map
52 MapsforgeMap(const QString
&fileName
, QObject
*parent
= 0);
54 QRectF
bounds() {return _bounds
;}
55 RectC
llBounds() {return _data
.bounds();}
57 int zoom() const {return _zoom
;}
58 void setZoom(int zoom
);
59 int zoomFit(const QSize
&size
, const RectC
&rect
);
63 void load(const Projection
&in
, const Projection
&out
, qreal deviceRatio
,
67 QPointF
ll2xy(const Coordinates
&c
)
68 {return _transform
.proj2img(_projection
.ll2xy(c
));}
69 Coordinates
xy2ll(const QPointF
&p
)
70 {return _projection
.xy2ll(_transform
.img2proj(p
));}
72 void draw(QPainter
*painter
, const QRectF
&rect
, Flags flags
);
74 bool usesDEM() const {return true;}
76 bool isValid() const {return _data
.isValid();}
77 QString
errorString() const {return _data
.errorString();}
79 static Map
*create(const QString
&path
, const Projection
&proj
, bool *isMap
);
82 void jobFinished(MapsforgeMapJob
*job
);
85 QString
key(int zoom
, const QPoint
&xy
) const;
86 Transform
transform(int zoom
) const;
87 void updateTransform();
88 bool isRunning(int zoom
, const QPoint
&xy
) const;
89 void runJob(MapsforgeMapJob
*job
);
90 void removeJob(MapsforgeMapJob
*job
);
91 void cancelJobs(bool wait
);
93 Mapsforge::MapData _data
;
94 Mapsforge::Style _style
;
97 Projection _projection
;
102 QList
<MapsforgeMapJob
*> _jobs
;
105 #endif // MAPSFORGEMAP_H