1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-28 15:56:33 -04:00

Merge pull request #1458 from srcejon/fix_1369

Maps: Use mapboxgl as default map on Linux,
This commit is contained in:
Edouard Griffiths 2022-09-30 18:06:40 +02:00 committed by GitHub
commit d71c45e2b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 171 additions and 69 deletions

View File

@ -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
@ -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

View File

@ -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
@ -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

View File

@ -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 {

View File

@ -25,6 +25,7 @@
#include <QGeoLocation>
#include <QGeoCoordinate>
#include <QQmlContext>
#include <QQmlProperty>
#include <QMessageBox>
#include <QAction>
@ -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),
@ -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();

View File

@ -268,6 +268,7 @@ private:
void updateVORs();
void readNavAids();
void updateChannelList();
void applyMapSettings();
private slots:
void on_startStop_toggled(bool checked);

View File

@ -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++)
{
@ -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]);
@ -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);

View File

@ -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;