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 "KmlElementDictionary.h"
9#include "GeoDataExtendedData.h"
10#include "GeoDataGeometry.h"
11#include "GeoDataPlacemark.h"
12#include "GeoDataLinearRing.h"
13#include "GeoDataPolygon.h"
14#include "GeoDataData.h"
15#include "GeoParser.h"
16#include "GeoDataPoint.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 OsmPlacemarkData* placemarkOsmData = parser.parentElement( 1 ).nodeAs<OsmPlacemarkData>();
51 GeoDataPoint *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 OsmPlacemarkData *placemarkOsmData = parser.parentElement( 1 ).nodeAs<OsmPlacemarkData>();
71 GeoDataPlacemark *placemark = parser.parentElement( 3 ).nodeAs<GeoDataPlacemark>();
72 GeoDataLinearRing &ring = *parser.parentElement().nodeAs<GeoDataLinearRing>();
73 GeoDataPolygon *polygon = geodata_cast<GeoDataPolygon>(placemark->geometry());
74 if (!polygon) {
75 return nullptr;
76 }
77
78 /* The QVector'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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.