File indexing completed on 2025-01-05 03:59:13

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Shou Ya <shouyatf@gmail.com>
0004 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
0005 //
0006 
0007 #include "KmlGroundOverlayWriter.h"
0008 
0009 #include "GeoDataLatLonQuad.h"
0010 #include "GeoDataGroundOverlay.h"
0011 #include "GeoDataTypes.h"
0012 #include "GeoWriter.h"
0013 #include "KmlElementDictionary.h"
0014 
0015 namespace Marble
0016 {
0017 
0018 static GeoTagWriterRegistrar s_writerLookAt(
0019     GeoTagWriter::QualifiedName( QString::fromUtf8(GeoDataTypes::GeoDataGroundOverlayType),
0020                  QString::fromUtf8(kml::kmlTag_nameSpaceOgc22) ),
0021     new KmlGroundOverlayWriter );
0022 
0023 KmlGroundOverlayWriter::KmlGroundOverlayWriter() : KmlOverlayTagWriter( QString::fromUtf8(kml::kmlTag_GroundOverlay) )
0024 {
0025     // nothing to do
0026 }
0027 
0028 bool KmlGroundOverlayWriter::writeMid(const GeoNode *node, GeoWriter &writer) const
0029 {
0030     KmlOverlayTagWriter::writeMid( node, writer );
0031 
0032     const GeoDataGroundOverlay *ground_overlay =
0033         static_cast<const GeoDataGroundOverlay*>( node );
0034 
0035     writer.writeOptionalElement( QString::fromUtf8(kml::kmlTag_altitude),
0036                                  QString::number(ground_overlay->altitude()), QString::fromUtf8("0") );
0037     KmlGroundOverlayWriter::writeAltitudeMode( writer, ground_overlay->altitudeMode() );
0038 
0039     if ( !ground_overlay->latLonBox().isEmpty() ) {
0040         writeElement( &ground_overlay->latLonBox(), writer );
0041     }
0042 
0043     if ( ground_overlay->latLonQuad().isValid() ) {
0044         writeElement( &ground_overlay->latLonQuad(), writer );
0045     }
0046 
0047     return true;
0048 }
0049 
0050 QString KmlGroundOverlayWriter::altitudeModeToString(AltitudeMode mode)
0051 {
0052     switch (mode) {
0053     case ClampToGround:
0054     return QString::fromUtf8("clampToGround");
0055     case RelativeToGround:
0056     return QString::fromUtf8("relativeToGround");
0057     case ClampToSeaFloor:
0058     return QString::fromUtf8("clampToSeaFloor");
0059     case RelativeToSeaFloor:
0060     return QString::fromUtf8("relativeToSeaFloor");
0061     case Absolute:
0062     return QString::fromUtf8("absolute");
0063     }
0064     return QString::fromUtf8("");
0065 }
0066 
0067 void KmlGroundOverlayWriter::writeAltitudeMode(GeoWriter& writer, AltitudeMode altMode)
0068 {
0069     if ( altMode == ClampToGround ) {
0070         // clampToGround is always the default value, so we never have to write it
0071         return;
0072     }
0073 
0074     const QString altitudeMode = KmlGroundOverlayWriter::altitudeModeToString( altMode );
0075     bool const isGoogleExtension = ( altMode == ClampToSeaFloor || altMode == RelativeToSeaFloor );
0076     if ( isGoogleExtension ) {
0077         // clampToSeaFloor and relativeToSeaFloor are Google extensions that need a gx: tag namespace
0078         writer.writeElement( QString::fromUtf8(kml::kmlTag_nameSpaceGx22), QString::fromUtf8(kml::kmlTag_altitudeMode), altitudeMode);
0079     } else {
0080         writer.writeElement( QString::fromUtf8(kml::kmlTag_altitudeMode), altitudeMode );
0081     }
0082 }
0083 
0084 }
0085