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.
> 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:
> ... 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:
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.
> 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:
> ... 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:
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.
> On 6 Okt., 12:24, debaser <jamiebar...@gmail.com> wrote:
> > Hi all,
> > I have a KML file which defines a description used for the infoWindow.
> > The description tag containsCDATAwhich 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:
> > ... 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'sCDATAto add a div
> > to the infoWindow: