Commit 6ed158bf authored by Volker Krause's avatar Volker Krause
Browse files

Add journey section path support for Navitia

parent 0a794330
Pipeline #50121 passed with stage
in 23 seconds
......@@ -87,6 +87,8 @@ private Q_SLOTS:
QVERIFY(!stop.expectedDepartureTime().isValid());
}
QCOMPARE(sec.co2Emission(), 147);
QCOMPARE(sec.path().isEmpty(), false);
QCOMPARE(sec.path().sections()[0].path().size(), 5);
sec = journey.sections()[2];
QCOMPARE(sec.mode(), KPublicTransport::JourneySection::Transfer);
......
......@@ -63,9 +63,10 @@ bool NavitiaBackend::queryJourney(const JourneyRequest &req, JourneyReply *reply
query.addQueryItem(QStringLiteral("datetime"), req.dateTime().toString(QStringLiteral("yyyyMMddThhmmss")));
query.addQueryItem(QStringLiteral("datetime_represents"), req.dateTimeMode() == JourneyRequest::Arrival ? QStringLiteral("arrival") : QStringLiteral("departure"));
}
query.addQueryItem(QStringLiteral("count"), QString::number(std::max(1, req.maximumResults())));
// TODO: disable reply parts we don't care about
query.addQueryItem(QStringLiteral("disable_geojson"), QStringLiteral("true")); // ### seems to have no effect?
query.addQueryItem(QStringLiteral("disable_geojson"), req.includePaths() ? QStringLiteral("false") : QStringLiteral("true"));
query.addQueryItem(QStringLiteral("depth"), QStringLiteral("0")); // ### also has no effect?
url.setQuery(query);
}
......
......@@ -5,6 +5,7 @@
*/
#include "navitiaparser.h"
#include "../geo/geojson_p.h"
#include <KPublicTransport/Attribution>
#include <KPublicTransport/Journey>
......@@ -210,6 +211,15 @@ JourneySection NavitiaParser::parseJourneySection(const QJsonObject &obj) const
const auto emissionObj = obj.value(QLatin1String("co2_emission")).toObject();
section.setCo2Emission(emissionObj.value(QLatin1String("value")).toDouble(-1));
const auto pathLineString = GeoJson::readLineString(obj.value(QLatin1String("geojson")).toObject());
if (!pathLineString.empty()) {
Path path;
PathSection pathSection;
pathSection.setPath(pathLineString);
path.setSections({pathSection});
section.setPath(std::move(path));
}
return section;
}
......
......@@ -36,7 +36,7 @@ QPointF GeoJson::readPoint(const QJsonObject &obj)
static QPolygonF readPolygonCoordinates(const QJsonArray &coords)
{
QPolygonF poly;
poly.resize(coords.size());
poly.reserve(coords.size());
for (const auto &pointV : coords) {
const auto point = pointV.toArray();
poly.push_back(readPointCoordinates(point));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment