Referencing icon images loaded via .KMZ file?

756 views
Skip to first unread message

GRiker

unread,
Jan 14, 2008, 9:16:57 AM1/14/08
to KML Developer Support - Advanced Support for KML
Hi all, I posted this in 'Getting Started' but didn't get a response,
so I'm trying again here.

I create a .KMZ file containing a KML document and a subfolder called
Images with a .PNG file. The structure of my .KMZ file looks like
this:

Root.kml
Images (folder)
myIcon.png

I've looked at the file and confirmed this file structure with
WinZip. Google Earth loads and displays this file with no problems.

I load my KMZ file into GE with a NetworkLink using my own servlet.

Within my .kmz file I have a Style which references myIcon.png like
this:

<Icon>
<href>Images/myIcon.png</href>
</Icon>

The problem is that when my .KMZ file is loaded, Google Earth is
asking my servlet for Images/myIcon.png instead of loading it from the
KMZ I just sent. My reading of the docs seemed to indicate that
sending image files bundled with the .KMZ would make them accessible
using this local relative reference.

My initial load of the NetworkLink looks like this:

' ========================================
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<NetworkLink>
<id>MasterNetworkLinkID</id>
<name>GoogleMapEdit</name>
<Link id="MasterNetworkLink">
<href>http://localhost:12345/NetworkLink.kmz</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1</refreshInterval>
</Link>
</NetworkLink>
</kml>
' ========================================

My servelet responds with a KMZ file. Here is the relevant Style
section from the .KMZ file sent to Google Earth:

<Style id="normalPOI">
<IconStyle>
<Icon>
<href>Images/myIcon.png</href>
</Icon>
</IconStyle>

At this point, Google Earth asks the servlet for 'Images/myIcon.png'
instead of retrieving it from the .KMZ file.

I copied the KML from an object in Temporary Places that should have
been using the local copy of myIcon.png, and interestingly, its Style
element has been rewritten, including my servelet address:

<IconStyle>
<Icon>
<href>http://localhost:12345/Images/Restaurant.png</href>
</Icon>
</IconStyle>

So it appears that when my .KMZ file is loaded by Google Earth, the
<href> tag for the Icon is translated to be a fetch from the servelet
instead of from the local .KMZ file.

It seems that others have been using images in .KMZ files
successfully, so I'm guessing that I'm doing something different
that's causing GE to not use its local version of the .png file.

Any help will be appreciated.

G

barryhunter [KML Guru]

unread,
Jan 14, 2008, 10:37:23 AM1/14/08
to KML Developer Support - Advanced Support for KML
(cos you replied to yourself, it looked like you had a reply, so didnt
actully look - yes I hate this groups interface thingy!)

Anyway try,

<Icon>
<href>NetworkLink.kmz/Images/myIcon.png</href>
</Icon>

I think people have the that one working :)

GRiker

unread,
Jan 14, 2008, 1:35:44 PM1/14/08
to KML Developer Support - Advanced Support for KML
Barry, thanks for the quick reply.

I tried this, and it changed things, but it's still not working
correctly.

I no longer have GE asking for myIcon.png, but instead of showing
myIcon.png it shows a blue square with an 'x', suggesting that GE
knows that I expect it to load the image locally, but it's not able to
find it.

Any other tips?

Thanks.

G
> > G- Hide quoted text -
>
> - Show quoted text -

ManoM

unread,
Jan 14, 2008, 8:39:42 PM1/14/08
to KML Developer Support - Advanced Support for KML
Hi GRiker,

Can you post your KMZ file so we can try to replicate the problem?

ManoM

GRiker

unread,
Jan 15, 2008, 7:10:47 AM1/15/08
to KML Developer Support - Advanced Support for KML
Hi Mano, thanks for your reply.

I uploaded the KMZ file to the files section, 'IconsWontDisplay.kmz'.

G

barryhunter [KML Guru]

unread,
Jan 15, 2008, 8:23:36 AM1/15/08
to KML Developer Support - Advanced Support for KML
Unfortuntatly that file is but one part of the system, which seems to
be just an update statement.

Is there any chance you can recreate the system it online (eg
googlepages.com)



But one thing that does spring to mind is that you using the update
mechansim, so persumably you are updating a kml file from the
networklinked KMZ (which contains the icon). So in that case your
icons are loaded into the kml file (via an update) so paths would have
to be relative to that rather than the KMZ file (I looked like before
you where just using a standard network link with the content in the
link).

Also you would be wanting to reference a image inside a constantly
refreshing networklink, so by the time the main file gets updated, the
networklink could of refreshed (you use a 1 second interval)


