1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Added support for map layers selection

Enable selecting only raster or only vector layers when showing Garmin maps.
This commit is contained in:
Martin Tůma 2024-09-11 23:52:30 +02:00
parent e33c74bdd7
commit 52c6773b7e
10 changed files with 125 additions and 17 deletions

View File

@ -364,6 +364,21 @@ void GUI::createActions()
_showCoordinatesAction->setCheckable(true);
connect(_showCoordinatesAction, &QAction::triggered, _mapView,
&MapView::showCursorCoordinates);
QActionGroup *mapLayersGroup = new QActionGroup(this);
connect(mapLayersGroup, &QActionGroup::triggered, this,
&GUI::selectMapLayers);
_drawAllAction = new QAction(tr("All"), this);
_drawAllAction->setMenuRole(QAction::NoRole);
_drawAllAction->setCheckable(true);
_drawAllAction->setActionGroup(mapLayersGroup);
_drawRastersAction = new QAction(tr("Raster only"), this);
_drawRastersAction->setMenuRole(QAction::NoRole);
_drawRastersAction->setCheckable(true);
_drawRastersAction->setActionGroup(mapLayersGroup);
_drawVectorsAction = new QAction(tr("Vector only"), this);
_drawVectorsAction->setMenuRole(QAction::NoRole);
_drawVectorsAction->setCheckable(true);
_drawVectorsAction->setActionGroup(mapLayersGroup);
// Position
_showPositionAction = new QAction(QIcon::fromTheme(SHOW_POS_NAME,
@ -677,6 +692,11 @@ void GUI::createMenus()
_mapMenu->addAction(_loadMapDirAction);
_mapMenu->addAction(_clearMapCacheAction);
_mapMenu->addSeparator();
QMenu *layersMenu = _mapMenu->addMenu(tr("Layers"));
layersMenu->menuAction()->setMenuRole(QAction::NoRole);
layersMenu->addAction(_drawAllAction);
layersMenu->addAction(_drawRastersAction);
layersMenu->addAction(_drawVectorsAction);
_mapMenu->addAction(_showCoordinatesAction);
_mapMenu->addSeparator();
_mapMenu->addAction(_showMapAction);
@ -1462,7 +1482,7 @@ void GUI::plotMainPage(QPainter *painter, const QRectF &rect, qreal ratio,
sc = 1;
}
MapView::PlotFlags flags;
MapView::Flags flags;
if (_options.hiresPrint)
flags |= MapView::HiRes;
if (expand)
@ -1718,6 +1738,16 @@ void GUI::showPathMarkerInfo(QAction *action)
}
}
void GUI::selectMapLayers(QAction *action)
{
if (action == _drawVectorsAction)
_mapView->selectLayers(MapView::Layer::Vector);
else if (action == _drawRastersAction)
_mapView->selectLayers(MapView::Layer::Raster);
else
_mapView->selectLayers(MapView::Layer::Raster | MapView::Layer::Vector);
}
void GUI::loadMap()
{
#ifdef Q_OS_ANDROID
@ -2478,10 +2508,19 @@ void GUI::writeSettings()
#endif // Q_OS_ANDROID
/* Map */
MapView::Layers ml;
if (_drawRastersAction->isChecked())
ml = MapView::Layer::Raster;
else if (_drawVectorsAction->isChecked())
ml = MapView::Layer::Vector;
else
ml = MapView::Layer::Raster | MapView::Layer::Vector;
settings.beginGroup(SETTINGS_MAP);
WRITE(activeMap, _map->name());
WRITE(showMap, _showMapAction->isChecked());
WRITE(cursorCoordinates, _showCoordinatesAction->isChecked());
WRITE(layers, (int)ml);
settings.endGroup();
/* Graph */
@ -2716,6 +2755,15 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs,
_showCoordinatesAction->setChecked(true);
_mapView->showCursorCoordinates(true);
}
int layers = READ(layers).toInt();
if (layers == MapView::Layer::Raster) {
_drawRastersAction->setChecked(true);
_mapView->selectLayers(MapView::Layer::Raster);
} else if (layers == MapView::Layer::Vector) {
_drawVectorsAction->setChecked(true);
_mapView->selectLayers(MapView::Layer::Vector);
} else
_drawAllAction->setChecked(true);
activeMap = READ(activeMap).toString();
settings.endGroup();
@ -2831,10 +2879,10 @@ void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs,
/* DEM */
settings.beginGroup(SETTINGS_DEM);
if (READ(drawHillShading).toBool()) {
if (READ(drawHillShading).toBool())
_drawHillShadingAction->setChecked(true);
_mapView->drawHillShading(true);
}
else
_mapView->drawHillShading(false);
settings.endGroup();
/* Position */

View File

