Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps: Use mapboxgl as default map on Linux, #1458

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugins/channelrx/demodadsb/adsbdemodsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ void ADSBDemodSettings::resetToDefaults()
m_logEnabled = false;
m_airspaces = QStringList({"A", "D", "TMZ"});
m_airspaceRange = 500.0f;
#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4)
m_mapProvider = "mapboxgl"; // osm maps do not work in Qt 5.15.3 - https://github.com/f4exb/sdrangel/issues/1169
#ifdef LINUX
m_mapProvider = "mapboxgl"; // osm maps do not work in some versions of Linux https://github.com/f4exb/sdrangel/issues/1169 & 1369
#else
m_mapProvider = "osm";
#endif
Expand Down Expand Up @@ -315,8 +315,8 @@ bool ADSBDemodSettings::deserialize(const QByteArray& data)
d.readBlob(60, &m_geometryBytes);
d.readBool(61, &m_hidden, false);
d.readString(62, &m_checkWXAPIKey, "");
#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4)
d.readString(63, &m_mapProvider, "mapboxgl"); // osm maps do not work in Qt 5.15.3/4 - https://github.com/f4exb/sdrangel/issues/1169
#ifdef LINUX
d.readString(63, &m_mapProvider, "mapboxgl");
#else
d.readString(63, &m_mapProvider, "osm");
#endif
Expand Down
8 changes: 4 additions & 4 deletions plugins/feature/map/mapsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ MapSettings::~MapSettings()
void MapSettings::resetToDefaults()
{
m_displayNames = true;
#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4)
m_mapProvider = "mapboxgl"; // osm maps do not work in Qt 5.15.3/4 - https://github.com/f4exb/sdrangel/issues/1169
#ifdef LINUX
m_mapProvider = "mapboxgl"; // osm maps do not work in some versions of Linux https://github.com/f4exb/sdrangel/issues/1169 & 1369
#else
m_mapProvider = "osm";
#endif
Expand Down Expand Up @@ -183,8 +183,8 @@ bool MapSettings::deserialize(const QByteArray& data)
QByteArray blob;

d.readBool(1, &m_displayNames, true);
#if QT_VERSION == QT_VERSION_CHECK(5, 15, 3) || QT_VERSION == QT_VERSION_CHECK(5, 15, 4)
d.readString(2, &m_mapProvider, "mapboxgl"); // osm maps do not work in Qt 5.15.3/4 - https://github.com/f4exb/sdrangel/issues/1169
#ifdef LINUX
d.readString(2, &m_mapProvider, "mapboxgl");
#else
d.readString(2, &m_mapProvider, "osm");
#endif
Expand Down
98 changes: 67 additions & 31 deletions plugins/feature/vorlocalizer/map/map.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,84 @@ import QtPositioning 5.12
Item {
id: qmlMap
property int vorZoomLevel: 11
property string mapProvider: "osm"
property variant mapPtr
property string requestedMapType
property variant guiPtr

Plugin {
id: mapPlugin
name: "osm"
function createMap(pluginParameters, requestedMap, gui) {
requestedMapType = requestedMap
guiPtr = gui

var paramString = ""
for (var prop in pluginParameters) {
var parameter = 'PluginParameter { name: "' + prop + '"; value: "' + pluginParameters[prop] + '"}'
paramString = paramString + parameter
}
var pluginString = 'import QtLocation 5.12; Plugin{ name:"' + mapProvider + '"; ' + paramString + '}'
var plugin = Qt.createQmlObject (pluginString, qmlMap)

if (mapPtr) {
// Objects aren't destroyed immediately, so don't call findChild("map")
mapPtr.destroy()
mapPtr = null
}
mapPtr = actualMapComponent.createObject(page)
mapPtr.plugin = plugin
mapPtr.forceActiveFocus()
return mapPtr
}

Map {
id: map
objectName: "map"
Item {
id: page
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(51.5, 0.125) // London
zoomLevel: 10
}

Component {
id: actualMapComponent

MapItemView {
model: vorModel
delegate: vorRadialComponent
}
Map {
id: map
objectName: "map"
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(51.5, 0.125) // London
zoomLevel: 10

MapStation {
id: station
objectName: "station"
stationName: "Home"
coordinate: QtPositioning.coordinate(51.5, 0.125)
}
MapItemView {
model: vorModel
delegate: vorRadialComponent
}

MapItemView {
model: vorModel
delegate: vorComponent
}
MapStation {
id: station
objectName: "station"
stationName: "Home"
}

onZoomLevelChanged: {
if (zoomLevel > 11) {
station.zoomLevel = zoomLevel
vorZoomLevel = zoomLevel
} else {
station.zoomLevel = 11
vorZoomLevel = 11
MapItemView {
model: vorModel
delegate: vorComponent
}

onZoomLevelChanged: {
if (zoomLevel > 11) {
station.zoomLevel = zoomLevel
vorZoomLevel = zoomLevel
} else {
station.zoomLevel = 11
vorZoomLevel = 11
}
}
}

onSupportedMapTypesChanged : {
for (var i = 0; i < supportedMapTypes.length; i++) {
if (requestedMapType == supportedMapTypes[i].name) {
activeMapType = supportedMapTypes[i]
}
}
}
}
}

Component {
Expand Down
113 changes: 83 additions & 30 deletions plugins/feature/vorlocalizer/vorlocalizergui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QGeoLocation>
#include <QGeoCoordinate>
#include <QQmlContext>
#include <QQmlProperty>
#include <QMessageBox>
#include <QAction>

Expand Down Expand Up @@ -844,6 +845,87 @@ void VORLocalizerGUI::onMenuDialogCalled(const QPoint &p)
resetContextMenuType();
}

void VORLocalizerGUI::applyMapSettings()
{
// Get station position
Real stationLatitude = MainCore::instance()->getSettings().getLatitude();
Real stationLongitude = MainCore::instance()->getSettings().getLongitude();
Real stationAltitude = MainCore::instance()->getSettings().getAltitude();
m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude);

QQuickItem *item = ui->map->rootObject();

QObject *object = item->findChild<QObject*>("map");
QGeoCoordinate coords;
double zoom;
if (object != nullptr)
{
// Save existing position of map
coords = object->property("center").value<QGeoCoordinate>();
zoom = object->property("zoomLevel").value<double>();
}
else
{
// Center on my location when map is first opened
coords.setLatitude(stationLatitude);
coords.setLongitude(stationLongitude);
coords.setAltitude(stationAltitude);
zoom = 10.0;
}

// Create the map using the specified provider
QQmlProperty::write(item, "mapProvider", m_settings.m_mapProvider);
QVariantMap parameters;
QString mapType;

if (m_settings.m_mapProvider == "osm") {
mapType = "Street Map";
} else if (m_settings.m_mapProvider == "mapboxgl") {
mapType = "mapbox://styles/mapbox/streets-v10";
}

QVariant retVal;
if (!QMetaObject::invokeMethod(item, "createMap", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, retVal),
Q_ARG(QVariant, QVariant::fromValue(parameters)),
Q_ARG(QVariant, mapType),
Q_ARG(QVariant, QVariant::fromValue(this))))
{
qCritical() << "VORLocalizerGUI::applyMapSettings - Failed to invoke createMap";
}
QObject *newMap = retVal.value<QObject *>();

// Restore position of map
if (newMap != nullptr)
{
if (coords.isValid())
{
newMap->setProperty("zoomLevel", QVariant::fromValue(zoom));
newMap->setProperty("center", QVariant::fromValue(coords));
}
}
else
{
qDebug() << "VORLocalizerGUI::applyMapSettings - createMap returned a nullptr";
}

// Move antenna icon to My Position
QObject *stationObject = newMap->findChild<QObject*>("station");
if(stationObject != NULL)
{
QGeoCoordinate coords = stationObject->property("coordinate").value<QGeoCoordinate>();
coords.setLatitude(stationLatitude);
coords.setLongitude(stationLongitude);
coords.setAltitude(stationAltitude);
stationObject->setProperty("coordinate", QVariant::fromValue(coords));
stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName()));
}
else
{
qDebug() << "VORLocalizerGUI::applyMapSettings - Couldn't find station";
}
}

VORLocalizerGUI::VORLocalizerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent) :
FeatureGUI(parent),
ui(new Ui::VORLocalizerGUI),
Expand Down Expand Up @@ -886,36 +968,7 @@ VORLocalizerGUI::VORLocalizerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISe

connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));

// Get station position
Real stationLatitude = MainCore::instance()->getSettings().getLatitude();
Real stationLongitude = MainCore::instance()->getSettings().getLongitude();
Real stationAltitude = MainCore::instance()->getSettings().getAltitude();
m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude);

// Centre map at My Position
QQuickItem *item = ui->map->rootObject();
QObject *object = item->findChild<QObject*>("map");

if (object)
{
QGeoCoordinate coords = object->property("center").value<QGeoCoordinate>();
coords.setLatitude(stationLatitude);
coords.setLongitude(stationLongitude);
object->setProperty("center", QVariant::fromValue(coords));
}

// Move antenna icon to My Position to start with
QObject *stationObject = item->findChild<QObject*>("station");

if (stationObject)
{
QGeoCoordinate coords = stationObject->property("coordinate").value<QGeoCoordinate>();
coords.setLatitude(stationLatitude);
coords.setLongitude(stationLongitude);
coords.setAltitude(stationAltitude);
stationObject->setProperty("coordinate", QVariant::fromValue(coords));
stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName()));
}
applyMapSettings();

// Read in VOR information if it exists
readNavAids();
Expand Down
1 change: 1 addition & 0 deletions plugins/feature/vorlocalizer/vorlocalizergui.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class VORLocalizerGUI : public FeatureGUI {
void updateVORs();
void readNavAids();
void updateChannelList();
void applyMapSettings();

private slots:
void on_startStop_toggled(bool checked);
Expand Down
11 changes: 11 additions & 0 deletions plugins/feature/vorlocalizer/vorlocalizersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ void VORLocalizerSettings::resetToDefaults()
m_reverseAPIFeatureSetIndex = 0;
m_reverseAPIFeatureIndex = 0;
m_workspaceIndex = 0;
#ifdef LINUX
m_mapProvider = "mapboxgl"; // osm maps do not work in some versions of Linux https://github.com/f4exb/sdrangel/issues/1169 & 1369
#else
m_mapProvider = "osm";
#endif

for (int i = 0; i < VORDEMOD_COLUMNS; i++)
{
Expand Down Expand Up @@ -71,6 +76,7 @@ QByteArray VORLocalizerSettings::serialize() const

s.writeS32(20, m_workspaceIndex);
s.writeBlob(21, m_geometryBytes);
s.writeString(22, m_mapProvider);

for (int i = 0; i < VORDEMOD_COLUMNS; i++) {
s.writeS32(100 + i, m_columnIndexes[i]);
Expand Down Expand Up @@ -128,6 +134,11 @@ bool VORLocalizerSettings::deserialize(const QByteArray& data)

d.readS32(20, &m_workspaceIndex, 0);
d.readBlob(21, &m_geometryBytes);
#ifdef LINUX
d.readString(22, &m_mapProvider, "mapboxgl");
#else
d.readString(22, &m_mapProvider, "osm");
#endif

for (int i = 0; i < VORDEMOD_COLUMNS; i++) {
d.readS32(100 + i, &m_columnIndexes[i], i);
Expand Down
1 change: 1 addition & 0 deletions plugins/feature/vorlocalizer/vorlocalizersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct VORLocalizerSettings
Serializable *m_rollupState;
int m_workspaceIndex;
QByteArray m_geometryBytes;
QString m_mapProvider;

static const int VORDEMOD_COLUMNS = 10;
static const int VOR_COL_NAME = 0;
Expand Down