[OpenLayers-Users] Howto extract documentattributes(name/description) from KML Layer

christopher.schmidt at nokia.com christopher.schmidt at nokia.com
Mon Aug 2 11:17:21 EDT 2010


On Aug 2, 2010, at 11:07 AM, ext Sven Geggus wrote:

> Arnd Wippermann <arnd.wippermann at web.de> wrote:
> 
>>   brewpub_layer.events.register("loadend", brewpub_layer, function (e) {
>>       var fts = this.features;
>>       for(var i=0;i<fts.length;i++)
>>       {
>>           theHTML = fts[i].attributes.name + ", " + fts[i].attributes.description + "<br>";
>>       }
>>   }); 
> 
> Ok, while this works for feature attributes it does still not give me the
> the "global" name and description attributes of my kml document as a whole
> as well as those attributes inside the folder definition but those are
> actually the ones I am interested in.
> 
> My kml looks like this (roughly):
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://www.opengis.net/kml/2.2" ...
> <Document>
>        <name>Name of KML Document</name>
>        <Folder>
>                <name>Folder Name</name>
>                 <description>Folder description</name>
> 
>                 ... features come here
> 
>        </Folder>
> </Document>
> </kml>
> 
> So the question is how to access these attributes from javascript.

OpenLayers doesn't parse this data. You can get access to the raw KML
by setting the keepData option:

  http://dev.openlayers.org/apidocs/files/OpenLayers/Format-js.html#OpenLayers.Format.keepData

Then reading the XML doc from format.data, and doing your own parsing.

-- Chris

> Regards
> 
> Sven
> 
> -- 
> The main thing to note is that when you choose open source you don't
> get a Windows operating system.
>                                  (from http://www.dell.com/ubuntu)
> /me is giggls at ircnet, http://sven.gegg.us/ on the Web
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list