mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 05:13:58 +00:00
[traffic] Calculate filter list for active MWMs
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -266,12 +266,21 @@ void TrafficManager::UpdateViewport(ScreenBase const & screen)
|
|||||||
UpdateActiveMwms(screen.ClipRect(), m_lastDrapeMwmsByRect, m_activeDrapeMwms);
|
UpdateActiveMwms(screen.ClipRect(), m_lastDrapeMwmsByRect, m_activeDrapeMwms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TrafficManager::GetMwmFilters(std::set<MwmSet::MwmId> & mwms)
|
||||||
|
{
|
||||||
|
std::vector<m2::RectD> rects;
|
||||||
|
for (auto mwmId : mwms)
|
||||||
|
rects.push_back(mwmId.GetInfo()->m_bordersRect);
|
||||||
|
return traffxml::FiltersToXml(rects);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO make this work with multiple sources (e.g. Android)
|
// TODO make this work with multiple sources (e.g. Android)
|
||||||
bool TrafficManager::Subscribe(std::set<MwmSet::MwmId> & mwms)
|
bool TrafficManager::Subscribe(std::set<MwmSet::MwmId> & mwms)
|
||||||
{
|
{
|
||||||
// TODO what if we’re subscribed already?
|
// TODO what if we’re subscribed already?
|
||||||
|
std::string filterList = GetMwmFilters(mwms);
|
||||||
// TODO
|
// TODO
|
||||||
LOG(LINFO, ("Would subscribe to", mwms));
|
LOG(LINFO, ("Would subscribe to:\n", filterList));
|
||||||
m_subscriptionId = "placeholder_subscription_id";
|
m_subscriptionId = "placeholder_subscription_id";
|
||||||
m_isPollNeeded = true; // would be false if we got a feed here
|
m_isPollNeeded = true; // would be false if we got a feed here
|
||||||
return true;
|
return true;
|
||||||
@@ -280,9 +289,11 @@ bool TrafficManager::Subscribe(std::set<MwmSet::MwmId> & mwms)
|
|||||||
// TODO make this work with multiple sources (e.g. Android)
|
// TODO make this work with multiple sources (e.g. Android)
|
||||||
bool TrafficManager::ChangeSubscription(std::set<MwmSet::MwmId> & mwms)
|
bool TrafficManager::ChangeSubscription(std::set<MwmSet::MwmId> & mwms)
|
||||||
{
|
{
|
||||||
// TODO what if we’re not subscribed yet?
|
if (!IsSubscribed())
|
||||||
|
return false;
|
||||||
|
std::string filterList = GetMwmFilters(mwms);
|
||||||
// TODO
|
// TODO
|
||||||
LOG(LINFO, ("Would change subscription", m_subscriptionId, "to", mwms));
|
LOG(LINFO, ("Would change subscription", m_subscriptionId, "to:\n", filterList));
|
||||||
m_isPollNeeded = true; // would be false if we got a feed here
|
m_isPollNeeded = true; // would be false if we got a feed here
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -290,6 +301,7 @@ bool TrafficManager::ChangeSubscription(std::set<MwmSet::MwmId> & mwms)
|
|||||||
bool TrafficManager::SetSubscriptionArea()
|
bool TrafficManager::SetSubscriptionArea()
|
||||||
{
|
{
|
||||||
std::set<MwmSet::MwmId> activeMwms;
|
std::set<MwmSet::MwmId> activeMwms;
|
||||||
|
|
||||||
if (!IsSubscribed())
|
if (!IsSubscribed())
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -183,6 +183,14 @@ private:
|
|||||||
traffic::TrafficInfo::Availability m_lastAvailability;
|
traffic::TrafficInfo::Availability m_lastAvailability;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a TraFF filter list for a set of MWMs.
|
||||||
|
*
|
||||||
|
* @param mwms The MWMs for which a filter list is to be created.
|
||||||
|
* @return A `filter_list` in XML format.
|
||||||
|
*/
|
||||||
|
std::string GetMwmFilters(std::set<MwmSet::MwmId> & mwms);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Subscribes to a traffic service.
|
* @brief Subscribes to a traffic service.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -395,6 +395,22 @@ struct TraffMessage
|
|||||||
|
|
||||||
using TraffFeed = std::vector<TraffMessage>;
|
using TraffFeed = std::vector<TraffMessage>;
|
||||||
|
|
||||||
|
// TODO Capabilities
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Filter: currently not implemented.
|
||||||
|
* We only use bbox, for which we have a suitable data type.
|
||||||
|
* min_road_class is not needed as we do not filter by road class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TraffSubscription: currently not implemented.
|
||||||
|
* We just store the ID as a string.
|
||||||
|
* Filters are only by bbox, not by min_road_class. The list is auto-generated from the list of
|
||||||
|
* active MWMs and changes exactly when the active MWM set changes, eliminating the need to store
|
||||||
|
* the full filter list.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Guess the distance to the next point.
|
* @brief Guess the distance to the next point.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -643,4 +643,16 @@ bool ParseTraff(pugi::xml_document const & document, TraffFeed & feed)
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string FiltersToXml(std::vector<m2::RectD> & bboxRects)
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
for (auto rect : bboxRects)
|
||||||
|
os << std::format("<filter bbox=\"{} {} {} {}\"/>\n",
|
||||||
|
mercator::YToLat(rect.minY()),
|
||||||
|
mercator::XToLon(rect.minX()),
|
||||||
|
mercator::YToLat(rect.maxY()),
|
||||||
|
mercator::XToLon(rect.maxX()));
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
} // namespace openlr
|
} // namespace openlr
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
#include "traffxml/traff_model.hpp"
|
#include "traffxml/traff_model.hpp"
|
||||||
|
|
||||||
|
#include "geometry/rect2d.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace pugi
|
namespace pugi
|
||||||
{
|
{
|
||||||
class xml_document;
|
class xml_document;
|
||||||
@@ -11,4 +16,20 @@ class xml_node;
|
|||||||
namespace traffxml
|
namespace traffxml
|
||||||
{
|
{
|
||||||
bool ParseTraff(pugi::xml_document const & document, TraffFeed & feed);
|
bool ParseTraff(pugi::xml_document const & document, TraffFeed & feed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generates a list of XML `filter` elements from a vector of rects representing bboxes.
|
||||||
|
*
|
||||||
|
* The resulting string can be placed inside a TraFF XML `filter_list` element or can be passed as
|
||||||
|
* an extra to an Android intent.
|
||||||
|
*
|
||||||
|
* It will have one `filter` element for each element in `bboxRects`, although simplification may
|
||||||
|
* be applied to reduce the number of rects (currently not implemented).
|
||||||
|
*
|
||||||
|
* The `min_road_class` attribute is not used.
|
||||||
|
*
|
||||||
|
* @param bboxRects The rectangles, each of which represents a bounding box.
|
||||||
|
* @return A string of XML `filter` elements.
|
||||||
|
*/
|
||||||
|
std::string FiltersToXml(std::vector<m2::RectD> & bboxRects);
|
||||||
} // namespace traffxml
|
} // namespace traffxml
|
||||||
|
|||||||
Reference in New Issue
Block a user