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 "GeoDataCoordinates.h"
10#include "GeoDataLineString.h"
11#include "GeoDataTypes.h"
12#include "GeoWriter.h"
13#include "KmlElementDictionary.h"
14#include "KmlObjectTagWriter.h"
15
16namespace Marble
17{
18
19static GeoTagWriterRegistrar s_writerLookAt(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataLineStringType),
20 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
21 new KmlLineStringTagWriter);
22
23bool KmlLineStringTagWriter::write(const GeoNode *node, GeoWriter &writer) const
24{
25 const auto lineString = static_cast<const GeoDataLineString *>(node);
26
27 if (lineString->size() > 1) {
28 writer.writeStartElement(QString::fromUtf8(kml::kmlTag_LineString));
29 KmlObjectTagWriter::writeIdentifiers(writer, lineString);
30 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_extrude), QString::number(lineString->extrude()), QStringLiteral("0"));
31 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_tessellate), QString::number(lineString->tessellate()), QStringLiteral("0"));
32 writer.writeStartElement("coordinates");
33
34 // Write altitude for *all* elements, if *any* element
35 // has altitude information (!= 0.0)
36 bool hasAltitude = false;
37 for (int i = 0; i < lineString->size(); ++i) {
38 if (lineString->at(i).altitude()) {
39 hasAltitude = true;
40 break;
41 }
42 }
43
44 for (int i = 0; i < lineString->size(); ++i) {
45 GeoDataCoordinates coordinates = lineString->at(i);
46 if (i > 0) {
47 writer.writeCharacters(" ");
48 }
49
50 qreal lon = coordinates.longitude(GeoDataCoordinates::Degree);
51 writer.writeCharacters(QString::number(lon, 'f', 10));
52 writer.writeCharacters(",");
53 qreal lat = coordinates.latitude(GeoDataCoordinates::Degree);
54 writer.writeCharacters(QString::number(lat, 'f', 10));
55
56 if (hasAltitude) {
57 qreal alt = coordinates.altitude();
58 writer.writeCharacters(",");
59 writer.writeCharacters(QString::number(alt, 'f', 2));
60 }
61 }
62
63 writer.writeEndElement();
64 writer.writeEndElement();
65
66 return true;
67 }
68
69 return false;
70}
71
72}
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 fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
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 Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.