2
votes

In a KML file for Google Earth consumption I am using Google Charts dynamic icons whose URLs contain percent-encode characters, e.g., this one. As can be seen by intercepting network calls, the %E2%80%A2 (bullet character) is mangled by Google Earth into %C3%A2%C2%80%C2%A2, which causes the icon retrieval to fail. The problem is that the KML spec is extremely vague: of the IconStyle Icon href element it will only say that it is "an HTTP address [...] used to load an icon". So, can any Googler clarify what Google Earth expects and how to make icon URLs in KML files with percent-encoded characters work properly?

Please do not give me grief about how maybe the URL above is somehow incorrect: it works fine in a browser (after replacing  with the ampersand) and there is an example just like it about halfway through the dynamic icons developer reference.

An actual KML example file follows:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
  <Folder>
    <Placemark>
      <Style>
        <IconStyle>
          <scale>1.6</scale>
          <Icon>
            <!-- doesn't work -->
            <href>http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&#x26;chld=%E2%80%A2|cccccc|000000</href>
          </Icon>
        </IconStyle>
      </Style>
      <Point>
        <coordinates>-3.67,40.51</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <Style>
        <IconStyle>
          <scale>1.6</scale>
          <Icon>
            <!-- works -->
            <href>http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&#x26;chld=O|cccccc|000000</href>
          </Icon>
        </IconStyle>
      </Style>
      <Point>
        <coordinates>-3.68,40.52</coordinates>
      </Point>
    </Placemark>
  </Folder>
</Document>
</kml>
1
It's bizarre. Note that it's not the encoding, because you can encode other parameters (say the cccccc => %63...). It seems as though the chart api doesn't want to return some particular characters ...., but on the other hand, when accessing those same things in Firefox it works fine (returned the correct image). So strange. - Noon Silk
(Though I do confirm seeing the changed encoding in wireshark...). I suppose you're right; somewhere the encoding is getting mangled (on some basis that isn't immediately obvious to me). I think this is a bug. - Noon Silk

1 Answers

1
votes

I came back to this after a long lull and found the answer. Even though you are inserting an URL and thus URL encoding guidelines should apply KML expects special entities to be Unicode- and not URL-encoded even in URLs! In other words you need this:

<href>http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&#x26;chld=&#x2022;|cccccc|000000</href>

In retrospect the fact that that it requires "&#26;" for the ampersand should have put me on the right track but hindsight is always 20/20...