1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-04-21 12:49:10 +02:00

Compare commits

..

No commits in common. "a4a54101a318dbb742086d829c41ab5157050e02" and "d593b073d55677fa61ce2a5e876ab62622999087" have entirely different histories.

63 changed files with 807 additions and 743 deletions

View File

@ -1,4 +1,4 @@
version: 13.1.{build}
version: 13.0.{build}
configuration:
- Release

View File

@ -3,7 +3,7 @@ unix:!macx:!android {
} else {
TARGET = GPXSee
}
VERSION = 13.1
VERSION = 13.0
QT += core \
gui \

View File

@ -37,7 +37,7 @@ Unicode true
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "13.1"
!define VERSION "13.0"
; The file to write
OutFile "GPXSee-${VERSION}_x64.exe"

View File

@ -25,6 +25,7 @@ ToolTip AreaItem::info() const
AreaItem::AreaItem(const Area &area, Map *map, GraphicsItem *parent)
: PlaneItem(parent), _area(area)
{
_map = map;
_digitalZoom = 0;
_width = 2;
_opacity = 0.5;
@ -34,34 +35,34 @@ AreaItem::AreaItem(const Area &area, Map *map, GraphicsItem *parent)
_pen = QPen(strokeColor(), width());
_brush = QBrush(fillColor());
updatePainterPath(map);
updatePainterPath();
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
}
QPainterPath AreaItem::painterPath(Map *map, const Polygon &polygon)
QPainterPath AreaItem::painterPath(const Polygon &polygon)
{
QPainterPath path;
for (int i = 0; i < polygon.size(); i++) {
const QVector<Coordinates> &subpath = polygon.at(i);
path.moveTo(map->ll2xy(subpath.first()));
path.moveTo(_map->ll2xy(subpath.first()));
for (int j = 1; j < subpath.size(); j++)
path.lineTo(map->ll2xy(subpath.at(j)));
path.lineTo(_map->ll2xy(subpath.at(j)));
path.closeSubpath();
}
return path;
}
void AreaItem::updatePainterPath(Map *map)
void AreaItem::updatePainterPath()
{
_painterPath = QPainterPath();
for (int i = 0; i < _area.polygons().size(); i++)
_painterPath.addPath(painterPath(map, _area.polygons().at(i)));
_painterPath.addPath(painterPath(_area.polygons().at(i)));
}
void AreaItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -84,7 +85,10 @@ void AreaItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void AreaItem::setMap(Map *map)
{
prepareGeometryChange();
updatePainterPath(map);
_map = map;
updatePainterPath();
}
const QColor &AreaItem::strokeColor() const

View File

@ -33,8 +33,8 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
private:
QPainterPath painterPath(Map *map, const Polygon &polygon);
void updatePainterPath(Map *map);
QPainterPath painterPath(const Polygon &polygon);
void updatePainterPath();
void updateColor();
void updateWidth();
void updatePenStyle();
@ -45,6 +45,8 @@ private:
Area _area;
Map *_map;
qreal _width;
QColor _color;
qreal _opacity;

View File

@ -1721,7 +1721,8 @@ bool GUI::loadMapNode(const TreeNode<Map*> &node, MapAction *&action,
bool GUI::loadMap(const QString &fileName, MapAction *&action, bool silent)
{
TreeNode<Map*> maps(MapList::loadMaps(fileName));
TreeNode<Map*> maps(MapList::loadMaps(fileName,
CRS::projection(_options.inputProjection)));
QList<QAction*> existingActions(_mapsActionGroup->actions());
return loadMapNode(maps, action, silent, existingActions);
@ -1811,7 +1812,8 @@ void GUI::loadMapDir()
return;
QFileInfo fi(dir);
TreeNode<Map*> maps(MapList::loadMaps(dir));
TreeNode<Map*> maps(MapList::loadMaps(dir,
CRS::projection(_options.inputProjection)));
QList<QAction*> existingActions(_mapsActionGroup->actions());
QList<MapAction*> actions;
QMenu *menu = new QMenu(maps.name());
@ -2739,9 +2741,13 @@ void GUI::loadOptions()
_mapView->setPOIColor(_options.poiColor);
_mapView->setRenderHint(QPainter::Antialiasing, _options.pathAntiAliasing);
_mapView->setMarkerColor(_options.sliderColor);
_mapView->useOpenGL(_options.useOpenGL);
_mapView->setMapConfig(CRS::projection(_options.inputProjection),
CRS::projection(4326, _options.outputProjection), _options.hidpiMap);
if (_options.useOpenGL)
_mapView->useOpenGL(true);
_mapView->setDevicePixelRatio(devicePixelRatioF(),
_options.hidpiMap ? devicePixelRatioF() : 1.0);
_mapView->setOutputProjection(CRS::projection(4326,
_options.outputProjection));
_mapView->setInputProjection(CRS::projection(_options.inputProjection));
_mapView->setTimeZone(_options.timeZone.zone());
_mapView->setPositionSource(_positionSource);
@ -2850,12 +2856,14 @@ void GUI::updateOptions(const Options &options)
_positionSource = source;
}
if (options.hidpiMap != _options.hidpiMap
|| options.outputProjection != _options.outputProjection
|| options.inputProjection != _options.inputProjection)
_mapView->setMapConfig(CRS::projection(options.inputProjection),
CRS::projection(4326, options.outputProjection), options.hidpiMap);
if (options.hidpiMap != _options.hidpiMap)
_mapView->setDevicePixelRatio(devicePixelRatioF(),
options.hidpiMap ? devicePixelRatioF() : 1.0);
if (options.outputProjection != _options.outputProjection)
_mapView->setOutputProjection(CRS::projection(4326,
options.outputProjection));
if (options.inputProjection != _options.inputProjection)
_mapView->setInputProjection(CRS::projection(options.inputProjection));
if (options.timeZone != _options.timeZone) {
_mapView->setTimeZone(options.timeZone.zone());
_dateRange.first = _dateRange.first.toTimeZone(options.timeZone.zone());
@ -2933,7 +2941,8 @@ void GUI::loadInitialMaps(const QString &selected)
if (mapDir.isNull())
return;
TreeNode<Map*> maps(MapList::loadMaps(mapDir));
TreeNode<Map*> maps(MapList::loadMaps(mapDir,
CRS::projection(_options.inputProjection)));
createMapNodeMenu(createMapActionsNode(maps), _mapMenu, _mapsEnd);
// Select the active map according to the user settings
@ -3035,7 +3044,8 @@ void GUI::show()
void GUI::screenChanged(QScreen *screen)
{
_mapView->setDevicePixelRatio(devicePixelRatioF());
_mapView->setDevicePixelRatio(devicePixelRatioF(),
_options.hidpiMap ? devicePixelRatioF() : 1.0);
disconnect(SIGNAL(logicalDotsPerInchChanged(qreal)), this,
SLOT(logicalDotsPerInchChanged(qreal)));
@ -3047,5 +3057,6 @@ void GUI::logicalDotsPerInchChanged(qreal dpi)
{
Q_UNUSED(dpi)
_mapView->setDevicePixelRatio(devicePixelRatioF());
_mapView->setDevicePixelRatio(devicePixelRatioF(),
_options.hidpiMap ? devicePixelRatioF() : 1.0);
}

View File

@ -81,18 +81,19 @@ ToolTip MapItem::info() const
return tt;
}
MapItem::MapItem(MapAction *action, Map *map, const Projection &proj,
GraphicsItem *parent) : PlaneItem(parent)
MapItem::MapItem(MapAction *action, Map *map, GraphicsItem *parent)
: PlaneItem(parent)
{
Map *src = action->data().value<Map*>();
Q_ASSERT(map->isReady());
_name = src->name();
_fileName = src->path();
_bounds = src->llBounds(proj);
_bounds = src->llBounds();
connect(this, &MapItem::triggered, action, &MapAction::trigger);
_map = map;
_digitalZoom = 0;
_width = 2;
@ -100,23 +101,23 @@ MapItem::MapItem(MapAction *action, Map *map, const Projection &proj,
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, _width);
updatePainterPath(map);
updatePainterPath();
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
}
void MapItem::updatePainterPath(Map *map)
void MapItem::updatePainterPath()
{
_painterPath = QPainterPath();
QRectF r(bbox(_bounds, map));
QRectF r(bbox(_bounds, _map));
if (r.left() > r.right()) {
QRectF r1(bbox(RectC(_bounds.topLeft(),
Coordinates(180, _bounds.bottomRight().lat())), map));
Coordinates(180, _bounds.bottomRight().lat())), _map));
QRectF r2(bbox(RectC(Coordinates(-180, _bounds.topLeft().lat()),
_bounds.bottomRight()), map));
_bounds.bottomRight()), _map));
_painterPath.addRect(r1);
_painterPath.addRect(r2);
@ -142,7 +143,10 @@ void MapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void MapItem::setMap(Map *map)
{
prepareGeometryChange();
updatePainterPath(map);
_map = map;
updatePainterPath();
}
void MapItem::setColor(const QColor &color)

View File

