Commit 80554e9a authored by Volker Krause's avatar Volker Krause
Browse files

Add action to open a proper map on the indoor map page

parent a99bface
......@@ -105,6 +105,11 @@ Kirigami.Page {
icon.color: Solid.NetworkStatus.metered != Solid.NetworkStatus.No ? Kirigami.Theme.neutralTextColor : Kirigami.Theme.textColor
onTriggered: queryLiveLocationData();
},
Kirigami.Action { separator: true },
Kirigami.Action {
text: i18n("Open Map");
onTriggered: NavigationController.showOnMap(map.mapData.center.y, map.mapData.center.x, 18);
},
Kirigami.Action {
id: lightStyleAction
text: "Light Style"
......
......@@ -48,14 +48,17 @@ void NavigationController::showOnMap(const QVariant &place)
}
const auto geo = LocationUtil::geo(place);
const auto addr = LocationUtil::address(place);
if (geo.isValid()) {
// zoom out further from airports, they are larger and you usually want to go further away from them
showOnMap(geo.latitude(), geo.longitude(), place.userType() == qMetaTypeId<Airport>() ? 12 : 17);
return;
}
const auto addr = LocationUtil::address(place);
if (!addr.isEmpty()) {
QUrl url;
#ifdef Q_OS_ANDROID
QUrl url;
url.setScheme(QStringLiteral("geo"));
if (geo.isValid()) {
url.setPath(QString::number(geo.latitude()) + QLatin1Char(',') + QString::number(geo.longitude()));
} else if (!addr.isEmpty()) {
url.setScheme(QStringLiteral("geo"));
url.setPath(QStringLiteral("0,0"));
QUrlQuery query;
query.addQueryItem(QStringLiteral("q"), addr.streetAddress() + QLatin1String(", ")
......@@ -63,29 +66,7 @@ void NavigationController::showOnMap(const QVariant &place)
+ addr.addressLocality() + QLatin1String(", ")
+ addr.addressCountry());
url.setQuery(query);
} else {
return;
}
startActivity(url);
#else
if (geo.isValid()) {
// zoom out further from airports, they are larger and you usually want to go further away from them
const auto zoom = place.userType() == qMetaTypeId<Airport>() ? 12 : 17;
QUrl url;
url.setScheme(QStringLiteral("https"));
url.setHost(QStringLiteral("www.openstreetmap.org"));
url.setPath(QStringLiteral("/"));
const QString fragment = QLatin1String("map=") + QString::number(zoom)
+ QLatin1Char('/') + QString::number(geo.latitude())
+ QLatin1Char('/') + QString::number(geo.longitude());
url.setFragment(fragment);
QDesktopServices::openUrl(url);
return;
}
if (!addr.isEmpty()) {
QUrl url;
url.setScheme(QStringLiteral("https"));
url.setHost(QStringLiteral("www.openstreetmap.org"));
url.setPath(QStringLiteral("/search"));
......@@ -96,9 +77,33 @@ void NavigationController::showOnMap(const QVariant &place)
QUrlQuery query;
query.addQueryItem(QStringLiteral("query"), queryString);
url.setQuery(query);
#endif
QDesktopServices::openUrl(url);
}
}
void NavigationController::showOnMap(float latitude, float longitude, int zoom)
{
#ifdef Q_OS_ANDROID
constexpr const auto useGeoUrl = true;
#else
constexpr const auto useGeoUrl = false;
#endif
QUrl url;
if (useGeoUrl) {
url.setScheme(QStringLiteral("geo"));
url.setPath(QString::number(latitude) + QLatin1Char(',') + QString::number(longitude));
} else {
url.setScheme(QStringLiteral("https"));
url.setHost(QStringLiteral("www.openstreetmap.org"));
url.setPath(QStringLiteral("/"));
const QString fragment = QLatin1String("map=") + QString::number(zoom)
+ QLatin1Char('/') + QString::number(latitude)
+ QLatin1Char('/') + QString::number(longitude);
url.setFragment(fragment);
}
QDesktopServices::openUrl(url);
}
bool NavigationController::canNavigateTo(const QVariant& place)
......
......@@ -19,6 +19,7 @@ class NavigationController
Q_GADGET
public:
Q_INVOKABLE void showOnMap(const QVariant &place);
Q_INVOKABLE void showOnMap(float latitude, float longitude, int zoom);
Q_INVOKABLE bool canNavigateTo(const QVariant &place);
Q_INVOKABLE void navigateTo(const QVariant &place);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment