Commit 09d2c108 authored by Volker Krause's avatar Volker Krause
Browse files

Parse GBFS geofencing zones and use that for the ounding box computation

parent 1956156c
......@@ -5,6 +5,7 @@
*/
#include "gbfsjob.h"
#include "geo/geojson_p.h"
#include <KPublicTransport/Location>
......@@ -12,6 +13,8 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkReply>
#include <QPolygonF>
#include <QVersionNumber>
#include <cassert>
#include <cmath>
......@@ -237,6 +240,8 @@ void GBFSJob::parseData(const QJsonDocument &doc, GBFS::FileType type)
case GBFS::Versions:
parseVersionData(doc);
break;
case GBFS::GeofencingZones:
parseGeofencingZones(doc);
default:
break;
}
......@@ -367,11 +372,24 @@ void GBFSJob::parseVersionData(const QJsonDocument &doc)
}
}
void GBFSJob::parseGeofencingZones(const QJsonDocument &doc)
{
const auto features = doc.object().value(QLatin1String("data")).toObject()
.value(QLatin1String("geofencing_zones")).toObject()
.value(QLatin1String("features")).toArray();
for (const auto &featureVal : features) {
const auto geo = featureVal.toObject().value(QLatin1String("geometry")).toObject();
m_geofenceBoundingBox |= GeoJson::readOuterPolygon(geo).boundingRect();
}
qDebug() << "geo fence bounding box:" << m_geofenceBoundingBox;
}
void GBFSJob::finalize()
{
if (m_maxLat > m_minLat && m_maxLon > m_minLon) {
m_service.boundingBox = QRectF(QPointF(m_minLon, m_minLat), QPointF(m_maxLon, m_maxLat));
}
m_service.boundingBox |= m_geofenceBoundingBox;
GBFSServiceRepository::store(m_service);
Q_EMIT finished();
}
......@@ -14,6 +14,7 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QObject>
#include <QRectF>
#include <QUrl>
class QNetworkAccessManager;
......@@ -63,6 +64,7 @@ private:
void parseFreeBikeStatus(const QJsonDocument &doc);
void computeBoundingBox(const QJsonArray &array);
void parseVersionData(const QJsonDocument &doc);
void parseGeofencingZones(const QJsonDocument &doc);
void finalize();
QNetworkAccessManager *m_nam = nullptr;
......@@ -72,6 +74,7 @@ private:
QJsonArray m_feeds;
double m_minLat = 90.0, m_maxLat = -90.0, m_minLon = 180.0, m_maxLon = -180.0;
QRectF m_geofenceBoundingBox;
QString m_errorMsg;
Error m_error = NoError;
......
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