@ -4,15 +4,13 @@
#include "planeitem.h"
class MapAction;
class Projection;
class MapItem : public QObject, public PlaneItem
{
Q_OBJECT
public:
MapItem(MapAction *action, Map *map, const Projection &proj,
GraphicsItem *parent = 0);
MapItem(MapAction *action, Map *map, GraphicsItem *parent = 0);
QPainterPath shape() const {return _painterPath;}
QRectF boundingRect() const {return _painterPath.boundingRect();}
@ -39,12 +37,13 @@ protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
private:
void updatePainterPath(Map *map);
void updatePainterPath();
RectC _bounds;
QString _name;
QString _fileName;
Map *_map;
int _digitalZoom;
qreal _width;

View File

@ -60,12 +60,12 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) : QGraphicsView(parent)
_cursorCoordinates->setVisible(false);
_scene->addItem(_cursorCoordinates);
_deviceRatio = devicePixelRatioF();
_outputProjection = PCS::pcs(3857);
_inputProjection = GCS::gcs(4326);
_hidpi = true;
_map = map;
_map->load(_inputProjection, _outputProjection, _deviceRatio, _hidpi);
_map->load();
_map->setOutputProjection(_outputProjection);
_map->setInputProjection(_inputProjection);
connect(_map, &Map::tilesLoaded, this, &MapView::reloadMap);
_poi = poi;
@ -119,6 +119,8 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) : QGraphicsView(parent)
_showPositionCoordinates = false;
_showMotionInfo = false;
_deviceRatio = 1.0;
_mapRatio = 1.0;
_opengl = false;
_plot = false;
_digitalZoom = 0;
@ -245,7 +247,7 @@ void MapView::addWaypoints(const QVector<Waypoint> &waypoints)
MapItem *MapView::addMap(MapAction *map)
{
MapItem *mi = new MapItem(map, _map, _inputProjection);
MapItem *mi = new MapItem(map, _map);
mi->setColor(_palette.nextColor());
mi->setWidth(_areaWidth);
mi->setPenStyle(_areaStyle);
@ -326,7 +328,7 @@ int MapView::fitMapZoom() const
RectC br = _tr | _rr | _wr | _ar;
return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN),
br.isNull() ? _map->llBounds(_inputProjection) : br);
br.isNull() ? _map->llBounds() : br);
}
QPointF MapView::contentCenter() const
@ -400,18 +402,36 @@ void MapView::setMap(Map *map)
.intersected(_map->bounds()));
RectC cr(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
disconnect(_map, &Map::tilesLoaded, this, &MapView::reloadMap);
_map->unload();
disconnect(_map, &Map::tilesLoaded, this, &MapView::reloadMap);
_map = map;
_map->load(_inputProjection, _outputProjection, _deviceRatio, _hidpi);
_map->load();
_map->setOutputProjection(_outputProjection);
_map->setInputProjection(_inputProjection);
_map->setDevicePixelRatio(_deviceRatio, _mapRatio);
connect(_map, &Map::tilesLoaded, this, &MapView::reloadMap);
digitalZoom(0);
_map->zoomFit(viewport()->rect().size(), cr);
_scene->setSceneRect(_map->bounds());
rescale();
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setMap(_map);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setMap(_map);
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->setMap(_map);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setMap(_map);
for (POIHash::const_iterator it = _pois.constBegin();
it != _pois.constEnd(); it++)
it.value()->setMap(_map);
updatePOIVisibility();
_crosshair->setMap(_map);
QPointF nc = QRectF(_map->ll2xy(cr.topLeft()),
_map->ll2xy(cr.bottomRight())).center();
@ -682,9 +702,8 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
PlotFlags flags)
{
QRect orig, adj;
qreal ratio, diff, q, p;
qreal mapRatio, ratio, diff, q, p;
QPointF scenePos, scalePos, posPos, motionPos;
bool hidpi = _hidpi && _deviceRatio > 1.0;
int zoom;
@ -709,8 +728,8 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
}
// Expand the view if plotting into a bitmap
if (hidpi)
setHidpi(false);
mapRatio = _mapRatio;
setDevicePixelRatio(_deviceRatio, 1.0);
if (flags & Expand) {
qreal xdiff = (target.width() - adj.width()) / 2.0;
@ -765,8 +784,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
centerOn(scenePos);
}
if (hidpi)
setHidpi(true);
setDevicePixelRatio(_deviceRatio, mapRatio);
_mapScale->setDigitalZoom(_digitalZoom);
_mapScale->setPos(scalePos);
@ -1218,9 +1236,6 @@ bool MapView::gestureEvent(QGestureEvent *event)
void MapView::useOpenGL(bool use)
{
if (_opengl == use)
return;
_opengl = use;
if (use)
@ -1271,21 +1286,60 @@ void MapView::reloadMap()
_scene->invalidate();
}
void MapView::setMapConfig(const Projection &in, const Projection &out,
bool hidpi)
void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
_inputProjection = in;
_outputProjection = out;
_hidpi = hidpi;
if (_deviceRatio == deviceRatio && _mapRatio == mapRatio)
return;
setMap(_map);
_deviceRatio = deviceRatio;
_mapRatio = mapRatio;
QRectF vr(mapToScene(viewport()->rect()).boundingRect()
.intersected(_map->bounds()));
RectC cr(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
_map->setDevicePixelRatio(_deviceRatio, _mapRatio);
_scene->setSceneRect(_map->bounds());
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setMap(_map);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setMap(_map);
for (int i = 0; i < _areas.size(); i++)
_areas.at(i)->setMap(_map);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setMap(_map);
for (POIHash::const_iterator it = _pois.constBegin();
it != _pois.constEnd(); it++)
it.value()->setMap(_map);
updatePOIVisibility();
_crosshair->setMap(_map);
QPointF nc = QRectF(_map->ll2xy(cr.topLeft()),
_map->ll2xy(cr.bottomRight())).center();
centerOn(nc);
reloadMap();
}
void MapView::setDevicePixelRatio(qreal ratio)
void MapView::setOutputProjection(const Projection &proj)
{
_deviceRatio = ratio;
_outputProjection = proj;
Coordinates center = _map->xy2ll(mapToScene(viewport()->rect().center()));
_map->setOutputProjection(_outputProjection);
rescale();
centerOn(_map->ll2xy(center));
}
setMap(_map);
void MapView::setInputProjection(const Projection &proj)
{
_inputProjection = proj;
Coordinates center = _map->xy2ll(mapToScene(viewport()->rect().center()));
_map->setInputProjection(_inputProjection);
rescale();
centerOn(_map->ll2xy(center));
}
void MapView::fitContentToSize()
@ -1382,20 +1436,3 @@ void MapView::drawInfoBackground(bool draw)
_positionCoordinates->drawBackground(draw);
_motionInfo->drawBackground(draw);
}
void MapView::setHidpi(bool hidpi)
{
QRectF vr(mapToScene(viewport()->rect()).boundingRect()
.intersected(_map->bounds()));
RectC cr(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
_map->unload();
_map->load(_inputProjection, _outputProjection, _deviceRatio, hidpi);
rescale();
QPointF nc = QRectF(_map->ll2xy(cr.topLeft()),
_map->ll2xy(cr.bottomRight())).center();
centerOn(nc);
reloadMap();
}

View File

@ -92,8 +92,9 @@ public:
void useAntiAliasing(bool use);
void setCoordinatesFormat(CoordinatesFormat format);
void setTimeZone(const QTimeZone &zone);
void setMapConfig(const Projection &in, const Projection &out, bool hidpi);
void setDevicePixelRatio(qreal ratio);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void setOutputProjection(const Projection &proj);
void setInputProjection(const Projection &proj);
void clearMapCache();
void fitContentToSize();
@ -155,7 +156,6 @@ private:
bool gestureEvent(QGestureEvent *event);
void pinchGesture(QPinchGesture *gesture);
void skipColor() {_palette.nextColor();}
void setHidpi(bool hidpi);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
@ -209,7 +209,7 @@ private:
QCursor _cursor;
qreal _deviceRatio;
bool _hidpi;
qreal _mapRatio;
bool _opengl;
int _pinchZoom;

View File

@ -252,13 +252,8 @@ AQMMap::AQMMap(const QString &fileName, QObject *parent)
_valid = true;
}
void AQMMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void AQMMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_file.open(QIODevice::ReadOnly);
}
@ -310,6 +305,12 @@ int AQMMap::zoomOut()
return _zoom;
}
void AQMMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
_mapRatio = mapRatio;
}
QPointF AQMMap::ll2xy(const Coordinates &c)
{
const Zoom &z = _zooms.at(_zoom);
@ -405,7 +406,7 @@ void AQMMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
painter->drawPixmap(tp, pixmap);
}
Map *AQMMap::create(const QString &path, bool *isDir)
Map *AQMMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -17,7 +17,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds(const Projection &) {return _bounds;}
RectC llBounds() {return _bounds;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}
@ -26,9 +26,9 @@ public:
int zoomIn();
int zoomOut();
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
@ -38,7 +38,7 @@ public:
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
struct File {

View File

@ -14,7 +14,12 @@
static bool resCmp(OziMap *m1, OziMap *m2)
{
return m1->resolution(m1->bounds()) > m2->resolution(m2->bounds());
qreal r1, r2;
r1 = m1->resolution(m1->bounds());
r2 = m2->resolution(m2->bounds());
return r1 > r2;
}
static bool xCmp(OziMap *m1, OziMap *m2)
@ -33,7 +38,7 @@ void Atlas::computeZooms()
_zooms.append(Zoom(0, _maps.count() - 1));
for (int i = 1; i < _maps.count(); i++) {
qreal last = _maps.at(i-1)->resolution(_maps.at(i-1)->bounds());
qreal last = _maps.at(i-1)->resolution(_maps.at(i)->bounds());
qreal cur = _maps.at(i)->resolution(_maps.at(i)->bounds());
if (cur < last * ZOOM_THRESHOLD) {
_zooms.last().last = i-1;
@ -131,17 +136,18 @@ Atlas::Atlas(const QString &fileName, bool TAR, QObject *parent)
return;
}
computeZooms();
computeBounds();
_valid = true;
}
RectC Atlas::llBounds(const Projection &proj)
void Atlas::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
RectC bounds;
for (int i = 0; i < _maps.size(); i++)
bounds |= _maps.at(i)->llBounds(proj);
_maps[i]->setDevicePixelRatio(deviceRatio, mapRatio);
return bounds;
computeBounds();
}
QRectF Atlas::bounds()
@ -271,31 +277,20 @@ void Atlas::draw(QPainter *painter, const QRectF &rect, int mapIndex,
const QPointF offset = _bounds.at(mapIndex).xy.topLeft();
QRectF pr = QRectF(rect.topLeft() - offset, rect.size());
map->load();
painter->translate(offset);
map->draw(painter, pr, flags);
painter->translate(-offset);
}
void Atlas::load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi)
{
for (int i = 0; i < _maps.count(); i++)
_maps.at(i)->load(in, out, deviceRatio, hidpi);
computeZooms();
computeBounds();
}
void Atlas::unload()
{
for (int i = 0; i < _maps.count(); i++)
_maps.at(i)->unload();
_zooms.clear();
_bounds.clear();
}
Map *Atlas::createTAR(const QString &path, bool *isDir)
Map *Atlas::createTAR(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = true;
@ -303,7 +298,7 @@ Map *Atlas::createTAR(const QString &path, bool *isDir)
return new Atlas(path, true);
}
Map *Atlas::createTBA(const QString &path, bool *isDir)
Map *Atlas::createTBA(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = true;

View File

@ -3,7 +3,6 @@
#include "map.h"
#include "rectd.h"
#include "projection.h"
class OziMap;
@ -17,7 +16,6 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds(const Projection &proj);
int zoom() const {return _zoom;}
void setZoom(int zoom);
@ -30,15 +28,14 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void unload();
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *createTAR(const QString &path, bool *isDir);
static Map *createTBA(const QString &path, bool *isDir);
static Map *createTAR(const QString &path, const Projection &, bool *isDir);
static Map *createTBA(const QString &path, const Projection &, bool *isDir);
private:
struct Zoom {

View File

@ -390,7 +390,7 @@ QImage BSBMap::readImage()
}
BSBMap::BSBMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _img(0), _mapRatio(1.0), _dataOffset(-1), _valid(false)
: Map(fileName, parent), _img(0), _ratio(1.0), _dataOffset(-1), _valid(false)
{
QFile file(fileName);
@ -414,19 +414,19 @@ BSBMap::~BSBMap()
QPointF BSBMap::ll2xy(const Coordinates &c)
{
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _mapRatio;
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
}
Coordinates BSBMap::xy2ll(const QPointF &p)
{
return _projection.xy2ll(_transform.img2proj(p * _mapRatio));
return _projection.xy2ll(_transform.img2proj(p * _ratio));
}
QRectF BSBMap::bounds()
{
return _skewSize.isValid()
? QRectF(QPointF(0, 0), _skewSize / _mapRatio)
: QRectF(QPointF(0, 0), _size / _mapRatio);
? QRectF(QPointF(0, 0), _skewSize / _ratio)
: QRectF(QPointF(0, 0), _size / _ratio);
}
void BSBMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
@ -435,14 +435,17 @@ void BSBMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
_img->draw(painter, rect, flags);
}
void BSBMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void BSBMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(in);
Q_UNUSED(out);
Q_UNUSED(deviceRatio);
_mapRatio = hidpi ? deviceRatio : 1.0;
_ratio = mapRatio;
if (_img)
_img->setDevicePixelRatio(_ratio);
}
void BSBMap::load()
{
if (!_img) {
if (_skew > 0.0 && _skew < 360.0) {
QTransform matrix;
@ -451,9 +454,6 @@ void BSBMap::load(const Projection &in, const Projection &out,
} else
_img = new Image(readImage());
}
if (_img)
_img->setDevicePixelRatio(_mapRatio);
}
void BSBMap::unload()
@ -462,7 +462,7 @@ void BSBMap::unload()
_img = 0;
}
Map *BSBMap::create(const QString &path, bool *isMap)
Map *BSBMap::create(const QString &path, const Projection &, bool *isMap)
{
if (isMap)
*isMap = false;

View File

@ -25,14 +25,14 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isMap);
static Map *create(const QString &path, const Projection &, bool *isMap);
private:
bool parseBSB(const QByteArray &line);
@ -56,7 +56,7 @@ private:
Image *_img;
QSize _size;
QSize _skewSize;
qreal _mapRatio;
qreal _ratio;
qint64 _dataOffset;
QVector<QRgb> _palette;

View File

@ -14,7 +14,7 @@ public:
QString name() const {return QString();}
QRectF bounds();
RectC llBounds(const Projection &) {return OSM::BOUNDS;}
RectC llBounds() {return OSM::BOUNDS;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}

View File

@ -22,16 +22,9 @@ ENCMap::ENCMap(const QString &fileName, QObject *parent)
}
}
void ENCMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void ENCMap::load()
{
Q_UNUSED(in);
Q_UNUSED(hidpi);
_tileRatio = deviceRatio;
_projection = out;
_data.load();
QPixmapCache::clear();
}
void ENCMap::unload()
@ -225,7 +218,24 @@ void ENCMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
}
}
Map *ENCMap::create(const QString &path, bool *isMap)
void ENCMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(mapRatio);
_tileRatio = deviceRatio;
}
void ENCMap::setOutputProjection(const Projection &projection)
{
if (!projection.isValid() || projection == _projection)
return;
_projection = projection;
updateTransform();
QPixmapCache::clear();
}
Map *ENCMap::create(const QString &path, const Projection &, bool *isMap)
{
if (isMap)
*isMap = false;

View File

@ -53,7 +53,7 @@ public:
QString name() const {return _data.name();}
QRectF bounds() {return _bounds;}
RectC llBounds(const Projection &) {return _llBounds;}
RectC llBounds() {return _llBounds;}
int zoom() const {return _zoom;}
void setZoom(int zoom);
@ -61,9 +61,10 @@ public:
int zoomIn();
int zoomOut();
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setOutputProjection(const Projection &projection);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
QPointF ll2xy(const Coordinates &c)
{return _transform.proj2img(_projection.ll2xy(c));}
@ -75,7 +76,7 @@ public:
bool isValid() const {return _data.isValid();}
QString errorString() const {return _data.errorString();}
static Map *create(const QString &path, bool *isMap);
static Map *create(const QString &path, const Projection &, bool *isMap);
private slots:
void jobFinished(ENCMapJob *job);

View File

@ -182,13 +182,8 @@ Coordinates GEMFMap::xy2ll(const QPointF &p)
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale) * _mapRatio);
}
void GEMFMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void GEMFMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_file.open(QIODevice::ReadOnly);
}
@ -301,7 +296,7 @@ void GEMFMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
painter->drawPixmap(tp, pixmap);
}
Map *GEMFMap::create(const QString &path, bool *isDir)
Map *GEMFMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -14,7 +14,7 @@ public:
GEMFMap(const QString &fileName, QObject *parent = 0);
QRectF bounds();
RectC llBounds(const Projection &) {return _bounds;}
RectC llBounds() {return _bounds;}
int zoom() const {return _zi;}
void setZoom(int zoom) {_zi = zoom;}
@ -26,16 +26,18 @@ public:
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)
{_mapRatio = mapRatio;}
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
struct Region {

View File

@ -54,26 +54,28 @@ void GeoTIFFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
_img->draw(painter, rect, flags);
}
void GeoTIFFMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void GeoTIFFMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(in);
Q_UNUSED(out);
Q_UNUSED(deviceRatio);
_ratio = hidpi ? deviceRatio : 1.0;
_img = new Image(path());
_ratio = mapRatio;
if (_img)
_img->setDevicePixelRatio(_ratio);
}
void GeoTIFFMap::load()
{
if (!_img)
_img = new Image(path());
}
void GeoTIFFMap::unload()
{
delete _img;
_img = 0;
}
Map *GeoTIFFMap::create(const QString &path, bool *isDir)
Map *GeoTIFFMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -21,15 +21,14 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
Projection _projection;

View File

@ -18,21 +18,6 @@ using namespace IMG;
#define TILE_SIZE 384
#define TEXT_EXTENT 160
static RectC limitBounds(const RectC &bounds, const Projection &proj)
{
/* Limit the bounds for some well known projections
(world maps have N/S bounds up to 90/-90!) */
if (proj == PCS::pcs(3857) || proj == PCS::pcs(3395))
return bounds & OSM::BOUNDS;
else if (proj == PCS::pcs(3031) || proj == PCS::pcs(3976))
return bounds & RectC(Coordinates(-180, -60), Coordinates(180, -90));
else if (proj == PCS::pcs(3995) || proj == PCS::pcs(3413))
return bounds & RectC(Coordinates(-180, 90), Coordinates(180, 60));
else
return bounds;
}
static QList<MapData*> overlays(const QString &fileName)
{
QList<MapData*> list;
@ -71,27 +56,17 @@ IMGMap::IMGMap(const QString &fileName, bool GMAP, QObject *parent)
return;
}
_dataBounds = _data.first()->bounds() & OSM::BOUNDS;
_zoom = _data.first()->zooms().min();
updateTransform();
_valid = true;
}
void IMGMap::load(const Projection &in, const Projection &out,
qreal devicelRatio, bool hidpi)
void IMGMap::load()
{
Q_UNUSED(in);
Q_UNUSED(hidpi);
_tileRatio = devicelRatio;
_projection = out;
_dataBounds = limitBounds(_data.first()->bounds(), _projection);
for (int i = 0; i < _data.size(); i++)
_data.at(i)->load();
updateTransform();
QPixmapCache::clear();
}
void IMGMap::unload()
@ -286,7 +261,37 @@ void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
}
}
Map* IMGMap::createIMG(const QString &path, bool *isDir)
void IMGMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(mapRatio);
_tileRatio = deviceRatio;
}
void IMGMap::setOutputProjection(const Projection &projection)
{
if (!projection.isValid() || projection == _projection)
return;
_projection = projection;
// Limit the bounds for some well known projections
// (world maps have N/S bounds up to 90/-90!)
if (_projection == PCS::pcs(3857) || _projection == PCS::pcs(3395))
_dataBounds = _data.first()->bounds() & OSM::BOUNDS;
else if (_projection == PCS::pcs(3031) || _projection == PCS::pcs(3976))
_dataBounds = _data.first()->bounds() & RectC(Coordinates(-180, -60),
Coordinates(180, -90));
else if (_projection == PCS::pcs(3995) || _projection == PCS::pcs(3413))
_dataBounds = _data.first()->bounds() & RectC(Coordinates(-180, 90),
Coordinates(180, 60));
else
_dataBounds = _data.first()->bounds();
updateTransform();
QPixmapCache::clear();
}
Map* IMGMap::createIMG(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;
@ -294,7 +299,7 @@ Map* IMGMap::createIMG(const QString &path, bool *isDir)
return new IMGMap(path, false);
}
Map* IMGMap::createGMAP(const QString &path, bool *isDir)
Map* IMGMap::createGMAP(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = true;

View File

@ -55,7 +55,7 @@ public:
QString name() const {return _data.first()->name();}
QRectF bounds() {return _bounds;}
RectC llBounds(const Projection &) {return _data.first()->bounds();}
RectC llBounds() {return _dataBounds;}
int zoom() const {return _zoom;}
void setZoom(int zoom);
@ -70,15 +70,17 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal devicelRatio,
bool hidpi);
void setOutputProjection(const Projection &projection);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void load();
void unload();
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map* createIMG(const QString &path, bool *isDir);
static Map* createGMAP(const QString &path, bool *isDir);
static Map* createIMG(const QString &path, const Projection &, bool *isDir);
static Map* createGMAP(const QString &path, const Projection &, bool *isDir);
private slots:
void jobFinished(IMGMapJob *job);

View File