Is there any reason not to have the images referenced normally (like
you say works) rather than begin loaded inside the network link -
which seems questionable if that will work at all.

GRiker

unread,
Jan 15, 2008, 9:08:14 AM1/15/08
to KML Developer Support - Advanced Support for KML
Thanks for the reply.

Yes, I am using a 1-second refresh interval. My assumption was that
because all of the content is still active in GE, and that all of the
ids are still valid, that the contents of the Image/ directory from
the last transmitted .kmz file would be valid as well. Perhaps that's
not the case.

When you say 'have the images referenced normally', are you suggesting
that my servlet should serve them to GE as needed, rather than try to
bundle everything up together? My original motivation to keep the
icons with the file was thinking that there would be less bandwidth
consumed.

G

barryhunter [KML Guru]

unread,
Jan 15, 2008, 10:01:43 AM1/15/08
to KML Developer Support - Advanced Support for KML
Very marginly, the image should aready be compressed so putting it in
a KMZ wont really help. You basically just have the overhead of
another HTTP request, but you get the added benefit that the GE can
cache the image, and it doesnt have to downloaded again (like with the
KMZ) if the user already has downloaded it. (and if you are really
doing it on localhost, then its not really going to matter!)

>
> G

GRiker

unread,
Jan 15, 2008, 10:57:49 AM1/15/08
to KML Developer Support - Advanced Support for KML
That makes sense.

I made the changes to simply serve the .PNG file on request, and that
seems to be working nicely.

Thanks for your assistance.

G

Bob Wenzlau

unread,
Jan 28, 2008, 7:38:28 PM1/28/08
to KML Developer Support - Advanced Support for KML
I too have been struggling with how to build through a script a kmz
file that has embedded images. My client does not seem to be
concerned about the load time of the kmz, but prioritizes the speed
with which images load after opening a balloon on a placemark. They
take to long to resolve from the website. Therefore, I thought to
embed the images into the kmz. The particular kmz is updated hourly,
so the script would need to build up the folder, zip it, and rename it
to the kmz extension. The <href> is confusing when one is trying to
reference through a kmz file structure the location of the images,
icons and overlays.

I have ended up with results where either GE reports a bad href, or it
appears to not object to the href, but shows no image. It is tough to
troubleshoot the environment.

The discussion of this is underdeveloped in the KML 2.2 reference.

I hope the discussion here continues.

Thanks

Bob

ManoM

unread,
Jan 29, 2008, 2:06:21 PM1/29/08
to KML Developer Support - Advanced Support for KML
Hi Bob,

Can you post an example of your KMZ files so we can see if we can
figure out the issue?

ManoM

Bob Wenzlau

unread,
Jan 30, 2008, 7:43:48 PM1/30/08
to KML Developer Support - Advanced Support for KML
Here is my understanding of how it works to build your own kmz with
embedded images. This is basically a file hierarchy embedded in the
kmz file.

example.kmz (a kmz file that contains the following)
-doc.kml
-files (folder containing)
-imagelegend.png
-imageoverlay.png


Now the way to the structure of the doc.kml with some embedded
questions. I built this example to illustrate the question for how to
use this in the <href> as well as with the <img> tags.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<ScreenOverlay
<name>Legend</name>
<Icon>
<href>files\imagelegend.png</href> <--- I have tried flavors of
this including: <href>imagelegend.png</href> or <href>doc.kml\files
\imagelegend.png</href>
</Icon>
<overlayXY x="0" y="1" xunits="fraction" yunits="fraction"/>
<screenXY x="0" y="1" xunits="fraction" yunits="fraction"/>
<rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/>
<size x="0" y="0" xunits="fraction" yunits="fraction"/>
</ScreenOverlay>
<Placemark>
<name>Excavation Activity</name>
<description><![CDATA[<img src="files/image.png" >]]></description>
<--- Again here the file reference protocol is not clear to me. Using
src is a variant to <href>
<LookAt>
<longitude>-117.5037015453355</longitude>
<latitude>34.08031158628037</latitude>
<altitude>0</altitude>
<range>7273.359418321104</range>
<tilt>42.74143022058856</tilt>
<heading>0.002864473106379529</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<Point>
<coordinates>-117.5111991316464,34.09905814201333,0</coordinates>
</Point>
</Placemark>

</Document>
</kml>






ManoM

unread,
Jan 31, 2008, 6:24:48 PM1/31/08
to KML Developer Support - Advanced Support for KML
Hi Bob,

So close!

