0
votes

From Google Earth I fetch my KML file from - say - address http://myaddress.com:8080

In the KML file I have several styles defined with an HREF for each icon. In this HREF I have the name of the icon, and I expect that Google Earth would implicitly fetch this file from the same server address, i.e. at http://myaddress.com:8080/aircraft.png in the example, unless another address is specified.

Appearent this does not work. I suppose it is interpreted as a local file.

I am now forced to tell my KML server on which address it is advertising itself, and use that address to create an absolute HREF for each icon in each KML file it produces.

How can I prevent using the server address in the KML for HREF-ed icons?

Example KML file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
    <Document>
        <name>GE View</name>
        <open>1</open>
        <Style id="style8">
            <IconStyle>
                <scale>1.0</scale>
                <heading>0.0</heading>
                <Icon>
                    <href>aircraft.png</href>
                    <refreshInterval>0.0</refreshInterval>
                    <viewRefreshTime>0.0</viewRefreshTime>
                    <viewBoundScale>0.0</viewBoundScale>
                </Icon>
            </IconStyle>
        </Style>
        <Folder>
            <name>Entities</name>
            <open>1</open>
            <Placemark>
                <name>HLAobjectRoot.BaseEntity.PhysicalEntity.Platform.Aircraft101</name>
                <visibility>1</visibility>
                <open>0</open>
                <description>HLAobjectRoot.BaseEntity.PhysicalEntity.Platform.Aircraft101: EntityType=1.2.0.-103.57.0.0</description>
                <styleUrl>style8</styleUrl>
                <Point>
                    <extrude>1</extrude>
                    <altitudeMode>relativeToGround</altitudeMode>
                    <coordinates>-18.00000000000001,53.999999999219824,1000.0000635553151</coordinates>
                </Point>
            </Placemark>
        </Folder>
    </Document>
</kml>
1

1 Answers

0
votes

KML can handle relative references to files but if accessed from a web server from web browser, at least the way it does so in Windows, the KML file is saved into a temporary/downloads folder and accessed locally by Google Earth. At that point, the relative links to files on the web server are lost. This is an issue of the interaction of web browser and Google Earth as an external handler of KML files. If, however, the KML was opened in Google Earth from a local file (e.g. file:// URL) then the local relative references work as expected.

If you include icons and images in a KMZ file then you can reference those URLs with relative URLs in the KML.

Here is the structure of your KMZ file with icons or images:

+doc.kml
+aircraft.png

KML with relative reference:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
    <Document>
        <name>GE View</name>
        <open>1</open>
        <Style id="style8">
            <IconStyle>
                <Icon>
                    <href>aircraft.png</href>
                </Icon>
            </IconStyle>
        </Style>
...

Here is an example of a KMZ file with an embedded ground overlay image referenced as relative URL.

Some additional details for URLS in KMZ can be found here.