6 #include "KmlIconStyleTagWriter.h"
8 #include "GeoDataIconStyle.h"
9 #include "GeoDataTypes.h"
10 #include "GeoWriter.h"
11 #include "KmlElementDictionary.h"
16 static GeoTagWriterRegistrar s_writerIconStyle(
18 kml::kmlTag_nameSpaceOgc22 ),
19 new KmlIconStyleTagWriter );
21 KmlIconStyleTagWriter::KmlIconStyleTagWriter() : KmlColorStyleTagWriter( kml::kmlTag_IconStyle )
26 bool KmlIconStyleTagWriter::writeMid(
const GeoNode *node, GeoWriter& writer )
const
28 const GeoDataIconStyle *style =
static_cast<const GeoDataIconStyle*
>( node );
30 if ( style->scale() != 1.0 ) {
31 writer.writeElement( kml::kmlTag_scale,
QString::number( style->scale(),
'f' ) );
34 if (!style->size().isEmpty()) {
35 writer.writeNamespace(kml::kmlTag_nameSpaceMx, QStringLiteral(
"mx"));
36 writer.writeStartElement(kml::kmlTag_nameSpaceMx, kml::kmlTag_size);
37 writer.writeAttribute(kml::kmlTag_width,
QString::number(style->size().width()));
38 writer.writeAttribute(kml::kmlTag_height,
QString::number(style->size().height()));
39 writer.writeEndElement();
42 if ( !style->iconPath().isEmpty() ) {
43 writer.writeStartElement( kml::kmlTag_Icon );
44 writer.writeStartElement( kml::kmlTag_href );
45 writer.writeCharacters( style->iconPath() );
46 writer.writeEndElement();
47 writer.writeEndElement();
50 GeoDataHotSpot::Units xunits, yunits;
51 QPointF const hotSpot = style->hotSpot( xunits, yunits );
52 bool const emptyHotSpot = hotSpot.
x() == 0.5 && hotSpot.
y() == 0.5 &&
53 xunits == GeoDataHotSpot::Fraction && yunits == GeoDataHotSpot::Fraction;
54 if ( !emptyHotSpot ) {
55 writer.writeStartElement( kml::kmlTag_hotSpot );
56 if ( hotSpot.
x() != 0.5 || xunits != GeoDataHotSpot::Fraction ) {
59 if ( hotSpot.
y() != 0.5 || yunits != GeoDataHotSpot::Fraction ) {
63 if ( xunits != GeoDataHotSpot::Fraction ) {
64 writer.writeAttribute(
"xunits", unitString( xunits ) );
66 if ( yunits != GeoDataHotSpot::Fraction ) {
67 writer.writeAttribute(
"yunits", unitString( yunits ) );
69 writer.writeEndElement();
75 bool KmlIconStyleTagWriter::isEmpty(
const GeoNode *node )
const
77 const GeoDataIconStyle *style =
static_cast<const GeoDataIconStyle*
>( node );
78 GeoDataHotSpot::Units xunits, yunits;
79 QPointF const hotSpot = style->hotSpot( xunits, yunits );
80 return style->iconPath().isEmpty() &&
83 xunits == GeoDataHotSpot::Fraction &&
84 yunits == GeoDataHotSpot::Fraction;
87 QString KmlIconStyleTagWriter::unitString(GeoDataHotSpot::Units unit)
90 case GeoDataHotSpot::Pixels:
return "pixels";
91 case GeoDataHotSpot::InsetPixels:
return "insetPixels";
92 case GeoDataHotSpot::Fraction:
return "fraction";