Question

Big picture: I'm writing my own KMLs using a custom KML writer in C++. I have a set of placemarks that share some (not all) properties. Currently I store the shared properties as properties of the parent folder the placemarks reside in. These KMLs are viewed in Google Earth.

Users gain access to view this data using a BalloonStyle linked to the ExtendedData stored within each placemark/folder. The placemarks share a balloonstyle for their unique data, and the shared data is displayed using the parent folder's balloon style when they click on the folder in Google Earth.

I can't afford to duplicate the shared data in each placemark, which is why I store it in the parent folder.

Alternative 1: Is there any way to provide a user-clickable link to the parent folder's balloon within the child's balloon?

Alternative 2: Is it possible to display another Placemark/Feature's data in a placemark's info balloon?

As far as I know, both alternatives are impossible.

Edit: Simplified example code:

<?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" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
    <Document>
        <name>MyKml</name>
        <Style id="Style8">             <!-- style for child point -->
            <BalloonStyle>
                <text>
                Point: $[name]&lt;br/&gt;
                Code: $[code]&lt;br/&gt;
                Number of Points: $[numpts] <!-- Alt2: numpts belongs to the parent - this syntax is obviously wrong -->
                Link to parent: $[parentid] <!-- Alt1: if I can't display the parent's properties, can I at least give a clickable link to it? -->
                </text> 
            </BalloonStyle>
        </Style>
        <Style id="Style12">            <!-- style for parent folder -->
            <BalloonStyle>
                <text>
                Point Group: $[name]&lt;br/&gt;
                Number of Points: $[numpts]
                </text>
            </BalloonStyle>
        </Style>
        <Folder>
            <name>Point Group 1</name>
            <styleUrl>#Style12</styleUrl>
            <ExtendedData>
                <Data name="numpts">
                    <value>4</value>
                </Data>
            </ExtendedData>
            <Placemark>
                <name>PT1</name>
                <styleUrl>#Style8</styleUrl>
                <ExtendedData>
                    <Data name="code">
                        <value>TAT1</value>
                    </Data>
                </ExtendedData>
                <MultiGeometry>
                    <Point>
                        <coordinates>-121,47,110</coordinates>
                    </Point>
                </MultiGeometry>
            </Placemark>
            <Placemark>
                <name>PT2 - PT4</name>
                <styleUrl>#Style8</styleUrl>
                <ExtendedData>
                    <Data name="code">
                        <value>TAT2</value>
                    </Data>
                </ExtendedData>
                <MultiGeometry>
                    <Point>
                        <coordinates>-121.090,47.430,1224</coordinates>
                    </Point>
                    <Point>
                        <coordinates>-121.470,47.621,122</coordinates>
                    </Point>
                    <Point>
                        <coordinates>-121.990,47.121,122</coordinates>
                    </Point>
                </MultiGeometry>
            </Placemark>
        </Folder>
    </Document>
</kml>
Was it helpful?

Solution

Alternative 1: Is there any way to provide a user-clickable link to the parent folder's balloon within the child's balloon?

This is achieved using feature anchors where you can refer to and link to placemarks by its KML id using <a href="target"> in the description/balloon. If the target Feature has a LookAt or Camera element, the Feature is viewed from the specified viewpoint.

The href can be a fragment URL (that is, a URL with a # sign followed by a KML identifier). You can also append an action to the URL with a semi-colon (;) and one of these qualifiers:

  • ;flyto (default) - fly to the Feature
  • ;balloon - open the Feature's balloon but do not fly to the Feature
  • ;balloonFlyto - open the Feature's balloon and fly to the Feature

If you want to show the folder balloon from the point's you can update the BalloonStyle text as following and add "id" attribute to the Folder you want to refer to.

<Style id="Style8">
  <BalloonStyle>
    <text>
    <![CDATA[ 
    Point: $[name]<br/>
    Code: $[code]<br/>
    Number of Points: $[numpts]
    <BR><a href="#parent;balloon">Link to parent</a>
    ]]>
    </text> 
  </BalloonStyle>
</Style>
<Folder id="parent"> *** Must add "id" attribute to link to it ***
    ...
</Folder>

Alternative 2: Is it possible to display another Placemark/Feature's data in a placemark's info balloon?

Can't directly include metadata for another placemark in balloon of another but can link to it and switch to showing other's balloon by user clicking the link.

You could add links to the description of the placemarks to link to one another in the same way to link to Folder by its id then add $[description] place holder to the BalloonStyle text.

    <Style id="style9"> <!-- style for child point -->
        <BalloonStyle>
            <text>
            <![CDATA[
            Point: $[name]<br/>
            Code: $[code]<br/>
            <a href="#parent;balloon">Link to parent</a>
            <br>$[description]
            ]]>
            </text>
        </BalloonStyle>
    </Style>
    ...
    <Placemark id="pt1">
        ...
    </Placemark>
    <Placemark id="pt2">
        <name>PT2 - PT4</name>
        <description>
         <![CDATA[
            <a href="#pt1;balloon">Show P1</a><BR>
             ]]>
        </description>
        <styleUrl>#style9</styleUrl>
        ...
    </Placemark>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top