Google Groups Home
Help | Sign in
Message from discussion Extracting a div defined as CDATA in KML, using javascript?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
debaser  
View profile
 More options Oct 6 2008, 6:24 am
From: debaser <jamiebar...@gmail.com>
Date: Mon, 6 Oct 2008 03:24:10 -0700 (PDT)
Local: Mon, Oct 6 2008 6:24 am
Subject: Extracting a div defined as CDATA in KML, using javascript?
Hi all,

I have a KML file which defines a description used for the infoWindow.
The description tag contains CDATA which defines a div to be used to
display in the infoWindow, e.g.:

<Placemark>
  ...
  <description><![CDATA[
  <div style="font-size:9pt;font-family:trebuchet
MS,verdana,sans;margin-top:2px;margin-left:2px;line-height:9pt;">
  <p>this is only a test</p>
  <p>of the emergency broadcast system</p>
  </div>
  ]]></description>
</Placemark>

My problem comes in now, that instead of using the built in GGeoXml
utility to show markers, I'm manually reading the data using
GDownloadUrl:

GDownloadUrl(mapDataKmlUrl, function(data, responseCode) {
      var kml = GXml.parse(data);
      doStuff(kml);
    });

... where doStuff shows markers depending on the content defined in
the Placemarks. What I want to do now, is add an event to the marker
to display the same info window as would be shown before using the
GGeoXml utility, which would use the description's CDATA to add a div
to the infoWindow:

GEvent.addListener(marker, "click", function() {
    var infoWindowContent =
retrieveDescriptionFromPlacemark(placemark);
    marker.openInfoWindowHtml(infoWindowContent);
  });

I tried the following:

function retrieveDescriptionFromPlacemark(placemark) {
  return placemark.getElementsByTagName("description")
[0].childNodes[0].nodeValue;

}

... but it returns a blank string for that node. Any suggestions on
how to get the actual div content would be greatly appreciated.

Thanks,

James


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google