Flying to one placemark amongst many in a kmz file

29 views
Skip to first unread message

KellerDH

unread,
Jun 27, 2009, 10:00:19 PM6/27/09
to KML Developer Support - Google Earth Plug-in
Hi,

First day with GE plug-in. Let's say I make a webpage, and it just
has ten cities listed on it, with a link for each city. That link
opens a single webpage, placing a parameter at the end of the URL,
like "http://www.mywebpage.com?Baltimore." This webpage has the plug-
in on it, and it links to my kmz file, which contains all ten city
placemarks in it. How can I pass the placemark=baltimore variable to
the kmz file, in order to get the the plugin to flyto Baltimore when
the page loads?

Thank you.

Nymor

unread,
Jun 28, 2009, 9:44:50 AM6/28/09
to KML Developer Support - Google Earth Plug-in
Hi,

Here's an example for you
http://www.thekmz.co.uk/GEPlugin/examples/pminurl/pminurl.htm

In this I have a KML file with 3 placemarks in it - London, Paris and
Dublin (all of which have a LookAt tag)

If you just open the web page it will load the KML but not set the
view to anything.

If you open the web page by appending one of the cities in the URL it
will load the KML and then fly to the relevant city (using the
aformentioned LookAt). ie
http://www.thekmz.co.uk/GEPlugin/examples/pminurl/pminurl.htm?london

will go to London. (I convert to lowercase so case sensitivity doesn't
come in to play).

Obviously you'll need to amend this for your own particular
circumstances but the 2 core parts are:-

1. Parse the URL

For this I use...

var urlquery = location.href.split("?");

if(urlquery[1]) {
var urlterms = urlquery[1].split(",");
curr_pm = urlterms[0];
}

...so the pm I'm later looking for in my KML (curr_pm) is the first
item after the ?. (It's set so I can pass more options through but for
this only use the first item in the urlterms array).

2. Find the Placemark

For this I used Roman's kmldomwalk.js
http://code.google.com/p/earth-api-samples/source/browse/trunk/lib/kmldomwalk.js?r=54
(although you can do it whichever way you want) with which I walk
through the KML until I find a Placemark with the same name as my
curr_pm. When, and if, I find it I extract the LookAt from it and fly
there.

Hopefully that will get you on your way to what you want.

Regards
Nymor

KellerDH

unread,
Jun 28, 2009, 3:11:40 PM6/28/09
to KML Developer Support - Google Earth Plug-in
Wow, that looks great! That's very kind of you to help me like this.
And you've inspired me to press on. I was getting pretty frustrated.
Thank you, Nymor.

Doug

On Jun 28, 6:44 am, Nymor wrote:
> Hi,
>
> Here's an example for youhttp://www.thekmz.co.uk/GEPlugin/examples/pminurl/pminurl.htm
>
> In this I have a KML file with 3 placemarks in it - London, Paris and
> Dublin (all of which have a LookAt tag)
>
> If you just open the web page it will load the KML but not set the
> view to anything.
>
> If you open the web page by appending one of the cities in the URL it
> will load the KML and then fly to the relevant city (using the
> aformentioned LookAt). iehttp://www.thekmz.co.uk/GEPlugin/examples/pminurl/pminurl.htm?london
>
> will go to London. (I convert to lowercase so case sensitivity doesn't
> come in to play).
>
> Obviously you'll need to amend this for your own particular
> circumstances but the 2 core parts are:-
>
> 1. Parse the URL
>
> For this I use...
>
>         var urlquery = location.href.split("?");
>
>         if(urlquery[1]) {
>                 var urlterms = urlquery[1].split(",");
>                 curr_pm = urlterms[0];
>         }
>
> ...so the pm I'm later looking for in my KML (curr_pm) is the first
> item after the ?. (It's set so I can pass more options through but for
> this only use the first item in the urlterms array).
>
> 2. Find the Placemark
>
> For this I used Roman's kmldomwalk.jshttp://code.google.com/p/earth-api-samples/source/browse/trunk/lib/km...
Message has been deleted

Nymor

unread,
Jun 28, 2009, 3:51:05 PM6/28/09
to KML Developer Support - Google Earth Plug-in
No problem.

You said in your opening post that this was you first day with the
Plugin ... you get frustrated pretty quickly ;)

One resource that is well worth spending some time going through is
the API reference
http://code.google.com/apis/earth/documentation/reference/index.html

It not only contains all the things available within the Plugin but
also contains loads of examples, from simple to complex, and links to
the KML docs etc. Just looking through the demos will give you a good
idea what you can do - digging into them and reviewing the javascript
behind them using something like the Web Developer & Firebug plugins
for Mozilla.

And if all else fails, or not, this group is also a superb sounding
board.

Good luck

Nymor

KellerDH

unread,
Jun 29, 2009, 12:43:55 PM6/29/09
to KML Developer Support - Google Earth Plug-in
Thank you again, Nymor. I should've said "first day with javascript,"
too. :-) And yes, the API reference is very helpful. I will delve
deeper soon.
Doug

On Jun 28, 12:51 pm, Nymor wrote:
> No problem.
>
> You said in your opening post that this was you first day with the
> Plugin ... you get frustrated pretty quickly ;)
>
> One resource that is well worth spending some time going through is
> the API referencehttp://code.google.com/apis/earth/documentation/reference/index.html

