Update station icon on map when My Position preference changes

This commit is contained in:
Jon Beniston 2022-03-21 10:14:35 +00:00
parent 4b82b919d3
commit 5ec2133782
8 changed files with 116 additions and 21 deletions

View File

@ -3802,6 +3802,9 @@ ADSBDemodGUI::ADSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb
ui->warning->setText("Please set your antenna location under Preferences > My Position");
}
// Get updated when position changes
connect(&MainCore::instance()->getSettings(), &MainSettings::preferenceChanged, this, &ADSBDemodGUI::preferenceChanged);
// Add airports within range of My Position
if (m_airportInfo != nullptr) {
updateAirports();
@ -4587,3 +4590,55 @@ void ADSBDemodGUI::handleImportReply(QNetworkReply* reply)
reply->deleteLater();
}
}
void ADSBDemodGUI::preferenceChanged(int elementType)
{
Preferences::ElementType pref = (Preferences::ElementType)elementType;
if ((pref == Preferences::Latitude) || (pref == Preferences::Longitude) || (pref == Preferences::Altitude))
{
Real stationLatitude = MainCore::instance()->getSettings().getLatitude();
Real stationLongitude = MainCore::instance()->getSettings().getLongitude();
Real stationAltitude = MainCore::instance()->getSettings().getAltitude();
if ( (stationLatitude != m_azEl.getLocationSpherical().m_latitude)
|| (stationLongitude != m_azEl.getLocationSpherical().m_longitude)
|| (stationAltitude != m_azEl.getLocationSpherical().m_altitude))
{
m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude);
// Update distances and what is visible
updateAirports();
updateAirspaces();
updateNavAids();
// Update icon position on Map
QQuickItem *item = ui->map->rootObject();
QObject *map = item->findChild<QObject*>("map");
if (map != nullptr)
{
QObject *stationObject = map->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));
}
}
}
}
if (pref == Preferences::StationName)
{
// Update icon label on Map
QQuickItem *item = ui->map->rootObject();
QObject *map = item->findChild<QObject*>("map");
if (map != nullptr)
{
QObject *stationObject = map->findChild<QObject*>("station");
if(stationObject != NULL) {
stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName()));
}
}
}
}

View File

@ -942,6 +942,7 @@ private slots:
virtual bool eventFilter(QObject *obj, QEvent *event);
void import();
void handleImportReply(QNetworkReply* reply);
void preferenceChanged(int elementType);
signals:
void homePositionChanged();

View File

@ -275,7 +275,7 @@ The map displays aircraft locations and data geographically. Four types of map c
![ADS-B Demodulator Map](../../../doc/img/ADSBDemod_plugin_map2.png)
The initial antenna location is placed according to My Position set under the Preferences > My Position menu. The position is only updated when the ADS-B demodulator plugin is first opened.
The antenna location is placed according to My Position set under the Preferences > My Position menu.
If My Position is not set correctly, the position of aircraft may not be computed correctly.
Aircraft are only placed upon the map when a position can be calculated, which can require several frames to be received.

View File

@ -232,21 +232,24 @@ MapGUI::MapGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *featur
}
// Create antenna at My Position
SWGSDRangel::SWGMapItem antennaMapItem;
antennaMapItem.setName(new QString(MainCore::instance()->getSettings().getStationName()));
antennaMapItem.setLatitude(stationLatitude);
antennaMapItem.setLongitude(stationLongitude);
antennaMapItem.setAltitude(stationAltitude);
antennaMapItem.setImage(new QString("antenna.png"));
antennaMapItem.setImageRotation(0);
antennaMapItem.setText(new QString(MainCore::instance()->getSettings().getStationName()));
antennaMapItem.setModel(new QString("antenna.glb"));
antennaMapItem.setFixedPosition(true);
antennaMapItem.setOrientation(0);
antennaMapItem.setLabel(new QString(MainCore::instance()->getSettings().getStationName()));
antennaMapItem.setLabelAltitudeOffset(4.5);
antennaMapItem.setAltitudeReference(1);
update(m_map, &antennaMapItem, "Station");
//m_antennaMapItem.setName(new QString(MainCore::instance()->getSettings().getStationName()));
m_antennaMapItem.setName(new QString("Station"));
m_antennaMapItem.setLatitude(stationLatitude);
m_antennaMapItem.setLongitude(stationLongitude);
m_antennaMapItem.setAltitude(stationAltitude);
m_antennaMapItem.setImage(new QString("antenna.png"));
m_antennaMapItem.setImageRotation(0);
m_antennaMapItem.setText(new QString(MainCore::instance()->getSettings().getStationName()));
m_antennaMapItem.setModel(new QString("antenna.glb"));
m_antennaMapItem.setFixedPosition(true);
m_antennaMapItem.setOrientation(0);
m_antennaMapItem.setLabel(new QString(MainCore::instance()->getSettings().getStationName()));
m_antennaMapItem.setLabelAltitudeOffset(4.5);
m_antennaMapItem.setAltitudeReference(1);
update(m_map, &m_antennaMapItem, "Station");
// Get updated when position changes
connect(&MainCore::instance()->getSettings(), &MainSettings::preferenceChanged, this, &MapGUI::preferenceChanged);
// Read beacons, if they exist
QList<Beacon *> *beacons = Beacon::readIARUCSV(MapGUI::getBeaconFilename());
@ -1177,3 +1180,34 @@ void MapGUI::fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest)
ui->splitter->addWidget(ui->web);
}
}
void MapGUI::preferenceChanged(int elementType)
{
Preferences::ElementType pref = (Preferences::ElementType)elementType;
if ((pref == Preferences::Latitude) || (pref == Preferences::Longitude) || (pref == Preferences::Altitude))
{
float stationLatitude = MainCore::instance()->getSettings().getLatitude();
float stationLongitude = MainCore::instance()->getSettings().getLongitude();
float stationAltitude = MainCore::instance()->getSettings().getAltitude();
if ( (stationLatitude != m_azEl.getLocationSpherical().m_latitude)
|| (stationLongitude != m_azEl.getLocationSpherical().m_longitude)
|| (stationAltitude != m_azEl.getLocationSpherical().m_altitude))
{
// Update position of station
m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude);
m_antennaMapItem.setLatitude(stationLatitude);
m_antennaMapItem.setLongitude(stationLongitude);
m_antennaMapItem.setAltitude(stationAltitude);
update(m_map, &m_antennaMapItem, "Station");
}
}
if (pref == Preferences::StationName)
{
// Update station name
m_antennaMapItem.setLabel(new QString(MainCore::instance()->getSettings().getStationName()));
m_antennaMapItem.setText(new QString(MainCore::instance()->getSettings().getStationName()));
update(m_map, &m_antennaMapItem, "Station");
}
}

