[OpenLayers-Users] Description attribute of KML file

Andreas Hocevar ahocevar at opengeo.org
Tue Jun 9 03:22:57 EDT 2009


Hi,

On Tue, Jun 9, 2009 at 8:02 AM, mpele<pmilanovic at gmail.com> wrote:
>
>
>
> Excerpts from pmilanovic's message of Mon Jun 08 05:49:39 -0400 2009:
>>
>> Is it posible to read description attribute of KML file?

Yes, you can add custom XML parsing to the process of reading the KML file.

>
> feature.attributes.description should do this.
>
> /quote>
>
> Is it possible to GML layer be a feature?
>
> Maybe I wasn’t so precise, so
>
> For example:
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://www.opengis.net/kml/2.2">
>  <Document>
>    <name>Highlighted Icon</name>
>    <description>Description of document</description>
>    <Placemark>
>        <name>Roll over this icon</name>
>        <description>Description of placemar</description>
>        …
>
> I would like to read “Description of document”. I am able to read
> “Description of placemar” with feature.attributes.description, but I don’t
> know how to read description of document.

Here is what you could do. The snippet assumes you are using a GML
layer with a KML format, because that is what I read between the lines
in your question.

var documentDescription;
var layer = new OpenLayers.Layer.GML("my gml layer", "http://my.url", {
    format: OpenLayers.Format.KML,
    formatOptions: {
        read: function(data) {
            OpenLayers.Format.KML.prototype.read.apply(this, arguments);
            var desc = data.getElementsByTagNameNS(data, "*", "description");
            if(desc.length && desc[0].parentNode.nodeName == "Document") {
               documentDescription = desc[0].firstChild &&
desc[0].firstChild.nodeValue;
            }
        }
    }
});
// after loadend, you can do whatever you want with doucmentDescription

The above snippet is untested, but should be enough to give you a
sense of what to do.

Regards,
Andreas.

>
>
>
>
>
>
> --
> View this message in context: http://n2.nabble.com/Description-attribute-of-KML-file-tp3042113p3047632.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list