Search code examples
kmlgoogle-earthkmz

KML IconStyle color entered as blue but displays red in Google Earth


I'm using hexadecimal colors to label icons. For blue I'm using 0000ff. In the KML file it is as <color>ff0000ff</color>. However, when the KML is opened in Google Earth the icon placemark is red.

Looking at https://developers.google.com/kml/documentation/kmlreference my take is color should be coded as ff + hexadecimal number, therefore black is represented as ff000000, which works, but ff0000ff for blue does not.

I've tried various style and icon options without success. I've read and seen how there is a layering effect that will merge the icon and color. It seems using a wht-blank.png would be a neutral canvas to apply a color, but I suspect it could be interfering.

Below is my test kml.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
    <Document>
        <name>kml_test</name>
        <Placemark>
            <name>uniq_name</name>
            <Style>
                <IconStyle>
                    <scale>1</scale>
                    <color>ff0000ff</color>
                    <Icon>
                        <href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href>
                    </Icon>
                </IconStyle>
            </Style>
            <LabelStyle>
                <color>ffffffff</color>
                <scale>0.6</scale>
            </LabelStyle>
            <LookAt>
                <longitude>-118.000000</longitude>
                <latitude>34.000000</latitude>
                <range>1000</range>
            </LookAt>
            <Point>
                <altitudeMode>clampToGround</altitudeMode>
                <extrude>0</extrude>
                <coordinates>-118.000000,34.000000,0</coordinates>
            </Point>
        </Placemark>
    </Document>
</kml>

I expect <color>ff0000ff</color> to show a blue icon when kml is opened in Google Earth, not red.


Solution

  • KML does not use normal color order, instead it is in reversed order of Blue, Green, Red, or: AABBGGRR, where AA is the alpha or transparency, BB is blue, GG is Green and RR is Red.

    For more info see the documentation for the <color> tag, here: https://developers.google.com/kml/documentation/kmlreference#elements-specific-to-colorstyle

    specifically this line:

    The order of expression is aabbggrr
    

    For a blue icon you'll want to use: <color>ffff0000</color>