View File

@ -103,6 +103,7 @@ private:
MessageQueue m_inputMessageQueue;
MapModel m_mapModel;
AzEl m_azEl; // Position of station
SWGSDRangel::SWGMapItem m_antennaMapItem;
QList<Beacon *> *m_beacons;
MapBeaconDialog m_beaconDialog;
MapIBPBeaconDialog m_ibpBeaconDialog;
@ -158,6 +159,7 @@ private slots:
virtual void showEvent(QShowEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event);
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
void preferenceChanged(int elementType);
};

View File

@ -231,7 +231,7 @@ void MapModel::update(const PipeEndPoint *sourcePipe, SWGSDRangel::SWGMapItem *s
remove(item);
// Need to call update, for it to be removed in 3D map
// Item is set to not be available from this point in time
// It will still be avialable if time is set in the past
// It will still be available if time is set in the past
item->update(swgMapItem);
}
else
@ -508,11 +508,12 @@ QVariant MapModel::data(const QModelIndex &index, int role) const
else if (role == MapModel::mapTextRole)
{
// Create the text to go in the bubble next to the image
QString name = m_items[row]->m_label.isEmpty() ? m_items[row]->m_name : m_items[row]->m_label;
if (row == m_target)
{
AzEl *azEl = m_gui->getAzEl();
QString text = QString("%1<br>Az: %2%5 El: %3%5 Dist: %4 km")
.arg(m_selected[row] ? m_items[row]->m_text : m_items[row]->m_name)
.arg(m_selected[row] ? m_items[row]->m_text : name)
.arg(std::round(azEl->getAzimuth()))
.arg(std::round(azEl->getElevation()))
.arg(std::round(azEl->getDistance() / 1000.0))
@ -525,7 +526,7 @@ QVariant MapModel::data(const QModelIndex &index, int role) const
}
else
{
return QVariant::fromValue(m_items[row]->m_name);
return QVariant::fromValue(name);
}
}
else if (role == MapModel::mapTextVisibleRole)

View File

@ -69,7 +69,9 @@ MapSettings::MapSettings() :
m_itemSettings.insert("RadioSonde", new MapItemSettings("RadioSonde", QColor(102, 0, 102), false, 11, modelMinPixelSize));
m_itemSettings.insert("Radio Time Transmitters", new MapItemSettings("Radio Time Transmitters", QColor(255, 0, 0), true, 8));
m_itemSettings.insert("Radar", new MapItemSettings("Radar", QColor(255, 0, 0), true, 8));
m_itemSettings.insert("Station", new MapItemSettings("Station", QColor(255, 0, 0), true, 11));
MapItemSettings *stationItemSettings = new MapItemSettings("Station", QColor(255, 0, 0), true, 11);
stationItemSettings->m_display2DTrack = false;
m_itemSettings.insert("Station", stationItemSettings);
resetToDefaults();
}

View File

@ -141,7 +141,7 @@ These are not included with the SDRangel distribution, so must be downloaded.
The map feature displays a 2D and a 3D map overlaid with objects reported by other SDRangel channels and features, as well as beacon locations.
* The "Home Station" antenna location is placed according to My Position set under the Preferences > My Position menu. The position is only updated when the Map plugin is first opened.
* The "Home Station" antenna location is placed according to My Position set under the Preferences > My Position menu.
* To pan around the map, click the left mouse button and drag. To zoom in or out, use the mouse scroll wheel.
* Single clicking on an object in the map will display a text bubble with additional information about the object.
* Right clicking on a object on the 2D map will open a context menu, which allows: