From 1baa3db27e2a8967d939bb1c2c6255d95c962d2c Mon Sep 17 00:00:00 2001 From: Peret <19463568+peret2000@users.noreply.github.com> Date: Tue, 18 Feb 2025 20:13:33 +0100 Subject: [PATCH] Add Zoom property to Live map chart (#4619) It can be customized in config window, defaults to currently hardcoded value. --- src/Train/LiveMapWebPageWindow.cpp | 14 ++++++++++++-- src/Train/LiveMapWebPageWindow.h | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Train/LiveMapWebPageWindow.cpp b/src/Train/LiveMapWebPageWindow.cpp index 59af31027..18635efe1 100644 --- a/src/Train/LiveMapWebPageWindow.cpp +++ b/src/Train/LiveMapWebPageWindow.cpp @@ -82,11 +82,19 @@ LiveMapWebPageWindow::LiveMapWebPageWindow(Context *context) : GcChartWindow(con customUrl = new QLineEdit(this); customUrl->setFixedWidth(600); + customZoomLabel = new QLabel(tr("Initial Zoom")); + customZoom = new QSpinBox(this); + customZoom->setFixedWidth(60); + customZoom->setRange(0, 20); // Set the range for zoom levels + if (customUrl->text().trimmed().isEmpty()) customUrl->setText("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"); commonLayout->addRow(customUrlLabel, customUrl); connect(customUrl, SIGNAL(returnPressed()), this, SLOT(userUrl())); + if (customZoom->text().trimmed().isEmpty()) customZoom->setValue(15); + commonLayout->addRow(customZoomLabel, customZoom); + applyButton = new QPushButton(application->style()->standardIcon(QStyle::SP_ArrowRight), tr("Apply changes"), this); commonLayout->addRow(applyButton); @@ -145,7 +153,8 @@ void LiveMapWebPageWindow::ergFileSelected(ErgFile* f) } else { - QString js = ("
\n"); + QString sZoom = QString::number(zoom()); + QString js = ("\n"); routeLatLngs = "["; QString code = ""; @@ -230,7 +239,8 @@ void LiveMapWebPageWindow::telemetryUpdate(RealtimeData rtd) code = ""; if (!markerIsVisible) { - code = QString("centerMap (" + sLat + ", " + sLon + ", " + "15" + ");"); + QString sZoom = QString::number(zoom()); + code += QString("centerMap (" + sLat + ", " + sLon + ", " + sZoom + ");"); code += QString("showMyMarker (" + sLat + ", " + sLon + ");"); markerIsVisible = true; } diff --git a/src/Train/LiveMapWebPageWindow.h b/src/Train/LiveMapWebPageWindow.h index 953d2eb00..b4f4241fe 100644 --- a/src/Train/LiveMapWebPageWindow.h +++ b/src/Train/LiveMapWebPageWindow.h @@ -59,6 +59,7 @@ class LiveMapWebPageWindow : public GcChartWindow // properties can be saved/restored/set by the layout manager Q_PROPERTY(QString url READ url WRITE setUrl USER true) + Q_PROPERTY(int zoom READ zoom WRITE setZoom USER true) public: LiveMapWebPageWindow(Context *); @@ -72,6 +73,8 @@ class LiveMapWebPageWindow : public GcChartWindow // set/get properties QString url() const { return customUrl->text(); } void setUrl(QString x) { customUrl->setText(x); } + int zoom() const { return customZoom->value(); } + void setZoom(int x) { customZoom->setValue(x); } public slots: void configChanged(qint32); @@ -96,7 +99,7 @@ class LiveMapWebPageWindow : public GcChartWindow QLineEdit* rCustomUrl; QLineEdit* customLat; QLineEdit* customLon; - QLineEdit* customZoom; + QSpinBox* customZoom; QPushButton* rButton; QPushButton* applyButton;