Google Groups Home
Help | Sign in
Extracting a div defined as CDATA in KML, using javascript?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all
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
debaser  
View profile
(1 user)  More options Oct 6, 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    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.
geocodezip@gmail.com  
View profile
 More options Oct 6, 10:47 am
From: "geocode...@gmail.com" <geocode...@gmail.com>
Date: Mon, 6 Oct 2008 07:47:12 -0700 (PDT)
Local: Mon, Oct 6 2008 10:47 am
Subject: Re: Extracting a div defined as CDATA in KML, using javascript?
On Oct 6, 3:24 am, debaser <jamiebar...@gmail.com> wrote:

1. Please post a link to your map that shows the problem:
http://groups.google.com/group/Google-Maps-API/web/suggested-posting-...

2. I have no idea what is wrong with your code as you didn't post a
link, but something like:
**** TOTALLY UNTESTED ***
var infoWindowContents =
GXml.parse(kml.getElementsByTagName("Placemark")
[i].getElementsByTagName("description")[0]);
should work.

  -- Larry


    Reply    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.
Andy R  
View profile
 More options Oct 6, 10:55 am
From: Andy R <andy.ros...@bluewin.ch>
Date: Mon, 6 Oct 2008 07:55:46 -0700 (PDT)
Local: Mon, Oct 6 2008 10:55 am
Subject: Re: Extracting a div defined as CDATA in KML, using javascript?
Try ... childNodes[1].nodeValue;

On 6 Okt., 12:24, debaser <jamiebar...@gmail.com> wrote:


    Reply    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.
debaser  
View profile
 More options Oct 7, 7:06 am
From: debaser <jamiebar...@gmail.com>
Date: Tue, 7 Oct 2008 04:06:18 -0700 (PDT)
Local: Tues, Oct 7 2008 7:06 am
Subject: Re: Extracting a div defined as CDATA in KML, using javascript?
The problem is that it's a CDATA node. I need to retrieve either the
CDATA string as a whole, and extract the markup inside it, or just the
markup if possible. It seems that none of the browsers are picking up
that it's actually a CDATA node, and instead have one or more nodes,
each different types with different contents. This is why I love
Javascript... and sarcasm.

Thanks anyway :)


    Reply    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.
debaser  
View profile
 More options Oct 7, 7:07 am
From: debaser <jamiebar...@gmail.com>
Date: Tue, 7 Oct 2008 04:07:31 -0700 (PDT)
Local: Tues, Oct 7 2008 7:07 am
Subject: Re: Extracting a div defined as CDATA in KML, using javascript?
Yeah, if it's Firefox right? Now to make a custom script to check
browser versions and other stuff just to extract a CDATA node. Yay.
Fun.

Thanks Andy

On Oct 6, 4:55 pm, Andy R <andy.ros...@bluewin.ch> wrote:


    Reply    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.
marcelo  
View profile
 More options Oct 7, 7:15 am
From: marcelo <marcelo...@hotmail.com>
Date: Tue, 7 Oct 2008 04:15:02 -0700 (PDT)
Local: Tues, Oct 7 2008 7:15 am
Subject: Re: Extracting a div defined as CDATA in KML, using javascript?
var myData = GXml.value(childNodes[1]);

--
Marcelo - http://maps.forum.nu
--


    Reply    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.
debaser  
View profile
 More options Oct 7, 7:39 am
From: debaser <jamiebar...@gmail.com>
Date: Tue, 7 Oct 2008 04:39:15 -0700 (PDT)
Local: Tues, Oct 7 2008 7:39 am
Subject: Re: Extracting a div defined as CDATA in KML, using javascript?
Thank you so much marcelo! GXml.value() works, could have sworn I
tried that before :)

Although GXml.value(childNodes[0]); is what actually works for me
strangely enough, if I use other children I get back an empty string.

Cheers everyone

On Oct 7, 1:15 pm, marcelo <marcelo...@hotmail.com> wrote:


    Reply    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.
End of messages
« Back to Discussions « Newer topic     Older topic »

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