Accessing KmlPlacemark Properties / get Methods?

191 views
Skip to first unread message

rhoinkes

unread,
Jun 5, 2008, 8:12:54 PM6/5/08
to KML Developer Support - Google Earth Browser Plugin
Firstly, let me say that the Plugin is a great start and has the
potential to give me the programmability of Google Earth that my apps
really need (without getting into COM/Windows only).

I have the plugin starting up and loading up my KML with lots of
placemarks. I am trying to avoid infoWindow popups. I have an event
handling the mouse click, detecting that it was on a placemark and
doing the event.preventDefault(). All of that is fine.

HOWEVER, I do need to call up information in a sep. IFRAME (or other
entity on the page) based on the Placemark I click on. Previously
(prior to GE Plugin) the user had to click Placemark->InfoWindow-
>WebBrowser which was 2 clicks to get to the full info. I am trying to
limit this to 1 click Placemark->WebBrowser.

I get the KmlPlacemark from event.getCurrentTarget() but I can't seem
to find any methods to get back properties of the placemark that might
let me choose what to bring up in the IFRAME. Remember that these
placemarks are in the loaded KML file, NOT made via Javascript.

Is there a way currently (or will there be soon) any 'get' methods vs.
just set methods? getName, getDescription, almost anything would let
me ID the placemark uniquely.

Any help is greatly appreciated!

marquies

unread,
Jun 6, 2008, 4:03:52 AM6/6/08
to KML Developer Support - Google Earth Browser Plugin
You can add an unique event listener to each Placemark with

google.earth.addEventListener(p, "click", function() { /* do what I
want */ } );