GE uses Unix style URLs for file locations, unless specifically
locating something in a Windows directory:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<ScreenOverlay>
<name>Legend</name>
<Icon>
<href>files/icon.jpg</href>
</Icon>
<overlayXY x="0" y="1" xunits="fraction" yunits="fraction"/>
<screenXY x="0" y="1" xunits="fraction" yunits="fraction"/>
<rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/>
<size x="0" y="0" xunits="fraction" yunits="fraction"/>
</ScreenOverlay>
<Placemark>
<name>Excavation Activity</name>
<description><![CDATA[<img src="files/icon.jpg" >]]></
description>
<LookAt>
<longitude>-117.5037015453355</longitude>
<latitude>34.08031158628037</latitude>
<altitude>0</altitude>
<range>7273.359418321104</range>
<tilt>42.74143022058856</tilt>
<heading>0.002864473106379529</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<Point>

<coordinates>-117.5111991316464,34.09905814201333,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>

ManoM

Bob Wenzlau

unread,
Feb 14, 2008, 12:42:03 PM2/14/08
to KML Developer Support - Advanced Support for KML

Recall this post is about trying to build a kmz with icons embedded
into the kmz. Funny how seemingly easy stuff gets you. GE keeps
reconfiguring the <href> pointing to the icon files embedded in the
kmz -- so the icons fail to resolve. Is this where you need some
CData type statement to tell GE not to think too hard?

This points to the kmz that I made that is giving the problem:
http://backroom.terradex.com/share/Google/Current_AURN_Stations_Monitoring_Data.kmz

Here is a snippet from the vbScript generated KML that would be placed
into a kmz package. This uses the Unix style file reference:

<Style id="normal_current_style_2">
tf.write "<IconStyle>"
<scale>0.7</scale>
<Icon>
--> <href>files/current_low.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<scale>0</scale>
</LabelStyle>
<BalloonStyle>
<text>$[description]</text>
</BalloonStyle>
</Style>
<Style id="highlight_current_style_2">
<IconStyle>
<scale>1.0</scale>
<Icon>
<href>files/current_low.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<scale>1.0</scale>
</LabelStyle>
<BalloonStyle>
<text>$[description]</text>
</BalloonStyle>
</Style>


This is placed into a folder structure in early post:

placemarks.kmz (zipped kml)
placemarks.kml
files
icon.png


However when it is uploaded from GE, it creates its own dynamic file
reference to the icons. They do not resolve. Below is a placemark
where the local icon reference is generated. This was copied from the
kmz as it resolved in a GE session.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>KmlFile</name>
<Style id="normal_current_style_2">
<IconStyle>
<scale>0.7</scale>
<Icon>
---> <href>C:/Script/BureauVeritas/files/current_low.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<scale>0</scale>
</LabelStyle>
<BalloonStyle>
<text>$[description]</text>
</BalloonStyle>
</Style>
<Style id="highlight_current_style_2">
<IconStyle>
<Icon>
<href>C:/Script/BureauVeritas/files/current_low.png</href>
</Icon>
</IconStyle>
<LabelStyle>
</LabelStyle>
<BalloonStyle>
<text>$[description]</text>
</BalloonStyle>
</Style>
<StyleMap id="current_style_2">
<Pair>
<key>normal</key>
<styleUrl>#normal_current_style_2</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#highlight_current_style_2</styleUrl>
</Pair>
</StyleMap>
<Placemark id="data_137_copy0">
<name>Aberdeen Station</name>
<Snippet maxLines="2"></Snippet>
<description><![CDATA[<table border=0 >
<tr bgcolor="#E6E6FA"><td colspan=4 align=left><font
size=4><b>Aberdeen Air Pollution Monitoring Station</b></font></td></
tr>
<tr><td colspan=4 align=center><img width=250 src="http://www.bv-
aurnsiteinfo.co.uk/client/images/MainPhotoSmall/aberdeenmain.jpg"/></
td></tr>
<tr><td colspan=4 align=center><b>Station Description:</b> Close
to city centre and approximately 80 metres from main
road.
</td></tr>
<tr bgcolor="#E6E6FA" align=center ><td colspan=2 VALIGN=BOTTOM>
<b>Current Air Quality Level</b></td><td
VALIGN=BOTTOM><b>Concentration</b></td><td VALIGN=BOTTOM><b>Air
Pollutant</b></td></tr>
<tr valign="middle" bgcolor="#FFFFFF"><td width=75
valign=middle><img src="C:/Script/BureauVeritas/files/current_low.png"
width=30></td><td>Low</td><td align=center>58<td> <b>Ozone</b> -
Hourly Mean (µgm <sup>-3</sup> )</td></tr>
<tr valign="middle" bgcolor="#E6E6FA"><td width=75><img src="C:/
Script/BureauVeritas/files/current_low.png"width=30></td><td>Low</
td><td align=center>11<td> <b>Nitrogen dioxide </b> - Hourly Mean
(µgm<sup>-3</sup>)</td></tr>
<tr valign="middle" bgcolor="#FFFFFF"><td width=75><img src="C:/
Script/BureauVeritas/files/current_low.png"width=30></td><td>Low</
td><td align=center>19<td> <b>Particles</b> - 24 Hour mean PM10
(µgm<sup>-3</sup> Grav Equiv)</td></tr>
<tr bgcolor="#E6E6FA"><td colspan=4><a href="http://www.bv-
aurnsiteinfo.co.uk/viewSite.asp?pageRef=151&stationID=137&#">Link to
Station Information</a></td></tr>
<tr ><td align=left colspan=4>Data updates hourly and was last
collected by <a href="http://www.terradex.com">Terradex</a> at
2/14/2008 5:07:00 PM GMT on behalf of Defra and the Devolved
Administrations.</td></td></tr>
</table><br><br>]]></description>
<styleUrl>#current_style_2</styleUrl>
<Point>
<coordinates>-2.094277778,57.15736111,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>

