Marble

KmlNdTagHandler.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Marius-Valeriu Stanciu <stanciumarius94@gmail.com>
4//
5
6// Self
7#include "KmlNdTagHandler.h"
8
9// Marble
10#include "GeoDataExtendedData.h"
11#include "GeoDataGeometry.h"
12#include "GeoDataLineString.h"
13#include "GeoDataLinearRing.h"
14#include "GeoDataPlacemark.h"
15#include "GeoDataPoint.h"
16#include "GeoDataPolygon.h"
17#include "KmlElementDictionary.h"
18#include "osm/OsmPlacemarkData.h"
19
20// Qt
21#include <QDebug>
22
23namespace Marble
24{
25namespace kml
26{
27KML_DEFINE_TAG_HANDLER_MX(nd)
28
29GeoNode *KmlndTagHandler::parse(GeoParser &parser) const
30{
31 int ndIndex = parser.attribute("index").toInt();
32 /* Case 1: node of a line placemark:
33 *...
34 * <Placemark>
35 * <ExtendedData>
36 * <mx:OsmPlacemarkData>
37 * <mx:nd index="0">...</nd>
38 * <mx:nd index="1">...</nd>
39 * ...
40 */
41 if (parser.parentElement().represents(kmlTag_OsmPlacemarkData) && parser.parentElement(2).is<GeoDataPlacemark>()) {
42 auto placemark = parser.parentElement(2).nodeAs<GeoDataPlacemark>();
43 if (auto lineString = geodata_cast<GeoDataLineString>(placemark->geometry())) {
44 // Using GeoDataPoint because GeoDataCoordinates is not a GeoNode, so it can't be returned.
45 auto point = new GeoDataPoint(lineString->at(ndIndex));
46 return point;
47 }
48 return nullptr;
49 }
50 /* Case 2: node of a polygon's boundary
51 *...
52 * <Placemark>
53 * <ExtendedData>
54 * <mx:OsmPlacemarkData>
55 * <mx:member>
56 * <mx:OsmPlacemarkData>
57 * <mx:nd index="0">...</nd>
58 * <mx:nd index="1">...</nd>
59 * ...
60 */
61 else if (parser.parentElement().represents(kmlTag_OsmPlacemarkData) && parser.parentElement(1).is<GeoDataLinearRing>()) {
62 auto linearRing = parser.parentElement(1).nodeAs<GeoDataLinearRing>();
63
64 // Using GeoDataPoint because GeoDataCoordinates is not a GeoNode, so it can't be returned.
65 auto point = new GeoDataPoint(linearRing->at(ndIndex));
66 return point;
67 }
68 return nullptr;
69}
70}
71}
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.