@ -11,6 +11,22 @@
#define ic2dc(x) ((x) * 180.0 / 0x7FFFFFFF)
struct Level {
quint32 count;
quint32 offset;
quint32 scale;
};
struct Ctx {
QPainter *painter;
QFile *file;
qreal ratio;
Ctx(QPainter *painter, QFile *file, qreal ratio)
: painter(painter), file(file), ratio(ratio) {}
};
template<class T> bool JNXMap::readValue(T &val)
{
T data;
@ -37,7 +53,7 @@ bool JNXMap::readString(QByteArray& ba)
}
}
bool JNXMap::readHeader()
bool JNXMap::readTiles()
{
qint32 lat1, lon2, lat2, lon1;
quint32 version, dummy, levels;
@ -72,22 +88,16 @@ bool JNXMap::readHeader()
}
_zooms.reserve(lh.size());
for (int i = 0; i < lh.count(); i++)
_zooms.append(new Zoom(lh.at(i)));
for (int i = 0; i < lh.count(); i++) {
_zooms.append(new Zoom());
Zoom *z = _zooms.last();
const Level &l = lh.at(i);
return true;
}
bool JNXMap::readTiles()
{
for (int i = 0; i < _zooms.size(); i++) {
Zoom *z = _zooms[i];
if (!_file.seek(z->level.offset))
if (!_file.seek(l.offset))
return false;
z->tiles = QVector<Tile>(z->level.count);
for (quint32 j = 0; j < z->level.count; j++) {
z->tiles = QVector<Tile>(l.count);
for (quint32 j = 0; j < l.count; j++) {
Tile &tile = z->tiles[j];
if (!(readValue(tile.top) && readValue(tile.right)
@ -124,25 +134,16 @@ bool JNXMap::readTiles()
return true;
}
void JNXMap::clearTiles()
{
for (int i = 0; i < _zooms.size(); i++) {
Zoom *z = _zooms[i];
z->tiles.clear();
z->tree.RemoveAll();
}
}
JNXMap::JNXMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _file(fileName), _zoom(0), _mapRatio(1.0),
_valid(false)
JNXMap::JNXMap(const QString &fileName, const Projection &proj, QObject *parent)
: Map(fileName, parent), _file(fileName), _zoom(0), _projection(proj),
_mapRatio(1.0), _valid(false)
{
if (!_file.open(QIODevice::ReadOnly)) {
_errorString = _file.errorString();
_errorString = fileName + ": " + _file.errorString();
return;
}
if (!readHeader()) {
if (!readTiles()) {
_errorString = "JNX file format error";
return;
}
@ -157,22 +158,14 @@ JNXMap::~JNXMap()
qDeleteAll(_zooms);
}
void JNXMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void JNXMap::load()
{
Q_UNUSED(out);
_projection = in;
_mapRatio = hidpi ? deviceRatio : 1.0;
if (_file.open(QIODevice::ReadOnly))
readTiles();
_file.open(QIODevice::ReadOnly);
}
void JNXMap::unload()
{
_file.close();
clearTiles();
}
QPointF JNXMap::ll2xy(const Coordinates &c)
@ -274,10 +267,51 @@ void JNXMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
tree.Search(min, max, cb, &ctx);
}
Map *JNXMap::create(const QString &path, bool *isDir)
void JNXMap::setInputProjection(const Projection &projection)
{
if (!projection.isValid() || projection == _projection)
return;
_projection = projection;
for (int i = 0; i < _zooms.size(); i++) {
Zoom *z = _zooms[i];
z->tree.RemoveAll();
for (int j = 0; j < z->tiles.size(); j++) {
Tile &tile = z->tiles[j];
RectC llrect(Coordinates(ic2dc(tile.left), ic2dc(tile.top)),
Coordinates(ic2dc(tile.right), ic2dc(tile.bottom)));
RectD rect(_projection.ll2xy(llrect.topLeft()),
_projection.ll2xy(llrect.bottomRight()));
if (j == 0) {
ReferencePoint tl(PointD(0, 0), rect.topLeft());
ReferencePoint br(PointD(tile.width, tile.height),
rect.bottomRight());
z->transform = Transform(tl, br);
}
QRectF trect(z->transform.proj2img(rect.topLeft()),
z->transform.proj2img(rect.bottomRight()));
tile.pos = trect.topLeft();
qreal min[2], max[2];
min[0] = trect.left();
min[1] = trect.top();
max[0] = trect.right();
max[1] = trect.bottom();
z->tree.Insert(min, max, &tile);
}
}
}
Map *JNXMap::create(const QString &path, const Projection &proj, bool *isDir)
{
if (isDir)
*isDir = false;
return new JNXMap(path);
return new JNXMap(path, proj);
}

View File

@ -15,11 +15,11 @@ public:
Q_OBJECT
public:
JNXMap(const QString &fileName, QObject *parent = 0);
JNXMap(const QString &fileName, const Projection &proj, QObject *parent = 0);
~JNXMap();
QRectF bounds();
RectC llBounds(const Projection &) {return _bounds;}
RectC llBounds() {return _bounds;}
int zoom() const {return _zoom;}
void setZoom(int zoom) {_zoom = zoom;}
@ -30,16 +30,19 @@ public:
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void setInputProjection(const Projection &projection);
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)
{_mapRatio = mapRatio;}
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &proj, bool *isDir);
private:
struct Tile {
@ -51,37 +54,15 @@ private:
QPointF pos;
};
struct Level {
quint32 count;
quint32 offset;
quint32 scale;
};
struct Zoom {
Zoom() {}
Zoom(const Level &level) : level(level) {}
Level level;
Transform transform;
QVector<Tile> tiles;
RTree<Tile*, qreal, 2> tree;
};
struct Ctx {
QPainter *painter;
QFile *file;
qreal ratio;
Ctx(QPainter *painter, QFile *file, qreal ratio)
: painter(painter), file(file), ratio(ratio) {}
};
template<class T> bool readValue(T &val);
bool readString(QByteArray &ba);
bool readHeader();
bool readTiles();
void clearTiles();
static bool cb(Tile *tile, void *context);
static QPixmap pixmap(const Tile *tile, QFile *file);

View File

@ -13,12 +13,14 @@
#include <QFileInfo>
#include <QXmlStreamReader>
#include <QBuffer>
#include <QImage>
#include <QImageReader>
#include <QBuffer>
#include <QPainter>
#include <QPixmapCache>
#include <private/qzipreader_p.h>
#include "common/util.h"
#include"common/util.h"
#include "pcs.h"
#include "image.h"
#include "kmzmap.h"
@ -27,140 +29,162 @@
#define TL(m) ((m).bbox().topLeft())
#define BR(m) ((m).bbox().bottomRight())
bool KMZMap::resCmp(const Tile &m1, const Tile &m2)
{
return m1.resolution() > m2.resolution();
}
bool KMZMap::xCmp(const Tile &m1, const Tile &m2)
KMZMap::Overlay::Overlay(const QString &path, const QSize &size,
const RectC &bbox, double rotation, const Projection *proj, qreal ratio)
: _path(path), _size(size), _bbox(bbox), _rotation(rotation), _img(0),
_proj(proj), _ratio(ratio)
{
return TL(m1).lon() < TL(m2).lon();
}
ReferencePoint tl(PointD(0, 0), _proj->ll2xy(bbox.topLeft()));
ReferencePoint br(PointD(size.width(), size.height()),
_proj->ll2xy(bbox.bottomRight()));
bool KMZMap::yCmp(const Tile &m1, const Tile &m2)
{
return TL(m1).lat() > TL(m2).lat();
}
QTransform t;
t.rotate(-rotation);
QRectF b(0, 0, size.width(), size.height());
QPolygonF ma = t.map(b);
_bounds = ma.boundingRect();
KMZMap::Tile::Tile(const Overlay &overlay, QZipReader &zip)
: _overlay(overlay)
{
QByteArray ba(zip.fileData(overlay.path()));
QBuffer img(&ba);
QImageReader ir(&img);
_size = ir.size();
}
void KMZMap::Tile::configure(const Projection &proj)
{
ReferencePoint tl(PointD(0, 0), proj.ll2xy(bbox().topLeft()));
ReferencePoint br(PointD(_size.width(), _size.height()),
proj.ll2xy(bbox().bottomRight()));
_transform = Transform(tl, br);
}
QRectF KMZMap::Tile::bounds() const
qreal KMZMap::Overlay::resolution(const QRectF &rect) const
{
QTransform t;
t.rotate(-rotation());
QRectF b(0, 0, _size.width(), _size.height());
QPolygonF ma(t.map(b));
return ma.boundingRect();
}
qreal cy = rect.center().y();
QPointF cl(rect.left(), cy);
QPointF cr(rect.right(), cy);
qreal KMZMap::Tile::resolution() const
{
QRectF d(0, 0, _size.width(), _size.height());
qreal dy = d.center().y();
QPointF dl(d.left(), dy);
QPointF dr(d.right(), dy);
double cy = bbox().center().lat();
Coordinates cl(bbox().left(), cy);
Coordinates cr(bbox().right(), cy);
qreal ds = cl.distanceTo(cr);
qreal ps = QLineF(dl, dr).length();
qreal ds = xy2ll(cl).distanceTo(xy2ll(cr));
qreal ps = QLineF(cl, cr).length();
return ds/ps;
}
bool KMZMap::createTiles(const QList<Overlay> &overlays, QZipReader &zip)
void KMZMap::Overlay::draw(QPainter *painter, const QRectF &rect, Flags flags)
{
if (overlays.isEmpty()) {
_errorString = "No usable overlay found";
return false;
if (_img) {
QRectF rr(rect.topLeft() / _ratio, rect.size());
if (_rotation) {
painter->save();
painter->rotate(-_rotation);
_img->draw(painter, rr, flags);
painter->restore();
} else
_img->draw(painter, rr, flags);
}
_tiles.reserve(overlays.size());
for (int i = 0; i < overlays.size(); i++) {
const Overlay &ol = overlays.at(i);
Tile tile(ol, zip);
if (tile.isValid())
_tiles.append(tile);
else {
_errorString = ol.path() + ": invalid/missing overlay image";
return false;
}
}
return true;
//painter->setPen(Qt::red);
//painter->drawRect(_bounds);
}
void KMZMap::computeLLBounds()
void KMZMap::Overlay::load(QZipReader *zip)
{
for (int i = 0; i < _tiles.size(); i++)
_llbounds |= _tiles.at(i).bbox();
if (!_img) {
QByteArray ba(zip->fileData(_path));
_img = new Image(QImage::fromData(ba));
_img->setDevicePixelRatio(_ratio);
}
}
void KMZMap::Overlay::unload()
{
delete _img;
_img = 0;
}
void KMZMap::Overlay::setProjection(const Projection *proj)
{
_proj = proj;
ReferencePoint tl(PointD(0, 0), _proj->ll2xy(_bbox.topLeft()));
ReferencePoint br(PointD(_size.width(), _size.height()),
_proj->ll2xy(_bbox.bottomRight()));
QTransform t;
t.rotate(-_rotation);
QRectF b(0, 0, _size.width(), _size.height());
QPolygonF ma = t.map(b);
_bounds = ma.boundingRect();
_transform = Transform(tl, br);
}
void KMZMap::Overlay::setDevicePixelRatio(qreal ratio)
{
_ratio = ratio;
if (_img)
_img->setDevicePixelRatio(_ratio);
}
bool KMZMap::resCmp(const Overlay &m1, const Overlay &m2)
{
qreal r1, r2;
r1 = m1.resolution(m1.bounds());
r2 = m2.resolution(m2.bounds());
return r1 > r2;
}
bool KMZMap::xCmp(const Overlay &m1, const Overlay &m2)
{
return TL(m1).lon() < TL(m2).lon();
}
bool KMZMap::yCmp(const Overlay &m1, const Overlay &m2)
{
return TL(m1).lat() > TL(m2).lat();
}
void KMZMap::computeZooms()
{
std::sort(_tiles.begin(), _tiles.end(), resCmp);
std::sort(_maps.begin(), _maps.end(), resCmp);
_zooms.append(Zoom(0, _tiles.count() - 1));
for (int i = 1; i < _tiles.count(); i++) {
qreal last = _tiles.at(i-1).resolution();
qreal cur = _tiles.at(i).resolution();
_zooms.append(Zoom(0, _maps.count() - 1));
for (int i = 1; i < _maps.count(); i++) {
qreal last = _maps.at(i-1).resolution(_maps.at(i).bounds());
qreal cur = _maps.at(i).resolution(_maps.at(i).bounds());
if (cur < last * ZOOM_THRESHOLD) {
_zooms.last().last = i-1;
_zooms.append(Zoom(i, _tiles.count() - 1));
_zooms.append(Zoom(i, _maps.count() - 1));
}
}
}
void KMZMap::computeBounds()
{
QVector<QPointF> offsets(_tiles.count());
QVector<QPointF> offsets(_maps.count());
for (int z = 0; z < _zooms.count(); z++) {
QList<Tile> m;
QList<Overlay> m;
for (int i = _zooms.at(z).first; i <= _zooms.at(z).last; i++)
m.append(_tiles.at(i));
m.append(_maps.at(i));
std::sort(m.begin(), m.end(), xCmp);
offsets[_tiles.indexOf(m.first())].setX(m.first().bounds().left());
offsets[_maps.indexOf(m.first())].setX(m.first().bounds().left());
for (int i = 1; i < m.size(); i++) {
qreal w = ll2xy(TL(m.at(i)), m.first().transform()).x();
offsets[_tiles.indexOf(m.at(i))].setX(w + m.at(i).bounds().left());
qreal w = m.first().ll2xy(TL(m.at(i))).x();
offsets[_maps.indexOf(m.at(i))].setX(w + m.at(i).bounds().left());
}
std::sort(m.begin(), m.end(), yCmp);
offsets[_tiles.indexOf(m.first())].setY(m.first().bounds().top());
offsets[_maps.indexOf(m.first())].setY(m.first().bounds().top());
for (int i = 1; i < m.size(); i++) {
qreal h = ll2xy(TL(m.at(i)), m.first().transform()).y();
offsets[_tiles.indexOf(m.at(i))].setY(h + m.at(i).bounds().top());
qreal h = m.first().ll2xy(TL(m.at(i))).y();
offsets[_maps.indexOf(m.at(i))].setY(h + m.at(i).bounds().top());
}
}
_adjust = 0;
_bounds = QVector<Bounds>(_tiles.count());
for (int i = 0; i < _tiles.count(); i++) {
QRectF xy(offsets.at(i), _tiles.at(i).bounds().size());
_bounds[i] = Bounds(_tiles.at(i).bbox(), xy);
_adjust = qMin(qMin(_tiles.at(i).bounds().left(),
_tiles.at(i).bounds().top()), _adjust);
_bounds = QVector<Bounds>(_maps.count());
for (int i = 0; i < _maps.count(); i++) {
QRectF xy(offsets.at(i), _maps.at(i).bounds().size());
_bounds[i] = Bounds(_maps.at(i).bbox(), xy);
_adjust = qMin(qMin(_maps.at(i).bounds().left(),
_maps.at(i).bounds().top()), _adjust);
}
_adjust = -_adjust;
}
@ -212,7 +236,7 @@ RectC KMZMap::latLonBox(QXmlStreamReader &reader, double *rotation)
return RectC(Coordinates(left, top), Coordinates(right, bottom));
}
void KMZMap::groundOverlay(QXmlStreamReader &reader, QList<Overlay> &overlays)
void KMZMap::groundOverlay(QXmlStreamReader &reader, QZipReader &zip)
{
QString image;
RectC rect;
@ -227,87 +251,93 @@ void KMZMap::groundOverlay(QXmlStreamReader &reader, QList<Overlay> &overlays)
reader.skipCurrentElement();
}
if (rect.isValid())
overlays.append(Overlay(image, rect, rotation));
if (rect.isValid()) {
QByteArray ba(zip.fileData(image));
QBuffer img(&ba);
QImageReader ir(&img);
QSize size(ir.size());
if (size.isValid())
_maps.append(Overlay(image, size, rect, rotation, &_projection,
_ratio));
else
reader.raiseError(image + ": Invalid image file");
} else
reader.raiseError("Invalid LatLonBox");
}
void KMZMap::document(QXmlStreamReader &reader, QList<Overlay> &overlays)
void KMZMap::document(QXmlStreamReader &reader, QZipReader &zip)
{
while (reader.readNextStartElement()) {
if (reader.name() == QLatin1String("Document"))
document(reader, overlays);
document(reader, zip);
else if (reader.name() == QLatin1String("GroundOverlay"))
groundOverlay(reader, overlays);
groundOverlay(reader, zip);
else if (reader.name() == QLatin1String("Folder"))
folder(reader, overlays);
folder(reader, zip);
else
reader.skipCurrentElement();
}
}
void KMZMap::folder(QXmlStreamReader &reader, QList<Overlay> &overlays)
void KMZMap::folder(QXmlStreamReader &reader, QZipReader &zip)
{
while (reader.readNextStartElement()) {
if (reader.name() == QLatin1String("GroundOverlay"))
groundOverlay(reader, overlays);
groundOverlay(reader, zip);
else if (reader.name() == QLatin1String("Folder"))
folder(reader, overlays);
folder(reader, zip);
else
reader.skipCurrentElement();
}
}
void KMZMap::kml(QXmlStreamReader &reader, QList<Overlay> &overlays)
void KMZMap::kml(QXmlStreamReader &reader, QZipReader &zip)
{
while (reader.readNextStartElement()) {
if (reader.name() == QLatin1String("Document"))
document(reader, overlays);
document(reader, zip);
else if (reader.name() == QLatin1String("GroundOverlay"))
groundOverlay(reader, overlays);
groundOverlay(reader, zip);
else if (reader.name() == QLatin1String("Folder"))
folder(reader, overlays);
folder(reader, zip);
else
reader.skipCurrentElement();
}
}
KMZMap::KMZMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _zoom(0), _mapIndex(-1), _zip(0), _mapRatio(1.0),
_valid(false)
KMZMap::KMZMap(const QString &fileName, const Projection &proj, QObject *parent)
: Map(fileName, parent), _zoom(0), _mapIndex(-1), _zip(0), _projection(proj),
_ratio(1.0), _valid(false)
{
QZipReader zip(fileName, QIODevice::ReadOnly);
QByteArray xml(zip.fileData("doc.kml"));
QXmlStreamReader reader(xml);
QList<Overlay> overlays;
if (reader.readNextStartElement()) {
if (reader.name() == QLatin1String("kml"))
kml(reader, overlays);
kml(reader, zip);
else
reader.raiseError("Not a KMZ file");
}
if (reader.error()) {
_errorString = "doc.kml:" + QString::number(reader.lineNumber()) + ": "
+ reader.errorString();
return;
}
if (!createTiles(overlays, zip))
if (_maps.isEmpty()) {
_errorString = "No usable GroundOverlay found";
return;
computeLLBounds();
}
computeZooms();
computeBounds();
_valid = true;
}
KMZMap::~KMZMap()
{
delete _zip;
}
QRectF KMZMap::bounds()
{
QRectF rect;
@ -334,9 +364,8 @@ int KMZMap::zoomFit(const QSize &size, const RectC &br)
if (!_bounds.at(i).ll.contains(br.center()))
continue;
QRect sbr = QRectF(ll2xy(br.topLeft(), _tiles.at(i).transform()),
ll2xy(br.bottomRight(), _tiles.at(i).transform()))
.toRect().normalized();
QRect sbr = QRectF(_maps.at(i).ll2xy(br.topLeft()),
_maps.at(i).ll2xy(br.bottomRight())).toRect().normalized();
if (sbr.size().width() > size.width()
|| sbr.size().height() > size.height())
@ -384,10 +413,10 @@ QPointF KMZMap::ll2xy(const Coordinates &c)
}
}
QPointF p = ll2xy(c, _tiles.at(_mapIndex).transform());
if (_tiles.at(_mapIndex).rotation()) {
QPointF p = _maps.at(_mapIndex).ll2xy(c);
if (_maps.at(_mapIndex).rotation()) {
QTransform matrix;
matrix.rotate(-_tiles.at(_mapIndex).rotation());
matrix.rotate(-_maps.at(_mapIndex).rotation());
return matrix.map(p) + _bounds.at(_mapIndex).xy.topLeft();
} else
return p + _bounds.at(_mapIndex).xy.topLeft();
@ -405,89 +434,90 @@ Coordinates KMZMap::xy2ll(const QPointF &p)
}
QPointF p2 = p - _bounds.at(idx).xy.topLeft();
if (_tiles.at(idx).rotation()) {
if (_maps.at(idx).rotation()) {
QTransform matrix;
matrix.rotate(_tiles.at(idx).rotation());
return xy2ll(matrix.map(p2), _tiles.at(idx).transform());
matrix.rotate(_maps.at(idx).rotation());
return _maps.at(idx).xy2ll(matrix.map(p2));
} else
return xy2ll(p2, _tiles.at(idx).transform());
return _maps.at(idx).xy2ll(p2);
}
void KMZMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{
Q_UNUSED(flags);
QRectF er = rect.adjusted(-_adjust * _mapRatio, -_adjust * _mapRatio,
_adjust * _mapRatio, _adjust * _mapRatio);
QRectF er = rect.adjusted(-_adjust * _ratio, -_adjust * _ratio,
_adjust * _ratio, _adjust * _ratio);
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
QRectF ir = er.intersected(_bounds.at(i).xy);
if (!ir.isNull())
draw(painter, ir, i);
draw(painter, ir, i, flags);
}
}
void KMZMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void KMZMap::load()
{
Q_UNUSED(out);
_projection = in;
_mapRatio = hidpi ? deviceRatio : 1.0;
for (int i = 0; i < _tiles.size(); i++)
_tiles[i].configure(_projection);
computeBounds();
Q_ASSERT(!_zip);
_zip = new QZipReader(path(), QIODevice::ReadOnly);
}
void KMZMap::unload()
{
_bounds.clear();
for (int i = 0; i < _maps.count(); i++)
_maps[i].unload();
delete _zip;
_zip = 0;
}
void KMZMap::draw(QPainter *painter, const QRectF &rect, int mapIndex)
void KMZMap::setInputProjection(const Projection &projection)
{
const Tile &map = _tiles.at(mapIndex);
if (!projection.isValid() || projection == _projection)
return;
_projection = projection;
for (int i = 0; i < _maps.size(); i++)
_maps[i].setProjection(&_projection);
_bounds.clear();
computeBounds();
}
void KMZMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
if (mapRatio == _ratio)
return;
_ratio = mapRatio;
for (int i = 0; i < _maps.size(); i++)
_maps[i].setDevicePixelRatio(_ratio);
_bounds.clear();
computeBounds();
}
void KMZMap::draw(QPainter *painter, const QRectF &rect, int mapIndex,
Flags flags)
{
Overlay &map = _maps[mapIndex];
const QPointF offset = _bounds.at(mapIndex).xy.topLeft();
QRectF pr = QRectF(rect.topLeft() - offset, rect.size());
QRectF sr(pr.topLeft() * _mapRatio, pr.size() * _mapRatio);
QString key(path() + "/" + map.path());
QPixmap pm;
map.load(_zip);
painter->save();
painter->translate(offset);
if (map.rotation())
painter->rotate(-map.rotation());
if (QPixmapCache::find(key, &pm)) {
pm.setDevicePixelRatio(_mapRatio);
painter->drawPixmap(pr.topLeft(), pm, sr);
} else {
QByteArray ba(_zip->fileData(map.path()));
QImage img(QImage::fromData(ba));
pm = QPixmap::fromImage(img);
pm.setDevicePixelRatio(_mapRatio);
painter->drawPixmap(pr.topLeft(), pm, sr);
QPixmapCache::insert(key, pm);
}
//painter->setPen(Qt::red);
//painter->drawRect(map.bounds());
map.draw(painter, pr, flags);
painter->restore();
}
Map *KMZMap::create(const QString &path, bool *isDir)
Map *KMZMap::create(const QString &path, const Projection &proj, bool *isDir)
{
if (isDir)
*isDir = false;
return new KMZMap(path);
return new KMZMap(path, proj);
}

View File

@ -1,7 +1,6 @@
#ifndef KMZMAP_H
#define KMZMAP_H
#include <QImage>
#include "projection.h"
#include "transform.h"
#include "rectd.h"
@ -9,16 +8,15 @@
class QXmlStreamReader;
class QZipReader;
class Image;
class KMZMap : public Map
{
Q_OBJECT
public:
KMZMap(const QString &fileName, QObject *parent = 0);
~KMZMap();
KMZMap(const QString &fileName, const Projection &proj, QObject *parent = 0);
RectC llBounds(const Projection &) {return _llbounds;}
QRectF bounds();
int zoom() const {return _zoom;}
@ -32,52 +30,54 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setInputProjection(const Projection &projection);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &proj, bool *isDir);
private:
class Overlay {
public:
Overlay(const QString &path, const RectC &bbox, double rotation)
: _path(path), _bbox(bbox), _rotation(rotation) {}
Overlay(const QString &path, const QSize &size, const RectC &bbox,
double rotation, const Projection *proj, qreal ratio);
bool operator==(const Overlay &other) const
{return _path == other._path;}
QPointF ll2xy(const Coordinates &c) const
{return QPointF(_transform.proj2img(_proj->ll2xy(c))) / _ratio;}
Coordinates xy2ll(const QPointF &p) const
{return _proj->xy2ll(_transform.img2proj(p * _ratio));}
const QString &path() const {return _path;}
const RectC &bbox() const {return _bbox;}
const QRectF &bounds() const {return _bounds;}
qreal resolution(const QRectF &rect) const;
qreal rotation() const {return _rotation;}
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(QZipReader *zip);
void unload();
void setProjection(const Projection *proj);
void setDevicePixelRatio(qreal ratio);
private:
QString _path;
QSize _size;
QRectF _bounds;
RectC _bbox;
qreal _rotation;
};
class Tile {
public:
Tile(const Overlay &overlay, QZipReader &zip);
bool operator==(const Tile &other) const
{return _overlay.path() == other._overlay.path();}
bool isValid() const {return _size.isValid();}
const QString &path() const {return _overlay.path();}
qreal rotation() const {return _overlay.rotation();}
const RectC &bbox() const {return _overlay.bbox();}
const Transform &transform() const {return _transform;}
QRectF bounds() const;
qreal resolution() const;
void configure(const Projection &proj);
private:
Overlay _overlay;
QSize _size;
Image *_img;
const Projection *_proj;
Transform _transform;
qreal _ratio;
};
struct Zoom {
@ -96,32 +96,23 @@ private:
Bounds(const RectC &ll, const QRectF &xy) : ll(ll), xy(xy) {}
};
void kml(QXmlStreamReader &reader, QList<Overlay> &overlays);
void document(QXmlStreamReader &reader, QList<Overlay> &overlays);
void folder(QXmlStreamReader &reader, QList<Overlay> &overlays);
void groundOverlay(QXmlStreamReader &reader, QList<Overlay> &overlays);
void kml(QXmlStreamReader &reader, QZipReader &zip);
void document(QXmlStreamReader &reader, QZipReader &zip);
void folder(QXmlStreamReader &reader, QZipReader &zip);
void groundOverlay(QXmlStreamReader &reader, QZipReader &zip);
RectC latLonBox(QXmlStreamReader &reader, double *rotation);
QString icon(QXmlStreamReader &reader);
double number(QXmlStreamReader &reader);
void draw(QPainter *painter, const QRectF &rect, int mapIndex);
bool createTiles(const QList<Overlay> &overlays, QZipReader &zip);
void draw(QPainter *painter, const QRectF &rect, int mapIndex, Flags flags);
void computeZooms();
void computeBounds();
void computeLLBounds();
QPointF ll2xy(const Coordinates &c, const Transform &transform) const
{return QPointF(transform.proj2img(_projection.ll2xy(c))) / _mapRatio;}
Coordinates xy2ll(const QPointF &p, const Transform &transform) const
{return _projection.xy2ll(transform.img2proj(p * _mapRatio));}
static bool resCmp(const Overlay &m1, const Overlay &m2);
static bool xCmp(const Overlay &m1, const Overlay &m2);
static bool yCmp(const Overlay &m1, const Overlay &m2);
static bool resCmp(const Tile &m1, const Tile &m2);
static bool xCmp(const Tile &m1, const Tile &m2);
static bool yCmp(const Tile &m1, const Tile &m2);
RectC _llbounds;
QList<Tile> _tiles;
QList<Overlay> _maps;
QVector<Zoom> _zooms;
QVector<Bounds> _bounds;
int _zoom;
@ -129,7 +120,7 @@ private:
QZipReader *_zip;
qreal _adjust;
Projection _projection;
qreal _mapRatio;
qreal _ratio;
bool _valid;
QString _errorString;

View File

@ -37,12 +37,8 @@ void Map::growBottom(const QPointF &p, RectC &rect)
rect.setBottom(c.lat());
}
RectC Map::llBounds(const Projection &proj)
RectC Map::llBounds()
{
Q_UNUSED(proj);
/* We use bounds() and xy2ll() here as this fallback implementation is
used ONLY for maps providing those functions since map creation. */
QRectF b(bounds());
double dx = b.width() / SAMPLES;
double dy = b.height() / SAMPLES;

View File

@ -28,19 +28,10 @@ public:
: QObject(parent), _path(path) {}
virtual ~Map() {}
/* Functions available since map creation */
const QString &path() const {return _path;}
virtual QString name() const {return Util::file2name(path());}
virtual RectC llBounds(const Projection &proj);
virtual bool isValid() const {return true;}
virtual bool isReady() const {return true;}
virtual QString errorString() const {return QString();}
/* Functions that shall be called after load() */
virtual void load(const Projection &, const Projection &, qreal, bool) {}
virtual void unload() {}
virtual RectC llBounds();
virtual QRectF bounds() = 0;
virtual qreal resolution(const QRectF &rect);
@ -56,6 +47,15 @@ public:
virtual void draw(QPainter *painter, const QRectF &rect, Flags flags) = 0;
virtual void clearCache() {}
virtual void load() {}
virtual void unload() {}
virtual void setDevicePixelRatio(qreal, qreal) {}
virtual void setOutputProjection(const Projection &) {}
virtual void setInputProjection(const Projection &) {}
virtual bool isValid() const {return true;}
virtual bool isReady() const {return true;}
virtual QString errorString() const {return QString();}
signals:
void tilesLoaded();

View File

@ -62,7 +62,7 @@ MapList::ParserMap MapList::parsers()
MapList::ParserMap MapList::_parsers = parsers();
Map *MapList::loadFile(const QString &path, bool *isDir)
Map *MapList::loadFile(const QString &path, const Projection &proj, bool *isDir)
{
ParserMap::iterator it;
QFileInfo fi(path);
@ -73,7 +73,7 @@ Map *MapList::loadFile(const QString &path, bool *isDir)
if ((it = _parsers.find(suffix)) != _parsers.end()) {
while (it != _parsers.end() && it.key() == suffix) {
delete map;
map = it.value()(path, isDir);
map = it.value()(path, proj, isDir);
if (map->isValid())
return map;
else
@ -82,7 +82,7 @@ Map *MapList::loadFile(const QString &path, bool *isDir)
}
} else {
for (it = _parsers.begin(); it != _parsers.end(); it++) {
map = it.value()(path, isDir);
map = it.value()(path, proj, isDir);
if (map->isValid())
return map;
else {
@ -100,7 +100,8 @@ Map *MapList::loadFile(const QString &path, bool *isDir)
return map ? map : new InvalidMap(path, "Unknown file format");
}
TreeNode<Map*> MapList::loadDir(const QString &path, TreeNode<Map*> *parent)
TreeNode<Map *> MapList::loadDir(const QString &path, const Projection &proj,
TreeNode<Map *> *parent)
{
QDir md(path);
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
@ -117,12 +118,12 @@ TreeNode<Map*> MapList::loadDir(const QString &path, TreeNode<Map*> *parent)
QString suffix = fi.suffix().toLower();
if (fi.isDir()) {
TreeNode<Map*> child(loadDir(fi.absoluteFilePath(), &tree));
TreeNode<Map*> child(loadDir(fi.absoluteFilePath(), proj, &tree));
if (!child.isEmpty())
tree.addChild(child);
} else if (filter().contains("*." + suffix)) {
bool isDir = false;
Map *map = loadFile(fi.absoluteFilePath(), &isDir);
Map *map = loadFile(fi.absoluteFilePath(), proj, &isDir);
if (isDir) {
if (parent)
parent->addItem(map);
@ -137,13 +138,13 @@ TreeNode<Map*> MapList::loadDir(const QString &path, TreeNode<Map*> *parent)
return tree;
}
TreeNode<Map *> MapList::loadMaps(const QString &path)
TreeNode<Map *> MapList::loadMaps(const QString &path, const Projection &proj)
{
if (QFileInfo(path).isDir())
return loadDir(path);
return loadDir(path, proj);
else {
TreeNode<Map*> tree;
tree.addItem(loadFile(path));
tree.addItem(loadFile(path, proj));
return tree;
}
}

View File

@ -10,16 +10,18 @@ class Projection;
class MapList
{
public:
static TreeNode<Map*> loadMaps(const QString &path);
static TreeNode<Map*> loadMaps(const QString &path, const Projection &proj);
static QString formats();
static QStringList filter();
private:
typedef Map*(*ParserCb)(const QString &, bool *isDir);
typedef Map*(*ParserCb)(const QString &, const Projection &, bool *isDir);
typedef QMultiMap<QString, ParserCb> ParserMap;
static Map *loadFile(const QString &path, bool *isDir = 0);
static TreeNode<Map*> loadDir(const QString &path, TreeNode<Map*> *parent = 0);
static Map *loadFile(const QString &path, const Projection &proj,
bool *isDir = 0);
static TreeNode<Map*> loadDir(const QString &path, const Projection &proj,
TreeNode<Map *> *parent = 0);
static ParserMap parsers();
static ParserMap _parsers;

View File

@ -15,25 +15,16 @@ MapsforgeMap::MapsforgeMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _data(fileName), _zoom(0),
_projection(PCS::pcs(3857)), _tileRatio(1.0)
{
if (_data.isValid())
if (_data.isValid()) {
_zoom = _data.zooms().min();
updateTransform();
}
}
void MapsforgeMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void MapsforgeMap::load()
{
Q_UNUSED(in);
Q_UNUSED(hidpi);
_tileRatio = deviceRatio;
_projection = out;
_data.load();
_style.load(_data, _tileRatio);
updateTransform();
QPixmapCache::clear();
}
void MapsforgeMap::unload()
@ -234,7 +225,24 @@ void MapsforgeMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
}
}
Map *MapsforgeMap::create(const QString &path, bool *isMap)
void MapsforgeMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(mapRatio);
_tileRatio = deviceRatio;
}
void MapsforgeMap::setOutputProjection(const Projection &projection)
{
if (!projection.isValid() || projection == _projection)
return;
_projection = projection;
updateTransform();
QPixmapCache::clear();
}
Map *MapsforgeMap::create(const QString &path, const Projection &, bool *isMap)
{
if (isMap)
*isMap = false;

View File

@ -52,7 +52,7 @@ public:
MapsforgeMap(const QString &fileName, QObject *parent = 0);
QRectF bounds() {return _bounds;}
RectC llBounds(const Projection &) {return _data.bounds();}
RectC llBounds() {return _data.bounds();}
int zoom() const {return _zoom;}
void setZoom(int zoom);
@ -60,9 +60,10 @@ public:
int zoomIn();
int zoomOut();
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setOutputProjection(const Projection &projection);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
QPointF ll2xy(const Coordinates &c)
{return _transform.proj2img(_projection.ll2xy(c));}
@ -74,7 +75,7 @@ public:
bool isValid() const {return _data.isValid();}
QString errorString() const {return _data.errorString();}
static Map *create(const QString &path, bool *isMap);
static Map *create(const QString &path, const Projection &, bool *isMap);
private slots:
void jobFinished(MapsforgeMapJob *job);

View File

@ -206,8 +206,9 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
}
}
Map *MapSource::create(const QString &path, bool *isDir)
Map *MapSource::create(const QString &path, const Projection &proj, bool *isDir)
{
Q_UNUSED(proj);
Config config;
QFile file(path);

View File

@ -15,7 +15,7 @@ class Projection;
class MapSource
{
public:
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &proj, bool *isDir);
private:
enum Type {

View File

@ -165,19 +165,8 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
_valid = true;
}
void MBTilesMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void MBTilesMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
if (_scalable) {
_scaledSize = _tileSize * deviceRatio;
_tileRatio = deviceRatio;
}
_db.open();
}
@ -229,6 +218,16 @@ int MBTilesMap::zoomOut()
return _zi;
}
void MBTilesMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
_mapRatio = mapRatio;
if (_scalable) {
_scaledSize = _tileSize * deviceRatio;
_tileRatio = deviceRatio;
}
}
qreal MBTilesMap::coordinatesRatio() const
{
return _mapRatio > 1.0 ? _mapRatio / _tileRatio : 1.0;
@ -338,7 +337,7 @@ Coordinates MBTilesMap::xy2ll(const QPointF &p)
* coordinatesRatio());
}
Map *MBTilesMap::create(const QString &path, bool *isDir)
Map *MBTilesMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -13,7 +13,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds(const Projection &) {return _bounds;}
RectC llBounds() {return _bounds;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zi;}
@ -27,14 +27,14 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
qreal tileSize() const;

