mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:53:23 +00:00
Map: ignore dive sites without location in centerOnSelectedDiveSite()
Don't zoom onto (0,0) for selected dive sites that have no location. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0da86dfd86
commit
30d96d3704
1 changed files with 33 additions and 29 deletions
|
@ -48,26 +48,24 @@ void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
|
|||
void MapWidgetHelper::centerOnSelectedDiveSite()
|
||||
{
|
||||
QVector<struct dive_site *> selDS = m_mapLocationModel->selectedDs();
|
||||
QVector<QGeoCoordinate> selGC;
|
||||
|
||||
if (selDS.isEmpty()) {
|
||||
// no selected dives with GPS coordinates
|
||||
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
|
||||
} else if (selDS.size() == 1) {
|
||||
QGeoCoordinate dsCoord (selDS[0]->location.lat.udeg * 0.000001, selDS[0]->location.lon.udeg * 0.000001);
|
||||
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
|
||||
} else {
|
||||
/* more than one dive sites with GPS selected.
|
||||
* find the most top-left and bottom-right dive sites on the map coordinate system. */
|
||||
return;
|
||||
}
|
||||
|
||||
// find the most top-left and bottom-right dive sites on the map coordinate system.
|
||||
qreal minLat = 0.0, minLon = 0.0, maxLat = 0.0, maxLon = 0.0;
|
||||
bool start = true;
|
||||
int count = 0;
|
||||
for(struct dive_site *dss: selDS) {
|
||||
if (!has_location(&dss->location))
|
||||
continue;
|
||||
qreal lat = dss->location.lat.udeg * 0.000001;
|
||||
qreal lon = dss->location.lon.udeg * 0.000001;
|
||||
if (start) {
|
||||
if (++count == 1) {
|
||||
minLat = maxLat = lat;
|
||||
minLon = maxLon = lon;
|
||||
start = false;
|
||||
continue;
|
||||
}
|
||||
if (lat < minLat)
|
||||
|
@ -79,7 +77,13 @@ void MapWidgetHelper::centerOnSelectedDiveSite()
|
|||
else if (lon > maxLon)
|
||||
maxLon = lon;
|
||||
}
|
||||
// pass rectangle coordinates to QML
|
||||
|
||||
// Pass coordinates to QML, either as a point or as a rectangle.
|
||||
// If we didn't find any coordinates, do nothing.
|
||||
if (count == 1) {
|
||||
QGeoCoordinate dsCoord (selDS[0]->location.lat.udeg * 0.000001, selDS[0]->location.lon.udeg * 0.000001);
|
||||
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
|
||||
} else if (count > 1) {
|
||||
QGeoCoordinate coordTopLeft(minLat, minLon);
|
||||
QGeoCoordinate coordBottomRight(maxLat, maxLon);
|
||||
QGeoCoordinate coordCenter(minLat + (maxLat - minLat) * 0.5, minLon + (maxLon - minLon) * 0.5);
|
||||
|
|
Loading…
Add table
Reference in a new issue