diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-03-14 20:06:13 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-03-15 23:27:18 +0200 |
commit | 64e2247aa719da2096ada77984f15a242171a089 (patch) | |
tree | 33555776140501978c0451accc5a464da711e4f6 /map-widget | |
parent | 16b3892f22225640a0c30fd45353aa9805b2be9d (diff) | |
download | subsurface-64e2247aa719da2096ada77984f15a242171a089.tar.gz |
MapWidget.qml: try to preserve zoom when opening Google Maps
Extend openLocationInGoogleMaps() so that the current
map widget zoom level is roughly mapped to the Google Maps
zoom level.
The two zoom scales are quite different. Google Maps uses meters
directly, while the QML map uses a scale from ~1 - 21.
The approximation is done via exponential regression over
a small data set gathered from experiment.
Add a console.log() call so that the URL is logged.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'map-widget')
-rw-r--r-- | map-widget/qml/MapWidget.qml | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/map-widget/qml/MapWidget.qml b/map-widget/qml/MapWidget.qml index 5d1f60624..77e52ab56 100644 --- a/map-widget/qml/MapWidget.qml +++ b/map-widget/qml/MapWidget.qml @@ -324,10 +324,33 @@ Item { } } + /* + * open coordinates in google maps while attempting to roughly preserve + * the zoom level. the mapping between the QML map zoom level and the + * Google Maps zoom level is done via exponential regression: + * y = a * exp(b * x) + * + * data set: + * qml (x) gmaps (y in meters) + * 21 257 + * 15.313216749178913 3260 + * 12.553216749178931 20436 + * 11.11321674917894 52883 + * 9.313216749178952 202114 + * 7.51321674917896 737136 + * 5.593216749178958 2495529 + * 4.153216749178957 3895765 + * 1.753216749178955 18999949 + */ function openLocationInGoogleMaps(latitude, longitude) { var loc = latitude + "," + longitude - var url = "https://www.google.com/maps/place/@" + loc + ",5000m/data=!3m1!1e3!4m2!3m1!1s0x0:0x0" + var x = map.zoomLevel + var a = 53864950.831693 + var b = -0.60455861606547030630 + var zoom = Math.floor(a * Math.exp(b * x)) + var url = "https://www.google.com/maps/place/@" + loc + "," + zoom + "m/data=!3m1!1e3!4m2!3m1!1s0x0:0x0" Qt.openUrlExternally(url) + console.log("openLocationInGoogleMaps() map.zoomLevel: " + x + ", url: " + url) } MapWidgetContextMenu { |