View File

@ -13,8 +13,8 @@ OnlineMap::OnlineMap(const QString &fileName, const QString &name,
const Authorization &authorization, int tileSize, bool scalable, bool invertY,
bool quadTiles, QObject *parent)
: Map(fileName, parent), _name(name), _zooms(zooms), _bounds(bounds),
_zoom(_zooms.max()), _tileSize(tileSize), _mapRatio(1.0),
_tileRatio(tileRatio), _scalable(scalable), _invertY(invertY)
_zoom(_zooms.max()), _mapRatio(1.0), _tileRatio(tileRatio),
_tileSize(tileSize), _scalable(scalable), _invertY(invertY)
{
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
this);
@ -70,13 +70,9 @@ int OnlineMap::zoomOut()
return _zoom;
}
void OnlineMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void OnlineMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_mapRatio = mapRatio;
if (_scalable) {
_tileLoader->setScaledSize(_tileSize * deviceRatio);

View File

@ -19,7 +19,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds(const Projection &) {return _bounds;}
RectC llBounds() {return _bounds;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}
@ -33,8 +33,7 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void clearCache() {_tileLoader->clearCache();}
private:
@ -48,8 +47,8 @@ private:
Range _zooms;
RectC _bounds;
int _zoom;
int _tileSize;
qreal _mapRatio, _tileRatio;
int _tileSize;
bool _scalable;
bool _invertY;
};

