diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-12-08 17:55:49 -0200 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2016-12-09 11:28:31 -0200 |
commit | 97df99c134a5c4adbf083af0b1e5f8c9713dbb1f (patch) | |
tree | 670cd8c8172c1247350311783ee9f9d1caaf1949 /platform/qt | |
parent | a8c2688ca315a14dc2033ddf3ca21c2d9914587d (diff) | |
download | qtlocation-mapboxgl-97df99c134a5c4adbf083af0b1e5f8c9713dbb1f.tar.gz |
[Qt] Remove route before adding
This will allow to bind a GeoJSON to the source data property
without throwing an exception.
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/qmlapp/main.qml | 36 | ||||
-rw-r--r-- | platform/qt/resources/common.qrc | 3 | ||||
-rw-r--r-- | platform/qt/resources/source1.geojson (renamed from platform/qt/resources/source.geojson) | 0 | ||||
-rw-r--r-- | platform/qt/resources/source2.geojson | 92 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 8 |
5 files changed, 132 insertions, 7 deletions
diff --git a/platform/qt/qmlapp/main.qml b/platform/qt/qmlapp/main.qml index fa157333d0..6e6f290e43 100644 --- a/platform/qt/qmlapp/main.qml +++ b/platform/qt/qmlapp/main.qml @@ -30,10 +30,11 @@ ApplicationWindow { property var fillColor: waterColorDialog.color }, MapParameter { + id: source property var type: "source" property var name: "routeSource" property var sourceType: "geojson" - property var data: ":source.geojson" + property var data: ":source1.geojson" }, MapParameter { property var type: "layer" @@ -256,11 +257,11 @@ ApplicationWindow { title: "Style:" ColumnLayout { - ExclusiveGroup { id: group } + ExclusiveGroup { id: styleGroup } RadioButton { text: "Streets" checked: true - exclusiveGroup: group + exclusiveGroup: styleGroup onClicked: { style.url = "mapbox://styles/mapbox/streets-v9" landColorDialog.color = "#e0ded8" @@ -269,7 +270,7 @@ ApplicationWindow { } RadioButton { text: "Dark" - exclusiveGroup: group + exclusiveGroup: styleGroup onClicked: { style.url = "mapbox://styles/mapbox/dark-v9" landColorDialog.color = "#343332" @@ -278,7 +279,7 @@ ApplicationWindow { } RadioButton { text: "Satellite" - exclusiveGroup: group + exclusiveGroup: styleGroup onClicked: { style.url = "mapbox://styles/mapbox/satellite-v9" } @@ -300,6 +301,31 @@ ApplicationWindow { onClicked: waterColorDialog.open() } + GroupBox { + anchors.left: parent.left + anchors.right: parent.right + title: "Route:" + + ColumnLayout { + ExclusiveGroup { id: sourceGroup } + RadioButton { + text: "Route 1" + checked: true + exclusiveGroup: sourceGroup + onClicked: { + source.data = ":source1.geojson" + } + } + RadioButton { + text: "Route 2" + exclusiveGroup: sourceGroup + onClicked: { + source.data = ":source2.geojson" + } + } + } + } + CheckBox { id: toggleRoute anchors.left: parent.left diff --git a/platform/qt/resources/common.qrc b/platform/qt/resources/common.qrc index e9fd46cfa7..9d409760cc 100644 --- a/platform/qt/resources/common.qrc +++ b/platform/qt/resources/common.qrc @@ -1,6 +1,7 @@ <RCC> <qresource prefix="/"> - <file>source.geojson</file> + <file>source1.geojson</file> + <file>source2.geojson</file> <file>label-arrow.svg</file> <file>label-background.svg</file> </qresource> diff --git a/platform/qt/resources/source.geojson b/platform/qt/resources/source1.geojson index 1d270ba189..1d270ba189 100644 --- a/platform/qt/resources/source.geojson +++ b/platform/qt/resources/source1.geojson diff --git a/platform/qt/resources/source2.geojson b/platform/qt/resources/source2.geojson new file mode 100644 index 0000000000..df300d1040 --- /dev/null +++ b/platform/qt/resources/source2.geojson @@ -0,0 +1,92 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "type": "label", + "name": "Start" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 24.943320751190186, + 60.166471893909794 + ] + } + }, + { + "type": "Feature", + "properties": { + "type": "label", + "name": "End" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 24.942440986633297, + 60.16715507391703 + ] + } + }, + { + "type": "Feature", + "properties": { + "type": "label", + "name": "Traffic Accident" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 24.94018793106079, + 60.16696293097573 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 24.943320751190186, + 60.166471893909794 + ], + [ + 24.934544563293453, + 60.16347213858629 + ], + [ + 24.93321418762207, + 60.16446497048834 + ], + [ + 24.94018793106079, + 60.16696293097573 + ], + [ + 24.93875026702881, + 60.16806240040351 + ], + [ + 24.937891960144043, + 60.16777419352904 + ], + [ + 24.936089515686035, + 60.169033745694826 + ], + [ + 24.9384069442749, + 60.16984495711831 + ], + [ + 24.942440986633297, + 60.16715507391703 + ] + ] + } + } + ] +} diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 62fe778035..75f5d112ca 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -694,6 +694,8 @@ void QMapboxGL::addSource(const QString &sourceID, const QVariantMap ¶ms) using namespace mbgl::style; using namespace mbgl::style::conversion; + removeSource(sourceID); + Result<std::unique_ptr<Source>> source = convert<std::unique_ptr<Source>>(QVariant(params), sourceID.toStdString()); if (!source) { qWarning() << "Unable to add source:" << source.error().message.c_str(); @@ -705,7 +707,11 @@ void QMapboxGL::addSource(const QString &sourceID, const QVariantMap ¶ms) void QMapboxGL::removeSource(const QString& sourceID) { - d_ptr->mapObj->removeSource(sourceID.toStdString()); + auto sourceIDStdString = sourceID.toStdString(); + + if (d_ptr->mapObj->getSource(sourceIDStdString)) { + d_ptr->mapObj->removeSource(sourceIDStdString); + } } void QMapboxGL::addCustomLayer(const QString &id, |