Marble

KmlMemberTagHandler.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Marius-Valeriu Stanciu <stanciumarius94@gmail.com>
4//
5
6#include "KmlMemberTagHandler.h"
7
8#include "GeoDataGeometry.h"
9#include "GeoDataLinearRing.h"
10#include "GeoDataPlacemark.h"
11#include "GeoDataPolygon.h"
12#include "GeoDataTypes.h"
13#include "GeoParser.h"
14#include "KmlElementDictionary.h"
15#include "osm/OsmPlacemarkData.h"
16
17namespace Marble
18{
19namespace kml
20{
21KML_DEFINE_TAG_HANDLER_MX(member)
22
23GeoNode *KmlmemberTagHandler::parse(GeoParser &parser) const
24{
25 int memberIndex = parser.attribute("index").toInt();
26 /* Only possible case: member of polygon placemark:
27 *...
28 * <Placemark>
29 * <ExtendedData>
30 * <mx:OsmPlacemarkData>
31 * <mx:member index="-1">
32 * <mx:OsmPlacemarkData>
33 * <mx:nd index="0">...</nd>
34 * <mx:nd index="1">...</nd>
35 * ...
36 */
37 if (parser.parentElement(2).is<GeoDataPlacemark>()) {
38 auto placemark = parser.parentElement(2).nodeAs<GeoDataPlacemark>();
39 auto polygon = geodata_cast<GeoDataPolygon>(placemark->geometry());
40 if (!polygon) {
41 return nullptr;
42 }
43
44 // The memberIndex is used to determine which member this tag represents
45 if (memberIndex == -1) {
46 return &polygon->outerBoundary();
47 } else {
48 if (memberIndex >= polygon->innerBoundaries().size()) {
49 return nullptr;
50 }
51 return &polygon->innerBoundaries()[memberIndex];
52 }
53 }
54
55 return nullptr;
56}
57
58}
59}
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 Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.