View File

@ -487,14 +487,8 @@ int OruxMap::zoomOut()
return _zoom;
}
void OruxMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void OruxMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
if (_db.isValid())
_db.open();
}
@ -505,6 +499,12 @@ void OruxMap::unload()
_db.close();
}
void OruxMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
_mapRatio = mapRatio;
}
QPixmap OruxMap::tile(const Zoom &z, int x, int y) const
{
if (_db.isValid()) {
@ -590,7 +590,7 @@ Coordinates OruxMap::xy2ll(const QPointF &p)
return z.projection.xy2ll(z.transform.img2proj(p * _mapRatio));
}
Map *OruxMap::create(const QString &path, bool *isDir)
Map *OruxMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = true;

View File

@ -33,14 +33,14 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void load();
void unload();
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
struct Zoom {

View File

@ -152,13 +152,8 @@ OsmdroidMap::OsmdroidMap(const QString &fileName, QObject *parent)
_valid = true;
}
void OsmdroidMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void OsmdroidMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_db.open();
}
@ -213,6 +208,12 @@ int OsmdroidMap::zoomOut()
return _zoom;
}
void OsmdroidMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
_mapRatio = mapRatio;
}
qreal OsmdroidMap::tileSize() const
{
return (_tileSize / _mapRatio);
@ -309,7 +310,7 @@ Coordinates OsmdroidMap::xy2ll(const QPointF &p)
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale) * _mapRatio);
}
Map *OsmdroidMap::create(const QString &path, bool *isDir)
Map *OsmdroidMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -11,7 +11,7 @@ public:
OsmdroidMap(const QString &fileName, QObject *parent = 0);
QRectF bounds();
RectC llBounds(const Projection &) {return _bounds;}
RectC llBounds() {return _bounds;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}
@ -25,14 +25,14 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
int limitZoom(int zoom) const;