Any obvious errors?

Bob Wenzlau

unread,
Feb 14, 2008, 12:59:41 PM2/14/08
to KML Developer Support - Advanced Support for KML
I noticed a scripting error around the <iconStyle> tag and repaired
that, but still the problem persists.

On Feb 14, 9:42 am, Bob Wenzlau wrote:
> Recall this post is about trying to build a kmz with icons embedded
> into the kmz. Funny how seemingly easy stuff gets you. GE keeps
> reconfiguring the <href> pointing to the icon files embedded in the
> kmz -- so the icons fail to resolve. Is this where you need some
> CData type statement to tell GE not to think too hard?
>
> This points to the kmz that I made that is giving the problem:http://backroom.terradex.com/share/Google/Current_AURN_Stations_Monit...

Jonathan van Tuijl

unread,
Feb 14, 2008, 2:06:51 PM2/14/08
to KML Developer Support - Advanced Support for KML
Bob Wenzlau wrote:
> Recall this post is about trying to build a kmz with icons embedded
> into the kmz.  Funny how seemingly easy stuff gets you.  GE keeps
> reconfiguring the <href> pointing to the icon files embedded in the
> kmz -- so the icons fail to resolve.  Is this where you need some
> CData type statement to tell GE not to think too hard?
>
> This points to the kmz that I made that is giving the problem:
> http://backroom.terradex.com/share/Google/Current_AURN_Stations_Monitoring_Data.kmz

> This is placed into a folder structure in early post:
>
>         placemarks.kmz (zipped kml)
>                 placemarks.kml
>                 files
>                         icon.png

I took a look at the KMZ file. The problem is that it contains a
folder which in turn contains the file structure you think you have.
For some reason GE uses paths relative to the KMZ root and not the
file location (Google said it isn't a bug), so you would refer to the
contents like this:

Current_AURN_Stations_Monitoring_Data/
Current_AURN_Stations_Monitoring_Data.kml
Current_AURN_Stations_Monitoring_Data/files/
Current_AURN_Stations_Monitoring_Data/files/current_high.png
Current_AURN_Stations_Monitoring_Data/files/current_low.png
Current_AURN_Stations_Monitoring_Data/files/current_moderate.png
Current_AURN_Stations_Monitoring_Data/files/current_nodata.png
Current_AURN_Stations_Monitoring_Data/files/current_veryhigh.png

You can also get rid of that folder and move everything into the KMZ
root with a capable zip utility. This is the best solution, because if
Google ever switches to relative paths within KMZ files, it will keep
working.

I have answered this more than once, so if you need more information
you might find it by searching the group.

Jonathan

Bob Wenzlau

unread,
Feb 14, 2008, 7:12:16 PM2/14/08
to KML Developer Support - Advanced Support for KML
It Works! Thanks for teaching this again. Bob

On Feb 14, 11:06 am, Jonathan van Tuijl wrote:
> Bob Wenzlau wrote:
> > Recall this post is about trying to build a kmz with icons embedded
> > into the kmz. Funny how seemingly easy stuff gets you. GE keeps
> > reconfiguring the <href> pointing to the icon files embedded in the
> > kmz -- so the icons fail to resolve. Is this where you need some
> > CData type statement to tell GE not to think too hard?
>
> > This points to the kmz that I made that is giving the problem:
> >http://backroom.terradex.com/share/Google/Current_AURN_Stations_Monit...
Reply all
Reply to author
Forward
0 new messages