Question

Is it possible to have an Icon tag use a Base64 Encoded image? I've tried it without success, using data:image/png;base64, prepended to the encoded data for the image, but I still get the red X when I load the KML.

Was it helpful?

Solution

Overlays (screen overlay, ground overlay, etc.) and icon images via Style references in KML are referenced only as URLs either absolute or relative not as inline base64-encoded content which is allowed in other XML standards.

Icon Style example with absolute URL:

<Style>
      <IconStyle>
         <Icon>
            <href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href>
         </Icon>
      </IconStyle>
</Style>

Ground Overlay image example with relative URL:

<GroundOverlay>
    <Icon>
      <href>etna.jpg</href>
    </Icon>
</GroundOverlay>

In theory a URL could be referenced in KML with "data:image/png;base64..." but that usage is NOT defined in the official KML standard nor implemented in Google Earth.

It is possible to have base64-encoded images and access them via HTML and JavaScript code in a KML feature description but that is outside the context of KML and not applicable to seeing red X's. KML supports most JavaScript so that may be possible to display inline images in the description balloon.

In short, the image or icon cannot presently be base64-encoded for overlay images or icons displayed on the map that are referenced in the KML but you can compress the images and refer to them relative to the KML as entries inside a KMZ file. By including the images in a compressed KMZ file there would be no need to base64 encode the images in the first place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top