KellerDH

unread,
Jun 29, 2009, 7:29:10 PM6/29/09
to KML Developer Support - Google Earth Plug-in
Question, Nymor, if you're still there... is it difficult to integrate
the Network Link method of distributing the KML files into your
example code? I've read up on them, but only in bits and pieces, so
I'm still unclear about implementing them.
Thanks, if you have a moment. :)
Doug


On Jun 28, 12:51 pm, Nymor wrote:
> No problem.
>
> You said in your opening post that this was you first day with the
> Plugin ... you get frustrated pretty quickly ;)
>
> One resource that is well worth spending some time going through is
> the API referencehttp://code.google.com/apis/earth/documentation/reference/index.html

Nymor

unread,
Jul 1, 2009, 9:54:02 AM7/1/09
to KML Developer Support - Google Earth Plug-in
Can you give an example of what you're trying to do?

I don't have much experience of using Network Links within the plugin
but I'm sure others can help if you give them something to go. I will,
of course, try myself but those who know better will no doubt be able
to assist more.

Nymor

KellerDH

unread,
Jul 1, 2009, 2:44:17 PM7/1/09
to KML Developer Support - Google Earth Plug-in
Thank you for the reply, Nymor. It's hard for me to ask intelligent
questions knowing as little as I do. I will read on, though! :)

Nymor

unread,
Jul 1, 2009, 4:20:49 PM7/1/09
to KML Developer Support - Google Earth Plug-in
Do you have an example of what you're trying to do so we can see where
it fails .... with a bit of commentary of what you want to achieve.

... for example ... I have a page that tries to load a KML via a
Network Link, www.mysite.com/test1.htm, and etc...etc...

Nymor


ps. Don't have any concerns wrt to asking intelligent questions ...
trying to give intelligent answers is just as hard ;)

KellerDH

unread,
Jul 1, 2009, 5:00:11 PM7/1/09
to KML Developer Support - Google Earth Plug-in
Thanks again, Nymor. Actually, I think my biggest problem is that I'm
trying to edit and test these things from a webpage editor. Forget
the NetworkLink idea for now. I thought I'd first just tweak your
example page in order to make it run from my editor. So I tweaked
your UrlRoot, split, etc. section to just hardcode the KML Url and the
current parameter as 'london'. The page loads in the Firefox browser
that I tested it in... and your KML file loads, showing the three
placemarks... but no FlyTo.

Now, back to your london page example. If I click on the placemarks,
I don't get any balloon. I figured that I'd have to learn something
about the appendChild() deal to get your KML's balloons to show. But,
the darn editor problem is getting in the way.

thoughts? :-)

Doug

On Jul 1, 1:20 pm, Nymor wrote:
> Do you have an example of what you're trying to do so we can see where
> it fails .... with a bit of commentary of what you want to achieve.
>
> ... for example ... I have a page that tries to load a KML via a
> Network Link,www.mysite.com/test1.htm, and etc...etc...

Maciej Tomaszewski

unread,
Jul 1, 2009, 5:17:08 PM7/1/09
to KML Developer Support - Google Earth Plug-in
hi
I'm looking for a help with flying to object as well.
in my project Im parsing point from KML feed.
Point loads and workin but how can i fly to it on start?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /
>
<head>
<title>Where is Fastie</title>
<script src="http://www.google.com/jsapi?
key=ABQIAAAAgPEDcATOyzU0tR5Rp3cAuRTjaYEYh9pgYNpJWoDX0H_F8anvWRTHnPnmBAYhrLE9sxTb2PN7-
myXkw"></script>
<script>
google.load("earth", "1");

var ge = null;


function finished(object) {
if (!object) {
alert('bad or NULL kml');
return;
}
ge.getFeatures().appendChild(object);


}

function init() {

google.earth.createInstance("map3d", initCallback, failureCallback);
}

function initCallback(object) {
ge = object;
var layerRoot = ge.getLayerRoot();
ge.getWindow().setVisibility(true);

var options = ge.getOptions();
options.setStatusBarVisibility(true);
options.setGridVisibility(false);
options.setOverviewMapVisibility(true);
options.setScaleLegendVisibility(true);
options.setAtmosphereVisibility(true);
options.setMouseNavigationEnabled(true);

ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true);


// feed Im usung
var url = 'http://free.3dtracking.net/live.kmz?
Guid=1cea942a-4425-42d0-8fab-b2f5b2ed42e7';
google.earth.fetchKml(ge, url, finished);
}

function failureCallback(object) {
}

</script>
</head>

<body onload='init()' id='body'>
<center>
<div>
<p {font-family: arial;}><b>Where is Fastie!</a></p
</div>

<div id='map3d_container'
style='border: 4px solid silver; height: 700px; width:
100%;'>
<div id='map3d' style='height: 100%;'></div>
</div>
</center>

</body>
</html>

KellerDH

unread,
Jul 15, 2009, 2:10:11 PM7/15/09
to KML Developer Support - Google Earth Plug-in
Hi Maciej. Still need help with this?

On Jul 1, 2:17 pm, Maciej Tomaszewski wrote:
> hi
> I'm looking for a help with flying to object as well.
> in my project Im parsing point from KML feed.
> Point loads and workin but how can i fly to it on start?
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
Reply all
Reply to author
Forward
0 new messages