From c2ddba29b9003e50d04235ea9f39b808133411ef Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Fri, 1 Jan 2021 17:24:21 +0100 Subject: [PATCH] Load coordinates from cli args --- README.md | 15 +++++++++++++++ assets/main.qml | 7 +++++-- main.py | 4 ++++ main.pyproject | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 62b937b..479b2ab 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,18 @@ clicking on the map causes the window to close and the coordinates to be printed on stdout; ![](./screenshot.png) + +## Usage + +Build the app: + +```sh +make build +``` + +Run it: + +```sh +./dist/qt-map-py/qt-map-py # start centered in PoznaƄ +./dist/qt-map-py/qt-map-py 33.66195 -95.55362 # start centered at given lat / lon +``` diff --git a/assets/main.qml b/assets/main.qml index df80500..0b4f6f5 100644 --- a/assets/main.qml +++ b/assets/main.qml @@ -4,8 +4,6 @@ import QtLocation 5.15 import QtPositioning 5.5 - - ApplicationWindow { width: 640 height: 480 @@ -22,6 +20,11 @@ ApplicationWindow { return marker.coordinate.latitude + "|" + marker.coordinate.longitude } + function setMapPosition(lat, lon){ + marker.coordinate = QtPositioning.coordinate(parseFloat(lat), parseFloat(lon)); + map.center = QtPositioning.coordinate(parseFloat(lat), parseFloat(lon)); + } + Plugin { id: mapPlugin diff --git a/main.py b/main.py index 6cf2e53..4f603bc 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,10 @@ if __name__ == "__main__": if not engine.rootObjects(): sys.exit(-1) root = engine.rootObjects()[0] + if len(sys.argv) == 3: + lat = sys.argv[1] + lon = sys.argv[2] + root.setMapPosition(lat, lon) def cb(): print(root.getSelectedLocation()) diff --git a/main.pyproject b/main.pyproject index d344703..2853464 100644 --- a/main.pyproject +++ b/main.pyproject @@ -1,3 +1,3 @@ { - "files": ["pin64.png","main.py","main.qml"] + "files": ["pin64.png","main.py","assets/main.qml","main.qml","assets/pin64.png"] }