Marble

OsmObjectManager.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Stanciu Marius-Valeriu <stanciumarius94@gmail.com>
4//
5
6// Self
7#include "OsmObjectManager.h"
8
9// Marble
10#include "GeoDataBuilding.h"
11#include "GeoDataLinearRing.h"
12#include "GeoDataMultiGeometry.h"
13#include "GeoDataPlacemark.h"
14#include "GeoDataPolygon.h"
15#include "osm/OsmPlacemarkData.h"
16
17namespace Marble
18{
19
20qint64 OsmObjectManager::m_minId = -1;
21
23{
24 OsmPlacemarkData &osmData = placemark->osmData();
25
26 bool isNull = osmData.isNull();
27 if (isNull) {
28 // The "--m_minId" assignments mean: assigning an id lower( by 1 ) than the current lowest,
29 // and updating the current lowest id.
30 osmData.setId(--m_minId);
31 }
32
33 // Assigning osmData to each of the line's nodes ( if they don't already have data )
34 if (const auto lineString = geodata_cast<GeoDataLineString>(placemark->geometry())) {
35 QList<GeoDataCoordinates>::const_iterator it = lineString->constBegin();
36 QList<GeoDataCoordinates>::ConstIterator const end = lineString->constEnd();
37
38 for (; it != end; ++it) {
39 if (osmData.nodeReference(*it).isNull()) {
40 osmData.nodeReference(*it).setId(--m_minId);
41 }
42 }
43 }
44
45 const auto building = geodata_cast<GeoDataBuilding>(placemark->geometry());
46
47 const GeoDataLinearRing *lineString;
48 if (building) {
49 lineString = geodata_cast<GeoDataLinearRing>(&static_cast<const GeoDataMultiGeometry *>(building->multiGeometry())->at(0));
50 } else {
51 lineString = geodata_cast<GeoDataLinearRing>(placemark->geometry());
52 }
53 // Assigning osmData to each of the line's nodes ( if they don't already have data )
54 if (lineString) {
55 for (auto it = lineString->constBegin(), end = lineString->constEnd(); it != end; ++it) {
56 if (osmData.nodeReference(*it).isNull()) {
57 osmData.nodeReference(*it).setId(--m_minId);
58 }
59 }
60 }
61
62 const GeoDataPolygon *polygon;
63 if (building) {
64 polygon = geodata_cast<GeoDataPolygon>(&static_cast<const GeoDataMultiGeometry *>(building->multiGeometry())->at(0));
65 } else {
66 polygon = geodata_cast<GeoDataPolygon>(placemark->geometry());
67 }
68 // Assigning osmData to each of the polygons boundaries, and to each of the
69 // nodes that are part of those boundaries ( if they don't already have data )
70 if (polygon) {
71 const GeoDataLinearRing &outerBoundary = polygon->outerBoundary();
72 int index = -1;
73 if (isNull) {
74 osmData.addTag(QStringLiteral("type"), QStringLiteral("multipolygon"));
75 }
76
77 // Outer boundary
78 OsmPlacemarkData &outerBoundaryData = osmData.memberReference(index);
79 if (outerBoundaryData.isNull()) {
80 outerBoundaryData.setId(--m_minId);
81 }
82
83 // Outer boundary nodes
85 QList<GeoDataCoordinates>::ConstIterator const end = outerBoundary.constEnd();
86
87 for (; it != end; ++it) {
88 if (outerBoundaryData.nodeReference(*it).isNull()) {
89 outerBoundaryData.nodeReference(*it).setId(--m_minId);
90 }
91 }
92
93 // Each inner boundary
94 for (const GeoDataLinearRing &innerRing : polygon->innerBoundaries()) {
95 ++index;
96 OsmPlacemarkData &innerRingData = osmData.memberReference(index);
97 if (innerRingData.isNull()) {
98 innerRingData.setId(--m_minId);
99 }
100
101 // Inner boundary nodes
102 QList<GeoDataCoordinates>::const_iterator it = innerRing.constBegin();
103 QList<GeoDataCoordinates>::ConstIterator const end = innerRing.constEnd();
104
105 for (; it != end; ++it) {
106 if (innerRingData.nodeReference(*it).isNull()) {
107 innerRingData.nodeReference(*it).setId(--m_minId);
108 }
109 }
110 }
111 }
112}
113
115{
116 m_minId = qMin(id, m_minId);
117}
118
119}
QList< GeoDataCoordinates >::ConstIterator constBegin() const
Returns a const iterator that points to the begin of the LineString.
QList< GeoDataCoordinates >::ConstIterator constEnd() const
Returns a const iterator that points to the end of the LineString.
A LinearRing that allows to store a closed, contiguous set of line segments.
A class that can contain other GeoDataGeometry objects.
a class representing a point of interest on the map
OsmPlacemarkData & osmData()
Quick, safe accessor to the placemark's OsmPlacemarkData stored within it's ExtendedData.
GeoDataGeometry * geometry()
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
A polygon that can have "holes".
GeoDataLinearRing & outerBoundary()
Returns the outer boundary that is represented as a LinearRing.
QList< GeoDataLinearRing > & innerBoundaries()
Returns a set of inner boundaries which are represented as LinearRings.
static void registerId(qint64 id)
registerId is used to keep track of the minimum id
static void initializeOsmData(GeoDataPlacemark *placemark)
initializeOsmData assigns valid osmData to a placemark that does not have it.
This class is used to encapsulate the osm data fields kept within a placemark's extendedData.
OsmPlacemarkData & nodeReference(const GeoDataCoordinates &coordinates)
this function returns the osmData associated with a nd
OsmPlacemarkData & memberReference(int key)
this function returns the osmData associated with a member boundary's index -1 represents the outer b...
bool isNull() const
isNull returns false if the osmData is loaded from a source or true if its just default constructed
void addTag(const QString &key, const QString &value)
addTag this function inserts a string key=value mapping, equivalent to the <tag k="@p key" v="@p valu...
Binds a QML item to a specific geodetic location in screen coordinates.
T * geodata_cast(GeoDataObject *node)
Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.