6#include "routeoverlay.h"
8using namespace KOSMIndoorRouting;
10RouteOverlay::RouteOverlay(
QObject *parent)
15RouteOverlay::~RouteOverlay() =
default;
20 if (mapData.isEmpty()) {
24 m_mxRouteKey = m_data.dataSet().
makeTagKey(
"mx:routing");
28void RouteOverlay::setStart(OSM::Coordinate c,
int floorLevel)
31 m_gc.push_back(std::move(m_startNode));
34 m_startNode = OSM::UniqueElement(
new OSM::Node);
35 m_startNode.setId(m_data.dataSet().nextInternalId());
36 m_startNode.node()->coordinate = c;
37 m_startNode.setTagValue(m_mxRouteKey,
"start");
38 m_startLevel = floorLevel;
43void RouteOverlay::setEnd(OSM::Coordinate c,
int floorLevel)
46 m_gc.push_back(std::move(m_endNode));
49 m_endNode = OSM::UniqueElement(
new OSM::Node);
50 m_endNode.setId(m_data.dataSet().nextInternalId());
51 m_endNode.node()->coordinate = c;
52 m_endNode.setTagValue(m_mxRouteKey,
"end");
53 m_endLevel = floorLevel;
58void RouteOverlay::setRoute(
const Route &route)
60 for (
auto &way : m_routeWays) {
61 m_gc.push_back(std::move(way));
64 m_routeWayFloorLevels.clear();
65 m_transientNodesGC.push_back(std::move(m_transientNodes));
68 if (m_route.steps().size() < 2) {
73 m_transientNodes.reserve(m_route.steps().size());
74 OSM::BoundingBox bbox;
76 int prevLevel = m_route.steps()[0].floorLevel;
78 OSM::UniqueElement way;
79 for (
auto it = m_route.steps().begin(); it != m_route.steps().end();) {
81 bbox = OSM::unite(bbox, {(*it).coordinate, (*it).coordinate});
84 way = OSM::UniqueElement(
new OSM::Way);
85 way.setId(m_data.dataSet().nextInternalId());
86 way.setTagValue(m_mxRouteKey,
"route");
90 node.id = m_data.dataSet().nextInternalId();
91 node.coordinate = (*it).coordinate;
92 way.way()->nodes.push_back(node.id);
93 m_transientNodes.push_back(std::move(node));
95 if (way.way()->nodes.size() >= 2 && (*it).floorLevel != prevLevel) {
96 m_routeWays.push_back(std::move(way));
97 m_routeWayFloorLevels.push_back(prevLevel);
98 prevLevel = (*it).floorLevel;
106 m_routeWays.push_back(std::move(way));
107 m_routeWayFloorLevels.push_back(prevLevel);
110 std::sort(m_transientNodes.begin(), m_transientNodes.end());
111 for (
auto &way :m_routeWays) {
112 way.way()->bbox = bbox;
118void RouteOverlay::forEach(
int floorLevel,
const std::function<
void(OSM::Element,
int)> &func)
const
120 for (std::size_t i = 0; i < m_routeWays.size(); ++i) {
121 if (floorLevel == m_routeWayFloorLevels[i]) {
122 func(m_routeWays[i], floorLevel);
126 if (m_startNode && m_startLevel == floorLevel) {
127 func(m_startNode, floorLevel);
129 if (m_endNode && m_endLevel == floorLevel) {
130 func(m_endNode, floorLevel);
134void RouteOverlay::endSwap()
137 m_transientNodesGC.clear();
140const std::vector<OSM::Node>* RouteOverlay::transientNodes()
const
142 return &m_transientNodes;
145#include "moc_routeoverlay.cpp"
void reset()
Trigger style re-compilation.
void update()
Trigger map re-rendering when the source changes.
Raw OSM map data, separated by levels.
TagKey makeTagKey(const char *keyName, StringMemory keyMemOpt=StringMemory::Transient)
Create a tag key for the given tag name.
OSM-based multi-floor indoor maps for buildings.