@ -68,6 +68,7 @@ private slots:
void showGraphGrids(bool show);
void showGraphSliderInfo(bool show);
void showPathMarkerInfo(QAction *action);
void selectMapLayers(QAction *action);
#ifdef Q_OS_ANDROID
void showGraphTabs(bool show);
#else // Q_OS_ANDROID
@ -298,6 +299,9 @@ private:
QAction *_downloadMapDEMAction;
QAction *_showDEMTilesAction;
QAction *_drawHillShadingAction;
QAction *_drawRastersAction;
QAction *_drawVectorsAction;
QAction *_drawAllAction;
QAction *_mapsEnd;
QAction *_poisEnd;
#ifndef Q_OS_ANDROID

View File

@ -62,7 +62,8 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) : QGraphicsView(parent)
_outputProjection = PCS::pcs(3857);
_inputProjection = GCS::gcs(4326);
_hidpi = true;
_hillShading = false;
_hillShading = true;
_layers = Layer::Raster | Layer::Vector;
_map = map;
_map->load(_inputProjection, _outputProjection, _deviceRatio, _hidpi);
connect(_map, &Map::tilesLoaded, this, &MapView::reloadMap);
@ -683,7 +684,7 @@ void MapView::keyReleaseEvent(QKeyEvent *event)
}
void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
PlotFlags flags)
Flags flags)
{
QRect orig, adj;
qreal ratio, diff, q, p;
@ -1115,6 +1116,10 @@ void MapView::drawBackground(QPainter *painter, const QRectF &rect)
flags = Map::OpenGL;
if (_hillShading)
flags |= Map::HillShading;
if (_layers & Layer::Raster)
flags |= Map::Rasters;
if (_layers & Layer::Vector)
flags |= Map::Vectors;
_map->draw(painter, ir, flags);
}
@ -1252,6 +1257,13 @@ void MapView::drawHillShading(bool draw)
setMap(_map);
}
void MapView::selectLayers(Layers layers)
{
_layers = layers;
setMap(_map);
}
void MapView::useStyles(bool use)
{
GraphicsItem::useStyle(use);

View File

@ -51,7 +51,14 @@ public:
HiRes = 1,
Expand = 2
};
Q_DECLARE_FLAGS(PlotFlags, Flag)
Q_DECLARE_FLAGS(Flags, Flag)
enum Layer {
NoLayers = 0,
Raster = 1,
Vector = 2
};
Q_DECLARE_FLAGS(Layers, Layer)
MapView(Map *map, POI *poi, QWidget *parent = 0);
@ -66,8 +73,7 @@ public:
void setGraph(int index);
void showExtendedInfo(bool show) {_scene->showExtendedInfo(show);}
void plot(QPainter *painter, const QRectF &target, qreal scale,
PlotFlags flags);
void plot(QPainter *painter, const QRectF &target, qreal scale, Flags flags);
void clear();
@ -130,6 +136,7 @@ public slots:
void showMotionInfo(bool show);
void useStyles(bool use);
void drawHillShading(bool draw);
void selectLayers(Layers layers);
private slots:
void updatePOI();
@ -209,6 +216,7 @@ private:
bool _infoBackground;
bool _hillShading;
Layers _layers;
int _digitalZoom;
bool _plot;
@ -222,4 +230,6 @@ private:
int _wheelDelta;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MapView::Layers)
#endif // MAPVIEW_H

View File

@ -5,6 +5,7 @@
#include <QGeoPositionInfoSource>
#include "common/config.h"
#include "data/graph.h"
#include "GUI/mapview.h"
#include "format.h"
#include "units.h"
#include "timetype.h"
@ -31,6 +32,8 @@
? QPageSize::PageSizeId::Letter \
: QPageSize::PageSizeId::A4)
#define ALL_LAYERS (int)(MapView::Layer::Raster | MapView::Layer::Vector)
#ifdef Q_OS_ANDROID
#define PIXMAP_CACHE 384
#define DEM_CACHE 128
@ -144,6 +147,7 @@ SETTING(showToolbars, "toolbar", true );
SETTING(activeMap, "map", "Open Street Map" );
SETTING(showMap, "show", true );
SETTING(cursorCoordinates, "coordinates", false );
SETTING(layers, "layers", ALL_LAYERS );
/* Graph */
SETTING(showGraphs, "show", true );

View File

@ -95,6 +95,7 @@ public:
static const Setting activeMap;
static const Setting showMap;
static const Setting cursorCoordinates;
static const Setting layers;
/* Graph */
static const Setting showGraphs;

View File

