Marble

KmlOsmPlacemarkDataTagHandler.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Marius-Valeriu Stanciu <stanciumarius94@gmail.com>
4//
5
6// Marble
7#include "KmlOsmPlacemarkDataTagHandler.h"
8#include "GeoDataData.h"
9#include "GeoDataExtendedData.h"
10#include "GeoDataGeometry.h"
11#include "GeoDataLinearRing.h"
12#include "GeoDataPlacemark.h"
13#include "GeoDataPoint.h"
14#include "GeoDataPolygon.h"
15#include "GeoParser.h"
16#include "KmlElementDictionary.h"
17#include "osm/OsmPlacemarkData.h"
18
19#include <QVariant>
20
21namespace Marble
22{
23namespace kml
24{
25KML_DEFINE_TAG_HANDLER_MX(OsmPlacemarkData)
26
27GeoNode *KmlOsmPlacemarkDataTagHandler::parse(GeoParser &parser) const
28{
29 OsmPlacemarkData osmData = OsmPlacemarkData::fromParserAttributes(parser.attributes());
30 /* Case 1: This is the main OsmPlacemarkData of a placemark:
31 * <Placemark>
32 * <ExtendedData>
33 * <mx:OsmPlacemarkData>
34 * ...
35 */
36 if (parser.parentElement().is<GeoDataExtendedData>() && parser.parentElement(1).is<GeoDataPlacemark>()) {
37 auto placemark = parser.parentElement(1).nodeAs<GeoDataPlacemark>();
38 placemark->setOsmData(osmData);
39 return &placemark->osmData();
40 }
41 /* Case 2: This is the OsmPlacemarkData of a Nd
42 * <Placemark>
43 * <ExtendedData>
44 * <mx:OsmPlacemarkData>
45 * <mx:nd>
46 * <mx:OsmPlacemarkData>
47 * ...
48 */
49 else if (parser.parentElement(1).is<OsmPlacemarkData>() && parser.parentElement().is<GeoDataPoint>()) {
50 auto placemarkOsmData = parser.parentElement(1).nodeAs<OsmPlacemarkData>();
51 auto point = parser.parentElement().nodeAs<GeoDataPoint>();
52 GeoDataCoordinates coordinates = point->coordinates();
53 /* The GeoDataPoint object was only used as GeoNode wrapper for the GeoDataCoordinates
54 * and it is no longer needed
55 */
56 delete point;
57 placemarkOsmData->addNodeReference(coordinates, osmData);
58 return &placemarkOsmData->nodeReference(coordinates);
59 }
60 /* Case 3: This is the OsmPlacemarkData of a polygon's member
61 * <Placemark>
62 * <ExtendedData>
63 * <mx:OsmPlacemarkData>
64 * <mx:member>
65 * <mx:OsmPlacemarkData>
66 * ...
67 */
68 else if (parser.parentElement(1).is<OsmPlacemarkData>() && parser.parentElement().is<GeoDataLinearRing>()
69 && parser.parentElement(3).is<GeoDataPlacemark>()) {
70 auto placemarkOsmData = parser.parentElement(1).nodeAs<OsmPlacemarkData>();
71 auto placemark = parser.parentElement(3).nodeAs<GeoDataPlacemark>();
72 GeoDataLinearRing &ring = *parser.parentElement().nodeAs<GeoDataLinearRing>();
73 auto polygon = geodata_cast<GeoDataPolygon>(placemark->geometry());
74 if (!polygon) {
75 return nullptr;
76 }
77
78 /* The QList's indexOf function is perfect: returns the index of the ring
79 * within the vector if the ring is an innerBoundary;
80 * Else it returns -1, meaning it's an outerBoundary
81 */
82 int memberIndex = polygon->innerBoundaries().indexOf(ring);
83
84 placemarkOsmData->addMemberReference(memberIndex, osmData);
85 return &placemarkOsmData->memberReference(memberIndex);
86 }
87 return nullptr;
88}
89}
90}
static OsmPlacemarkData fromParserAttributes(const QXmlStreamAttributes &attributes)
fromParserAttributes is a convenience function that parses all osm-related arguments of a tag
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 Dec 20 2024 11:52:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.