Hyperlinking Placemarks within a KML file

2,071 views
Skip to first unread message

Philo

unread,
Feb 9, 2010, 10:28:20 PM2/9/10
to KML Developer Support - Advanced Support for KML
Good day. I have been browsing the forums to find an answer for this,
but I haven't been able to, eventhough I wouldn't be suprised if this
has been asked before:

I have seen links between two or more KML files either through network
links or through the common <a href="http://.....filename.kml> html
command.

What I have not been able to figure out is how to create a hyperlink
from a text within a placemark ballon to another placemark; how to
link placemarks and balloons within the same KML file.

In other words, say I have Placemark A and Placemark B within the same
KML file. I would like to be able to click on a text within the
Placemark A balloon that would take me to the location of Placemark B
and open its balloon.

This should not be hard to do, considering both placemarks are within
the same KML file, and considering that each placemark can be assigned
with a placemark id. I have tried entering
<a href="#PlacemarkB Id;balloon">Go to Placemark B</a>
in the html of Placemark A balloon, but no success.

Any ideas?
Thank you in advance for your time and for your patience.



Jason M

unread,
Feb 10, 2010, 8:39:01 AM2/10/10
to KML Developer Support - Advanced Support for KML
Hi,

Looks like you almost got it right but there is no clear example out
there. The trick is to specify the "id" of the target Placemark in the
link not it's name.
Note whitespace not allowed in the id tag so something like
"PlacemarkB Id" is not valid.

Taken from the KML Reference:

The href can be a fragment URL (that is, a URL with a # sign followed
by a KML identifier). When the user clicks a link that includes a
fragment URL, by default the browser flies to the Feature whose ID
matches the fragment. If the Feature has a LookAt or Camera element,
the Feature is viewed from the specified viewpoint.

The behavior can be further specified by appending one of the
following three strings to the fragment URL:

* ;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

Example:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark id="p1">
<name>1</name>
<description>
<![CDATA[
<a href="#p2;balloonFlyto">Fly to end</a>
]]>
</description>
<Point>
<coordinates>-122.536226,37.86047,0</coordinates>
</Point>
</Placemark>

<Placemark id="p2">
<name>2</name>
<description>
<![CDATA[
<a href="#p1;balloonFlyto"> Back to start</a>
]]>
</description>
<Point>
<coordinates>-122.536923,37.859855,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>

Philo

unread,
Feb 10, 2010, 11:03:30 AM2/10/10
to KML Developer Support - Advanced Support for KML
Thank you very much for that excellent example.
That's exactly what I was looking for and I now got it working in my
kml file.

Best wishes
> > Thank you in advance for your time and for your patience.- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -
Reply all
Reply to author
Forward
0 new messages