File indexing completed on 2024-06-02 03:51:04

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2015 Marius-Valeriu Stanciu <stanciumarius94@gmail.com>
0004 //
0005 
0006 // Self
0007 #include "KmlNdTagHandler.h"
0008 
0009 // Marble
0010 #include "KmlElementDictionary.h"
0011 #include "GeoDataExtendedData.h"
0012 #include "GeoDataGeometry.h"
0013 #include "GeoDataPlacemark.h"
0014 #include "GeoDataLineString.h"
0015 #include "GeoDataLinearRing.h"
0016 #include "GeoDataPolygon.h"
0017 #include "GeoDataPoint.h"
0018 #include "osm/OsmPlacemarkData.h"
0019 
0020 // Qt
0021 #include <QDebug>
0022 
0023 namespace Marble
0024 {
0025 namespace kml
0026 {
0027 KML_DEFINE_TAG_HANDLER_MX( nd )
0028 
0029 GeoNode* KmlndTagHandler::parse( GeoParser& parser ) const
0030 {
0031     int ndIndex = parser.attribute( "index" ).toInt();
0032     /* Case 1: node of a line placemark:
0033      *...
0034      * <Placemark>
0035      *      <ExtendedData>
0036      *          <mx:OsmPlacemarkData>
0037      *              <mx:nd index="0">...</nd>
0038      *              <mx:nd index="1">...</nd>
0039      * ...
0040      */
0041     if( parser.parentElement().represents( kmlTag_OsmPlacemarkData ) && parser.parentElement( 2 ).is<GeoDataPlacemark>() ) {
0042         GeoDataPlacemark *placemark = parser.parentElement( 2 ).nodeAs<GeoDataPlacemark>();
0043         if (auto lineString = geodata_cast<GeoDataLineString>(placemark->geometry())) {
0044             // Using GeoDataPoint because GeoDataCoordinates is not a GeoNode, so it can't be returned.
0045             GeoDataPoint *point = new GeoDataPoint( lineString->at( ndIndex ) );
0046             return point;
0047         }
0048         return nullptr;
0049     }
0050     /* Case 2: node of a polygon's boundary
0051     *...
0052     * <Placemark>
0053     *      <ExtendedData>
0054     *          <mx:OsmPlacemarkData>
0055     *              <mx:member>
0056     *                   <mx:OsmPlacemarkData>
0057     *                       <mx:nd index="0">...</nd>
0058     *                       <mx:nd index="1">...</nd>
0059     * ...
0060     */
0061     else if ( parser.parentElement().represents( kmlTag_OsmPlacemarkData ) && parser.parentElement( 1 ).is<GeoDataLinearRing>() ) {
0062         GeoDataLinearRing *linearRing = parser.parentElement( 1 ).nodeAs<GeoDataLinearRing>();
0063 
0064         // Using GeoDataPoint because GeoDataCoordinates is not a GeoNode, so it can't be returned.
0065         GeoDataPoint *point = new GeoDataPoint( linearRing->at( ndIndex ) );
0066         return point;
0067     }
0068     return nullptr;
0069 }
0070 }
0071 }