[Qt] Remove route before adding

This will allow to bind a GeoJSON to the source data property
without throwing an exception.
This commit is contained in:
Thiago Marcos P. Santos
2016-12-08 17:55:49 -02:00
committed by Thiago Marcos P. Santos
parent a8c2688ca3
commit 97df99c134
5 changed files with 132 additions and 7 deletions

View File

@@ -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

View File

@@ -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>

View File

@@ -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
]
]
}
}
]
}

View File

@@ -694,6 +694,8 @@ void QMapboxGL::addSource(const QString &sourceID, const QVariantMap &params)
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 &params)
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,