View File

@ -182,9 +182,6 @@ bool OZF::open()
if (!_file.open(QIODevice::ReadOnly))
return false;
if (!_zooms.isEmpty())
return true;
if (!readHeaders()) {
qWarning("%s: Invalid header", qPrintable(_file.fileName()));
_file.close();
@ -235,6 +232,7 @@ QPixmap OZF::tile(int zoom, int x, int y)
QSize OZF::size(int zoom) const
{
Q_ASSERT(_file.isOpen());
Q_ASSERT(0 <= zoom && zoom < _zooms.count());
return _zooms.at(zoom).size;

View File

@ -16,7 +16,6 @@ public:
_file(name) {}
bool open();
void close() {_file.close();}
QString fileName() const {return _file.fileName();}
bool isOpen() const {return _file.isOpen();}

View File

@ -50,8 +50,6 @@ OziMap::OziMap(const QString &fileName, bool TAR, QObject *parent)
if (!setTileInfo(_tar->files()))
return;
_tar->close();
} else {
QFile file(fileName);
MapFile mf(file);
@ -107,16 +105,6 @@ OziMap::OziMap(const QString &fileName, Tar &tar, QObject *parent)
_transform = mf.transform();
_tar = new Tar(fi.absolutePath() + "/" + fi.completeBaseName() + ".tar");
if (!_tar->open()) {
_errorString = _tar->fileName() + ": error reading tar file";
return;
}
if (!setTileInfo(_tar->files())) {
_errorString = _tar->fileName() + ": " + _errorString;
return;
}
_tar->close();
_valid = true;
}
@ -156,7 +144,6 @@ bool OziMap::setImageInfo(const QString &path)
return false;
}
_scale = _ozf->scale(_zoom);
_ozf->close();
} else {
QImageReader ir(_map.path);
if (!ir.canRead()) {
@ -205,42 +192,28 @@ bool OziMap::setTileInfo(const QStringList &tiles, const QString &path)
return false;
}
void OziMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void OziMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
if (_tar) {
Q_ASSERT(!_tar->isOpen());
if (!_tar->open())
if (_tar && !_tar->isOpen()) {
if (!_tar->open()) {
qWarning("%s: error loading tar file",
qPrintable(_tar->fileName()));
return;
}
if (_ozf) {
Q_ASSERT(!_ozf->isOpen());
if (!_ozf->open())
if (!setTileInfo(_tar->files()))
qWarning("%s: %s", qPrintable(_tar->fileName()),
qPrintable(_errorString));
return;
}
if (!_tile.isValid() && !_ozf) {
Q_ASSERT(!_img);
if (!_tile.isValid() && !_ozf && !_img)
_img = new Image(_map.path);
if (_img)
_img->setDevicePixelRatio(_mapRatio);
}
}
void OziMap::unload()
{
delete _img;
_img = 0;
if (_tar && _tar->isOpen())
_tar->close();
if (_ozf && _ozf->isOpen())
_ozf->close();
}
void OziMap::drawTiled(QPainter *painter, const QRectF &rect) const
@ -395,7 +368,16 @@ void OziMap::rescale(int zoom)
_scale = _ozf->scale(zoom);
}
Map *OziMap::createTAR(const QString &path, bool *isDir)
void OziMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
_mapRatio = mapRatio;
if (_img)
_img->setDevicePixelRatio(_mapRatio);
}
Map *OziMap::createTAR(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;
@ -403,7 +385,7 @@ Map *OziMap::createTAR(const QString &path, bool *isDir)
return new OziMap(path, true);
}
Map *OziMap::createMAP(const QString &path, bool *isDir)
Map *OziMap::createMAP(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -33,8 +33,8 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void load();
void unload();
bool isValid() const {return _valid;}
@ -47,8 +47,8 @@ public:
QPointF pp2xy(const PointD &p) const
{return _transform.proj2img(p) / _mapRatio;}
static Map *createTAR(const QString &path, bool *isDir);
static Map *createMAP(const QString &path, bool *isDir);
static Map *createTAR(const QString &path, const Projection &, bool *isDir);
static Map *createMAP(const QString &path, const Projection &, bool *isDir);
private:
struct ImageInfo {

View File

@ -354,13 +354,8 @@ QCTMap::QCTMap(const QString &fileName, QObject *parent)
_valid = true;
}
void QCTMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void QCTMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_file.open(QIODevice::ReadOnly);
}
@ -491,7 +486,7 @@ void QCTMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
}
}
Map *QCTMap::create(const QString &path, bool *isDir)
Map *QCTMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -21,14 +21,16 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)
{_mapRatio = mapRatio;}
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
bool readName(QDataStream &stream);

