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 "KmlElementDictionary.h"
11#include "GeoDataExtendedData.h"
12#include "GeoDataGeometry.h"
13#include "GeoDataPlacemark.h"
14#include "GeoDataLineString.h"
15#include "GeoDataLinearRing.h"
16#include "GeoDataPolygon.h"
17#include "GeoDataPoint.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 GeoDataPlacemark *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 GeoDataPoint *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 GeoDataLinearRing *linearRing = parser.parentElement( 1 ).nodeAs<GeoDataLinearRing>();
63
64 // Using GeoDataPoint because GeoDataCoordinates is not a GeoNode, so it can't be returned.
65 GeoDataPoint *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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:50:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.