summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2019-09-22 20:38:07 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2019-09-24 19:33:14 -0700
commit8347e7ed9fc117e1d10ea5071cbbfc62b7000577 (patch)
tree178dd7ecf1a1445f27c85e1a3013ee42db14cf04 /app
parentaca9ff0527349d07c7547893d28a3ace89d6edd9 (diff)
qml: allow map plugins to be set on runtime
Allow selection of OSM over MapBox with enableOSM configuration file option. Bug-AGL: SPEC-2667 Change-Id: Ie055ca1263b0a6f2a74046e5ff85535e48e60d31 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'app')
-rw-r--r--app/file_operation.cpp23
-rw-r--r--app/file_operation.h2
-rwxr-xr-xapp/navigation.qml30
3 files changed, 37 insertions, 18 deletions
diff --git a/app/file_operation.cpp b/app/file_operation.cpp
index 09bd4d0..819cce5 100644
--- a/app/file_operation.cpp
+++ b/app/file_operation.cpp
@@ -15,6 +15,7 @@ void File_Operation::initFileOperation(){
m_update_interval = 100; // set default millisecond
m_start_latitude = 36.136261; // set default coordinate Westgate
m_start_longitute = -115.151254;
+ m_enable_osm = false;
m_mapStyleUrls = "mapbox://styles/mapbox/streets-v10"; // set default map style
QFile file(NAVI_CONFIG_FILEPATH);
@@ -27,13 +28,6 @@ void File_Operation::initFileOperation(){
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
QJsonObject jsonObj(jsonDoc.object());
- if(jsonObj.contains("mapAccessToken")){
- m_mapAccessToken = jsonObj["mapAccessToken"].toString();
- }else{
- fprintf(stderr,"Failed to find mapAccessToken data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
- return;
- }
-
if(jsonObj.contains("speed")){
m_car_speed = jsonObj["speed"].toDouble();
}else{
@@ -62,6 +56,21 @@ void File_Operation::initFileOperation(){
return;
}
+ // Check if using OSM
+ if (jsonObj.contains("enableOSM")){
+ m_enable_osm = jsonObj["enableOSM"].toBool();
+ if (m_enable_osm)
+ return;
+ }
+
+ // MapBox only settings
+ if(jsonObj.contains("mapAccessToken")){
+ m_mapAccessToken = jsonObj["mapAccessToken"].toString();
+ }else{
+ fprintf(stderr,"Failed to find mapAccessToken data \"%s\": %m", qPrintable(NAVI_CONFIG_FILEPATH));
+ return;
+ }
+
if(jsonObj.contains("mapStyleUrls")){
m_mapStyleUrls = jsonObj["mapStyleUrls"].toString();
}else{
diff --git a/app/file_operation.h b/app/file_operation.h
index 411cc25..962c506 100644
--- a/app/file_operation.h
+++ b/app/file_operation.h
@@ -22,6 +22,7 @@ class File_Operation: public QObject{
int m_update_interval; // set millisecond
double m_start_latitude;
double m_start_longitute;
+ bool m_enable_osm;
QString m_mapStyleUrls;
public:
@@ -34,6 +35,7 @@ public:
Q_INVOKABLE double getStartLatitude();
Q_INVOKABLE double getStartLongitute();
Q_INVOKABLE QString getMapStyleUrls();
+ Q_INVOKABLE bool isOSMEnabled() { return m_enable_osm; };
private:
void initFileOperation();
diff --git a/app/navigation.qml b/app/navigation.qml
index c4eba78..de08bf6 100755
--- a/app/navigation.qml
+++ b/app/navigation.qml
@@ -39,6 +39,23 @@ ApplicationWindow {
property real positionTimer_interval : fileOperation.getUpdateInterval() // set millisecond
property real car_moving_distance : (car_driving_speed / 3.6) / (1000/positionTimer_interval) // Metric unit
+ Plugin {
+ id: mapbox
+ name: "mapbox"
+ PluginParameter {
+ name: "mapbox.access_token";
+ value: fileOperation.getMapAccessToken()
+ }
+ }
+ Plugin {
+ id: osm
+ name: "osm"
+ PluginParameter {
+ name: "osm.mapping.host";
+ value: "https://a.tile.openstreetmap.org/"
+ }
+ }
+
Map{
id: map
property int pathcounter : 0
@@ -60,11 +77,7 @@ ApplicationWindow {
width: parent.width
height: parent.height
- plugin: Plugin {
- name: "mapbox"
- PluginParameter { name: "mapbox.access_token";
- value: fileOperation.getMapAccessToken() }
- }
+ plugin: fileOperation.isOSMEnabled() ? osm : mapbox
center: QtPositioning.coordinate(car_position_lat, car_position_lon)
zoomLevel: default_zoom_level
bearing: 0
@@ -214,12 +227,7 @@ ApplicationWindow {
RouteModel {
id: routeModel
objectName: "routeModel"
- plugin : Plugin {
- name: "mapbox"
- PluginParameter { name: "mapbox.access_token";
- value: fileOperation.getMapAccessToken()
- }
- }
+ plugin: map.plugin
query: RouteQuery {
id: routeQuery
}