View File

@ -355,13 +355,8 @@ Coordinates RMap::xy2ll(const QPointF &p)
p.y() / scale.y()) * _mapRatio));
}
void RMap::load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi)
void RMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_file.open(QIODevice::ReadOnly);
}
@ -460,7 +455,13 @@ void RMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
}
}
Map *RMap::create(const QString &path, bool *isDir)
void RMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
_mapRatio = mapRatio;
}
Map *RMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -25,8 +25,8 @@ public:
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void load();
void unload();
void draw(QPainter *painter, const QRectF &rect, Flags flags);
@ -34,7 +34,7 @@ public:
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
struct Header {

View File

@ -100,13 +100,8 @@ SqliteMap::SqliteMap(const QString &fileName, QObject *parent)
_valid = true;
}
void SqliteMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void SqliteMap::load()
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_db.open();
}
@ -161,6 +156,12 @@ int SqliteMap::zoomOut()
return _zoom;
}
void SqliteMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(deviceRatio);
_mapRatio = mapRatio;
}
qreal SqliteMap::tileSize() const
{
return (_tileSize / _mapRatio);
@ -256,7 +257,7 @@ Coordinates SqliteMap::xy2ll(const QPointF &p)
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale) * _mapRatio);
}
Map *SqliteMap::create(const QString &path, bool *isDir)
Map *SqliteMap::create(const QString &path, const Projection &, bool *isDir)
{
if (isDir)
*isDir = false;

View File

@ -11,7 +11,7 @@ public:
SqliteMap(const QString &fileName, QObject *parent = 0);
QRectF bounds();
RectC llBounds(const Projection &) {return _bounds;}
RectC llBounds() {return _bounds;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}
@ -25,14 +25,14 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &, bool *isDir);
private:
int limitZoom(int zoom) const;

View File

@ -49,9 +49,6 @@ bool Tar::open()
if (!_file.open(QIODevice::ReadOnly))
return false;
if (!_index.isEmpty())
return true;
QFileInfo fi(_file.fileName());
QString tmiPath = fi.path() + "/" + fi.completeBaseName() + ".tmi";

View File

@ -11,7 +11,6 @@ public:
Tar(const QString &name) : _file(name) {}
bool open();
void close() {_file.close();}
QStringList files() const {return _index.keys();}
QByteArray file(const QString &name);

View File

@ -99,15 +99,6 @@ void WMSMap::wmsReady()
emit mapLoaded();
}
void WMSMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
}
void WMSMap::clearCache()
{
_tileLoader->clearCache();

View File

@ -20,7 +20,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds(const Projection &) {return _wms->bbox();}
RectC llBounds() {return _wms->bbox();}
int zoom() const {return _zoom;}
void setZoom(int zoom);
@ -33,8 +33,8 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)
{_mapRatio = mapRatio;}
void clearCache();
bool isReady() const {return _wms->isReady();}

View File

@ -44,15 +44,6 @@ void WMTSMap::wmtsReady()
emit mapLoaded();
}
void WMTSMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
{
Q_UNUSED(in);
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
}
void WMTSMap::clearCache()
{
_tileLoader->clearCache();
@ -106,7 +97,7 @@ QRectF WMTSMap::bounds()
return lb.isValid() ? lb & tb : tb;
}
RectC WMTSMap::llBounds(const Projection &)
RectC WMTSMap::llBounds()
{
if (_wmts->bbox().isValid())
return _wmts->bbox();

View File

@ -20,7 +20,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds(const Projection &);
RectC llBounds();
int zoom() const {return _zoom;}
void setZoom(int zoom);
@ -33,8 +33,8 @@ public:
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)
{_mapRatio = mapRatio;}
void clearCache();
bool isReady() const {return _wmts->isReady();}

View File

@ -9,8 +9,9 @@
#include "worldfilemap.h"
WorldFileMap::WorldFileMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _img(0), _mapRatio(1.0), _hasPRJ(false), _valid(false)
WorldFileMap::WorldFileMap(const QString &fileName, const Projection &proj,
QObject *parent) : Map(fileName, parent), _projection(proj), _img(0),
_ratio(1.0), _hasPRJ(false), _valid(false)
{
QFileInfo fi(fileName);
QDir dir(fi.absoluteDir());
@ -73,25 +74,17 @@ WorldFileMap::~WorldFileMap()
QPointF WorldFileMap::ll2xy(const Coordinates &c)
{
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _mapRatio;
return QPointF(_transform.proj2img(_projection.ll2xy(c))) / _ratio;
}
Coordinates WorldFileMap::xy2ll(const QPointF &p)
{
return _projection.xy2ll(_transform.img2proj(p * _mapRatio));
}
RectC WorldFileMap::llBounds(const Projection &proj)
{
if (_projection.isNull())
_projection = proj;
return Map::llBounds(proj);
return _projection.xy2ll(_transform.img2proj(p * _ratio));
}
QRectF WorldFileMap::bounds()
{
return QRectF(QPointF(0, 0), _size / _mapRatio);
return QRectF(QPointF(0, 0), _size / _ratio);
}
void WorldFileMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
@ -100,20 +93,19 @@ void WorldFileMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
_img->draw(painter, rect, flags);
}
void WorldFileMap::load(const Projection &in, const Projection &out,
qreal deviceRatio, bool hidpi)
void WorldFileMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{
Q_UNUSED(out);
Q_UNUSED(deviceRatio);
if (!_hasPRJ)
_projection = in;
_mapRatio = hidpi ? deviceRatio : 1.0;
Q_ASSERT(!_img);
_img = new Image(_imgFile);
_ratio = mapRatio;
if (_img)
_img->setDevicePixelRatio(_mapRatio);
_img->setDevicePixelRatio(_ratio);
}
void WorldFileMap::load()
{
if (!_img)
_img = new Image(_imgFile);
}
void WorldFileMap::unload()
@ -122,10 +114,19 @@ void WorldFileMap::unload()
_img = 0;
}
Map *WorldFileMap::create(const QString &path, bool *isDir)
void WorldFileMap::setInputProjection(const Projection &projection)
{
if (_hasPRJ || !projection.isValid() || projection == _projection)
return;
_projection = projection;
}
Map *WorldFileMap::create(const QString &path, const Projection &proj,
bool *isDir)
{
if (isDir)
*isDir = false;
return new WorldFileMap(path);
return new WorldFileMap(path, proj);
}

View File

@ -12,31 +12,32 @@ class WorldFileMap : public Map
Q_OBJECT
public:
WorldFileMap(const QString &fileName, QObject *parent = 0);
WorldFileMap(const QString &fileName, const Projection &proj,
QObject *parent = 0);
~WorldFileMap();
RectC llBounds(const Projection &proj);
QRectF bounds();
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
void load();
void unload();
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void setInputProjection(const Projection &projection);
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, bool *isDir);
static Map *create(const QString &path, const Projection &proj, bool *isDir);
private:
Projection _projection;
Transform _transform;
Image *_img;
QSize _size;
qreal _mapRatio;
qreal _ratio;
QString _imgFile;
bool _hasPRJ;