Wether you fetch a KML with window.google.earth.fetchKml ,
ge.parseKml or create it manually, you can get all KML-Features with
ge.getGlobe().getFeatures(). You can iterate them and identify by name
or maybe id. You can get every attribute of them with a getter method
like getName(). What getter are aviable depends on the type of the
feature, consult API-Doc (http://code.google.com/apis/earth/
documentation/API.html#KmlFeature)

var features = ge.getGlobe().getFeatures().getChildNodes();
for(var i = 0; i < features.getLength(); i++) {
var feat = features.item(i);
alert(feat.getType() + '; ' + feat.getName());

fraser

unread,
Jun 11, 2008, 3:30:29 PM6/11/08
to KML Developer Support - Google Earth Browser Plugin
Hi,

Yes the plug-in is ace, nice work!

OK some history...

I have been playing around with various ways of adding placemarks to
Google earth.

At the moment I have a MySQL database and I am generating KML files
from this via PHP.

See: http://www.simpsonhaugh.co.uk/SimpsonHaugh/map/genMapKML.php

I am then loading the KML into the plug-in using fetchKml. I then
wanted to iterate through the place marks and maybe build a sidebar,
etc. I tried using the a function based on the code in the second
post. The thing is I just cant seem to get any of the KmlPlacemarks
only the KmlDocument itself.

The parseKml() function simply alerts

"KmlDocument; SimpsonHaugh - Projects"

See: http://www.simpsonhaugh.co.uk/SimpsonHaugh/map/earth.php

How would one iterate through the rest of the KML to get at the
placemarks?

I tried loading the KML via a networklink with the same result...

Any help would be great!

Cheers,

Fraser.
> > I get theKmlPlacemarkfrom event.getCurrentTarget() but I can't seem
> > to find any methods to get back properties of the placemark that might
> > let me choose what to bring up in the IFRAME. Remember that these
> > placemarks are in the loaded KML file, NOT made via Javascript.
>
> > Is there a way currently (or will there be soon) any 'get' methods vs.
> > just set methods? getName, getDescription, almost anything would let
> > me ID the placemark uniquely.
>
> > Any help is greatly appreciated!- Hide quoted text -
>
> - Show quoted text -
Message has been deleted
Message has been deleted

Dilated

unread,
Jun 12, 2008, 5:49:25 AM6/12/08
to KML Developer Support - Google Earth Browser Plugin
I'm having the exact same problem. The KML loads up great no problems
there, its pretty nice. Just can't access any of the properties
within...

the top chunk of the kml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns=\"http://earth.google.com/kml/2.2\">
<Document id='game_data'>
<Style id='city'>
<IconStyle>
<color>ffffffff</color>
<scale>0.7</scale>
<Icon>
<href>images/city_icon.png</href>
</Icon>
</IconStyle>
...
placemarks...etc...
paths...etc...
...

here's code I'm using to try and access the properties:
function getCities() {
var features = ge.getGlobe().getFeatures().getChildNodes();
for(var i = 0; i < features.getLength(); i++) {
var feat = features.item(i);
alert(feat.getType() + '; ' + feat.getId());
}

}

the only element i can manage to pull up from getFeatures, alerts
"KmlDocument; game_data"
It seems identical for,
ge.getGlobe().getFeatures().getChildNodes();
ge.getFeatures().getChildNodes();

On Jun 11, 1:30 pm, fraser wrote:
> Hi,
>
> Yes the plug-in is ace, nice work!
>
> OK some history...
>
> I have been playing around with various ways of adding placemarks to
> Google earth.
>
> At the moment I have a MySQL database and I am generatingKMLfiles
> from this via PHP.
>
> See:http://www.simpsonhaugh.co.uk/SimpsonHaugh/map/genMapKML.php
>
> I am then loading theKMLinto the plug-in using fetchKml. I then
> wanted to iterate through the place marks and maybe build a sidebar,
> etc. I tried using the a function based on the code in the second
> post. The thing is I just cant seem to get any of the KmlPlacemarks
> only the KmlDocument itself.
>
> The parseKml() function simply alerts
>
> "KmlDocument; SimpsonHaugh - Projects"
>
> See:http://www.simpsonhaugh.co.uk/SimpsonHaugh/map/earth.php
>
> How would one iterate through the rest of theKMLto get at the
> placemarks?
>
> I tried loading theKMLvia a networklink with the same result...
>
> Any help would be great!
>
> Cheers,
>
> Fraser.
>
> On Jun 6, 9:03 am, marquies wrote:
>
> > You can add an unique event listener to each Placemark with
>
> > google.earth.addEventListener(p, "click", function() { /* do what I
> > want */ } );
>
> > Wether you fetch aKMLwith window.google.earth.fetchKml ,
> > ge.parseKml or create it manually, you can get allKML-Features with
> > ge.getGlobe().getFeatures(). You can iterate them and identify by name
> > or maybe id. You can get every attribute of them with a getter method
> > like getName(). What getter are aviable depends on the type of the
> > feature, consult API-Doc (http://code.google.com/apis/earth/
> > documentation/API.html#KmlFeature)
>
> > var features = ge.getGlobe().getFeatures().getChildNodes();
> > for(var i = 0; i < features.getLength(); i++) {
> > var feat = features.item(i);
> > alert(feat.getType() + '; ' + feat.getName());
>
> > }
>
> > On 6 Jun., 02:12, rhoinkes wrote:
>
> > > Firstly, let me say that the Plugin is a great start and has the
> > > potential to give me the programmability of Google Earth that my apps
> > > really need (without getting into COM/Windows only).
>
> > > I have the plugin starting up and loading up myKMLwith lots of
> > > placemarks. I am trying to avoid infoWindow popups. I have an event
> > > handling the mouse click, detecting that it was on a placemark and
> > > doing the event.preventDefault(). All of that is fine.
>
> > > HOWEVER, I do need to call up information in a sep. IFRAME (or other
> > > entity on the page) based on the Placemark I click on. Previously
> > > (prior to GE Plugin) the user had to click Placemark->InfoWindow->WebBrowser which was 2 clicks to get to the full info. I am trying to
>
> > > limit this to 1 click Placemark->WebBrowser.
>
> > > I get theKmlPlacemarkfrom event.getCurrentTarget() but I can't seem
> > > to find any methods to get back properties of the placemark that might
> > > let me choose what to bring up in the IFRAME. Remember that these
> > > placemarks are in the loadedKMLfile, NOT made via Javascript.

fraser

unread,
Jun 12, 2008, 6:46:41 AM6/12/08
to KML Developer Support - Google Earth Browser Plugin
Yes, really frustrating!

Just to add, If I add a placemark manually with...
//
var placemark = ge.createPlacemark('');
placemark.setName("foo");
ge.getFeatures().appendChild(placemark);
//

Then I can acess that placemark, as expected, using
ge.getFeatures().getChildNodes().

But how on (google) earth do I access the placemarks generated when
loading a kml file via fetchKML?

google.earth.fetchKml(ge, kml_url, fetchKmlCallback);
function fetchKmlCallback(kml)
{
ge.getFeatures().appendChild(kml);
}

....
> > > - Show quoted text -- Hide quoted text -

Roman N

unread,
Jul 17, 2008, 7:09:59 PM7/17/08
to KML Developer Support - Google Earth Browser Plugin
fraser,

You should be able to use the getFeatures() method on the 'kml'
variable just as you would with the 'ge' variable, i.e.:

var firstChildInKml = kml.getFeatures().getFirstChild();

From there you could traverse the object model as needed.

- Roman
> > > TheparseKml() function simply alerts
>
> > > "KmlDocument; SimpsonHaugh - Projects"
>
> > > See:http://www.simpsonhaugh.co.uk/SimpsonHaugh/map/earth.php
>
> > > How would one iterate through the rest of theKMLto get at the
> > > placemarks?
>
> > > I tried loading theKMLvia a networklink with the same result...
>
> > > Any help would be great!
>
> > > Cheers,
>
> > > Fraser.
>
> > > On Jun 6, 9:03 am, marquies wrote:
>
> > > > You can add an unique event listener to each Placemark with
>
> > > > google.earth.addEventListener(p, "click", function() { /* do what I
> > > > want */ } );
>
> > > > Wether you fetch aKMLwith window.google.earth.fetchKml ,
> > > > ge.parseKmlor create it manually, you can get allKML-Features with

fraser

unread,
Jul 17, 2008, 7:32:29 PM7/17/08
to KML Developer Support - Google Earth Browser Plugin
Hi Roman,

Thanks for the reply, I got there in the end!
It was a silly mistake, I had missed a 'getFeatures' on the child
nodes

firstChildInKml.getChildNodes(); //Error "Object does not support this
property or method"
firstChildInKml.getFeatures().getFirstChild(); //Correct

Incidentally after I realised the error I posted a recursive function
to iterate through KML in this thread...
http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/3a420108cdb9385c/a31a6d30d151bb75?lnk=gst&q=kml+dom#a31a6d30d151bb75

Thanks again for the response.

Regards,

Fraser.
Reply all
Reply to author
Forward
0 new messages