Marble

KmlGroundOverlayWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2012 Shou Ya <shouyatf@gmail.com>
4// SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
5//
6
7#include "KmlGroundOverlayWriter.h"
8
9#include "GeoDataGroundOverlay.h"
10#include "GeoDataLatLonQuad.h"
11#include "GeoDataTypes.h"
12#include "GeoWriter.h"
13#include "KmlElementDictionary.h"
14
15namespace Marble
16{
17
18static GeoTagWriterRegistrar s_writerLookAt(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoDataTypes::GeoDataGroundOverlayType),
19 QString::fromLatin1(kml::kmlTag_nameSpaceOgc22)),
20 new KmlGroundOverlayWriter);
21
22KmlGroundOverlayWriter::KmlGroundOverlayWriter()
23 : KmlOverlayTagWriter(QString::fromLatin1(kml::kmlTag_GroundOverlay))
24{
25 // nothing to do
26}
27
28bool KmlGroundOverlayWriter::writeMid(const GeoNode *node, GeoWriter &writer) const
29{
30 KmlOverlayTagWriter::writeMid(node, writer);
31
32 const auto ground_overlay = static_cast<const GeoDataGroundOverlay *>(node);
33
34 writer.writeOptionalElement(QLatin1String(kml::kmlTag_altitude), QString::number(ground_overlay->altitude()), QStringLiteral("0"));
35 KmlGroundOverlayWriter::writeAltitudeMode(writer, ground_overlay->altitudeMode());
36
37 if (!ground_overlay->latLonBox().isEmpty()) {
38 writeElement(&ground_overlay->latLonBox(), writer);
39 }
40
41 if (ground_overlay->latLonQuad().isValid()) {
42 writeElement(&ground_overlay->latLonQuad(), writer);
43 }
44
45 return true;
46}
47
48QString KmlGroundOverlayWriter::altitudeModeToString(AltitudeMode mode)
49{
50 switch (mode) {
51 case ClampToGround:
52 return QStringLiteral("clampToGround");
54 return QStringLiteral("relativeToGround");
55 case ClampToSeaFloor:
56 return QStringLiteral("clampToSeaFloor");
58 return QStringLiteral("relativeToSeaFloor");
59 case Absolute:
60 return QStringLiteral("absolute");
61 }
62 return {};
63}
64
65void KmlGroundOverlayWriter::writeAltitudeMode(GeoWriter &writer, AltitudeMode altMode)
66{
67 if (altMode == ClampToGround) {
68 // clampToGround is always the default value, so we never have to write it
69 return;
70 }
71
72 const QString altitudeMode = KmlGroundOverlayWriter::altitudeModeToString(altMode);
73 bool const isGoogleExtension = (altMode == ClampToSeaFloor || altMode == RelativeToSeaFloor);
74 if (isGoogleExtension) {
75 // clampToSeaFloor and relativeToSeaFloor are Google extensions that need a gx: tag namespace
76 writer.writeElement(QString::fromLatin1(kml::kmlTag_nameSpaceGx22), QString::fromLatin1(kml::kmlTag_altitudeMode), altitudeMode);
77 } else {
78 writer.writeElement(QString::fromLatin1(kml::kmlTag_altitudeMode), altitudeMode);
79 }
80}
81
82}
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.
@ RelativeToGround
Altitude is always given relative to ground level.
@ ClampToSeaFloor
Altitude always sticks to sea floor.
@ ClampToGround
Altitude always sticks to ground level.
@ RelativeToSeaFloor
Altitude is given relative to the sea floor.
@ Absolute
Altitude is given relative to the sealevel.
QString fromLatin1(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.