Marble

KmlLineStringTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
4// SPDX-FileCopyrightText: 2014 Marek Hakala <hakala.marek@gmail.com>
5//
6
7#include "KmlLineStringTagWriter.h"
8
9#include "GeoDataLineString.h"
10#include "GeoDataTypes.h"
11#include "GeoDataCoordinates.h"
12#include "GeoWriter.h"
13#include "KmlElementDictionary.h"
14#include "KmlObjectTagWriter.h"
15
16namespace Marble
17{
18
19static GeoTagWriterRegistrar s_writerLookAt(
20 GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataLineStringType,
21 kml::kmlTag_nameSpaceOgc22 ),
22 new KmlLineStringTagWriter );
23
24bool KmlLineStringTagWriter::write( const GeoNode *node, GeoWriter& writer ) const
25{
26 const GeoDataLineString *lineString = static_cast<const GeoDataLineString*>( node );
27
28 if ( lineString->size() > 1 )
29 {
30 writer.writeStartElement( kml::kmlTag_LineString );
31 KmlObjectTagWriter::writeIdentifiers( writer, lineString );
32 writer.writeOptionalElement( kml::kmlTag_extrude, QString::number( lineString->extrude() ), "0" );
33 writer.writeOptionalElement( kml::kmlTag_tessellate, QString::number( lineString->tessellate() ), "0" );
34 writer.writeStartElement( "coordinates" );
35
36 // Write altitude for *all* elements, if *any* element
37 // has altitude information (!= 0.0)
38 bool hasAltitude = false;
39 for ( int i = 0; i < lineString->size(); ++i ) {
40 if ( lineString->at( i ).altitude() ) {
41 hasAltitude = true;
42 break;
43 }
44 }
45
46 for ( int i = 0; i < lineString->size(); ++i ) {
47 GeoDataCoordinates coordinates = lineString->at( i );
48 if ( i > 0 )
49 {
50 writer.writeCharacters( " " );
51 }
52
53 qreal lon = coordinates.longitude( GeoDataCoordinates::Degree );
54 writer.writeCharacters( QString::number( lon, 'f', 10 ) );
55 writer.writeCharacters( "," );
56 qreal lat = coordinates.latitude( GeoDataCoordinates::Degree );
57 writer.writeCharacters( QString::number( lat, 'f', 10 ) );
58
59 if ( hasAltitude ) {
60 qreal alt = coordinates.altitude();
61 writer.writeCharacters( "," );
62 writer.writeCharacters( QString::number( alt, 'f', 2 ) );
63 }
64 }
65
66 writer.writeEndElement();
67 writer.writeEndElement();
68
69 return true;
70 }
71
72 return false;
73}
74
75}
QPair< QString, QString > QualifiedName
Object Name and Namespace Pair This type is intended to be used in a similar way to.
Binds a QML item to a specific geodetic location in screen coordinates.
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:54:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.