@ -114,8 +114,11 @@ const QFont *RasterTile::poiFont(Style::FontSize size, int zoom,
}
}
void RasterTile::ll2xy(QList<MapData::Poly> &polys) const
void RasterTile::ll2xy(QList<MapData::Poly> &polys, bool polygons) const
{
if (!_vectors && !polygons)
return;
for (int i = 0; i < polys.size(); i++) {
MapData::Poly &poly = polys[i];
for (int j = 0; j < poly.points.size(); j++) {
@ -127,6 +130,9 @@ void RasterTile::ll2xy(QList<MapData::Poly> &polys) const
void RasterTile::ll2xy(QList<MapData::Point> &points) const
{
if (!_vectors)
return;
for (int i = 0; i < points.size(); i++) {
QPointF p(ll2xy(points.at(i).coordinates));
points[i].coordinates = Coordinates(p.x(), p.y());
@ -145,6 +151,9 @@ void RasterTile::drawPolygons(QPainter *painter,
continue;
if (poly.raster.isValid()) {
if (!_rasters)
continue;
RectC r(poly.raster.rect());
QPointF tl(ll2xy(r.topLeft()));
QPointF br(ll2xy(r.bottomRight()));
@ -173,6 +182,9 @@ void RasterTile::drawPolygons(QPainter *painter,
//painter->drawRect(QRectF(tl, br));
//painter->setRenderHint(QPainter::Antialiasing);
} else {
if (!_vectors)
continue;
const Style::Polygon &style = _data->style()->polygon(poly.type);
painter->setPen(style.pen());
@ -186,6 +198,9 @@ void RasterTile::drawPolygons(QPainter *painter,
void RasterTile::drawLines(QPainter *painter,
const QList<MapData::Poly> &lines) const
{
if (!_vectors)
return;
painter->setBrush(Qt::NoBrush);
for (int i = 0; i < lines.size(); i++) {
@ -238,6 +253,9 @@ void RasterTile::processPolygons(const QList<MapData::Poly> &polygons,
QSet<QString> set;
QList<TextItem *> labels;
if (!_vectors)
return;
for (int i = 0; i < polygons.size(); i++) {
const MapData::Poly &poly = polygons.at(i);
bool exists = set.contains(poly.label.text());
@ -272,6 +290,9 @@ void RasterTile::processPolygons(const QList<MapData::Poly> &polygons,
void RasterTile::processLines(QList<MapData::Poly> &lines,
QList<TextItem*> &textItems, const QImage (&arrows)[2])
{
if (!_vectors)
return;
std::stable_sort(lines.begin(), lines.end());
if (_zoom >= 22)
@ -390,6 +411,9 @@ void RasterTile::processShields(const QList<MapData::Poly> &lines,
void RasterTile::processPoints(QList<MapData::Point> &points,
QList<TextItem*> &textItems)
{
if (!_vectors)
return;
std::sort(points.begin(), points.end());
for (int i = 0; i < points.size(); i++) {
@ -511,8 +535,8 @@ void RasterTile::render()
arrows[WATER] = HIDPI_IMG(":/map", "water-arrow", _ratio);
fetchData(polygons, lines, points);
ll2xy(polygons);
ll2xy(lines);
ll2xy(polygons, true);
ll2xy(lines, false);
ll2xy(points);
processPoints(points, textItems);

View File

@ -19,9 +19,10 @@ class RasterTile
public:
RasterTile(const Projection &proj, const Transform &transform, MapData *data,
int zoom, const QRect &rect, qreal ratio, const QString &key,
bool hillShading)
bool hillShading, bool rasters, bool vectors)
: _proj(proj), _transform(transform), _data(data), _zoom(zoom),
_rect(rect), _ratio(ratio), _key(key), _hillShading(hillShading) {}
_rect(rect), _ratio(ratio), _key(key), _hillShading(hillShading),
_rasters(rasters), _vectors(vectors) {}
const QString &key() const {return _key;}
QPoint xy() const {return _rect.topLeft();}
@ -53,7 +54,7 @@ private:
{return _transform.proj2img(_proj.ll2xy(c));}
Coordinates xy2ll(const QPointF &p) const
{return _proj.xy2ll(_transform.img2proj(p));}
void ll2xy(QList<MapData::Poly> &polys) const;
void ll2xy(QList<MapData::Poly> &polys, bool polygons) const;
void ll2xy(QList<MapData::Point> &points) const;
void drawPolygons(QPainter *painter, const QList<MapData::Poly> &polygons) const;
@ -86,6 +87,7 @@ private:
QString _key;
QPixmap _pixmap;
bool _hillShading;
bool _rasters, _vectors;
};
}

View File

@ -246,7 +246,8 @@ void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
else {
tiles.append(RasterTile(_projection, _transform, _data.at(n),
_zoom, QRect(ttl, QSize(TILE_SIZE, TILE_SIZE)), _tileRatio,
key, !n && flags & Map::HillShading));
key, !n && flags & Map::HillShading, flags & Map::Rasters,
flags & Map::Vectors));
}
}
}

View File

@ -21,7 +21,9 @@ public:
NoFlags = 0,
Block = 1,
OpenGL = 2,
HillShading = 4
HillShading = 4,
Rasters = 8,
Vectors = 16
};
Q_DECLARE_FLAGS(Flags, Flag)