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 "GeoDataLatLonQuad.h"
10#include "GeoDataGroundOverlay.h"
11#include "GeoDataTypes.h"
12#include "GeoWriter.h"
13#include "KmlElementDictionary.h"
14
15namespace Marble
16{
17
18static GeoTagWriterRegistrar s_writerLookAt(
19 GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataGroundOverlayType,
20 kml::kmlTag_nameSpaceOgc22 ),
21 new KmlGroundOverlayWriter );
22
23KmlGroundOverlayWriter::KmlGroundOverlayWriter() : KmlOverlayTagWriter( 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 GeoDataGroundOverlay *ground_overlay =
33 static_cast<const GeoDataGroundOverlay*>( node );
34
35 writer.writeOptionalElement( kml::kmlTag_altitude,
36 QString::number(ground_overlay->altitude()), "0" );
37 KmlGroundOverlayWriter::writeAltitudeMode( writer, ground_overlay->altitudeMode() );
38
39 if ( !ground_overlay->latLonBox().isEmpty() ) {
40 writeElement( &ground_overlay->latLonBox(), writer );
41 }
42
43 if ( ground_overlay->latLonQuad().isValid() ) {
44 writeElement( &ground_overlay->latLonQuad(), writer );
45 }
46
47 return true;
48}
49
50QString KmlGroundOverlayWriter::altitudeModeToString(AltitudeMode mode)
51{
52 switch (mode) {
53 case ClampToGround:
54 return "clampToGround";
56 return "relativeToGround";
57 case ClampToSeaFloor:
58 return "clampToSeaFloor";
60 return "relativeToSeaFloor";
61 case Absolute:
62 return "absolute";
63 }
64 return "";
65}
66
67void KmlGroundOverlayWriter::writeAltitudeMode(GeoWriter& writer, AltitudeMode altMode)
68{
69 if ( altMode == ClampToGround ) {
70 // clampToGround is always the default value, so we never have to write it
71 return;
72 }
73
74 const QString altitudeMode = KmlGroundOverlayWriter::altitudeModeToString( altMode );
75 bool const isGoogleExtension = ( altMode == ClampToSeaFloor || altMode == RelativeToSeaFloor );
76 if ( isGoogleExtension ) {
77 // clampToSeaFloor and relativeToSeaFloor are Google extensions that need a gx: tag namespace
78 writer.writeElement( kml::kmlTag_nameSpaceGx22, kml::kmlTag_altitudeMode, altitudeMode);
79 } else {
80 writer.writeElement( kml::kmlTag_altitudeMode, altitudeMode );
81 }
82}
83
84}
85
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 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 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.