Marble

KmlGroundOverlayWriter.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2012 Shou Ya <[email protected]>
4 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <[email protected]>
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 
15 namespace Marble
16 {
17 
18 static GeoTagWriterRegistrar s_writerLookAt(
19  GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataGroundOverlayType,
20  kml::kmlTag_nameSpaceOgc22 ),
21  new KmlGroundOverlayWriter );
22 
23 KmlGroundOverlayWriter::KmlGroundOverlayWriter() : KmlOverlayTagWriter( kml::kmlTag_GroundOverlay )
24 {
25  // nothing to do
26 }
27 
28 bool 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 
50 QString KmlGroundOverlayWriter::altitudeModeToString(AltitudeMode mode)
51 {
52  switch (mode) {
53  case ClampToGround:
54  return "clampToGround";
55  case RelativeToGround:
56  return "relativeToGround";
57  case ClampToSeaFloor:
58  return "clampToSeaFloor";
59  case RelativeToSeaFloor:
60  return "relativeToSeaFloor";
61  case Absolute:
62  return "absolute";
63  }
64  return "";
65 }
66 
67 void 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 
@ RelativeToSeaFloor
Altitude is given relative to the sea floor.
Definition: MarbleGlobal.h:135
QString number(int n, int base)
QPair< QString, QString > QualifiedName
Object Name and Namespace Pair This type is intended to be used in a similar way to.
Definition: GeoTagWriter.h:44
@ ClampToSeaFloor
Altitude always sticks to sea floor.
Definition: MarbleGlobal.h:136
Binds a QML item to a specific geodetic location in screen coordinates.
@ Absolute
Altitude is given relative to the sealevel.
Definition: MarbleGlobal.h:134
@ ClampToGround
Altitude always sticks to ground level.
Definition: MarbleGlobal.h:132
@ RelativeToGround
Altitude is always given relative to ground level.
Definition: MarbleGlobal.h:133
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Oct 4 2023 04:09:42 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.