Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a KML layer like this:

new OpenLayers.Layer.Vector("KML", {
                projection: myDisplayProjection,
                strategies: [new OpenLayers.Strategy.Fixed()],
                protocol: new OpenLayers.Protocol.HTTP({
                    url: myKmlUrl,
                    format: new OpenLayers.Format.KML({
                        extractStyles: true,
                        extractAttributes: true

I am extracting styles and attributes.

I have some attributes attached to the document (as well as the placemarks/features).

Will this information be on the resultant layer (I think not) or how do I get this information other wise?

The information relevant to the whole layer.


share|improve this question

Aha. It looks like somebody has tried to do what I wanted:

He puts it better than me:

"Currently, name, description, author and other attributes of KML elements Document and Folder are ignored silently."

Looks like that is still true in the version of OpenLayers I am using (Release 2.13 dev I think).

So the version of OpenLayers I am using doesn't quite do what I want (and I don't know how to use git hub, nor do I understand when if ever this code was/will be released), but I might be able to hack a solution at my end using this nice man's code.

Thanks jachym and aragon

share|improve this answer

if you want to get attributes of your kml layer, try out this code with SelectFeature:

onSelect: function(f){
var feat = f.attributes;
var keys = [];
for(var key in feat){
    keys.push([key , feat[key]])

for(var a=0; a<keys.length; a++){
    fInfo += '<b>' + keys[a][0] + '</b> : ' + keys[a][1] + '<br>' 
fInfo = fInfo.replace('undefined', '');


it will give you result as following output.

name: Sundial, Nidai, Lithunia

description: A large horizantal sundial.

styleUrl: #msn_sunny_copy70

i hope it helps you...

share|improve this answer
Thanks. In your example, f is a feature, correct? Features are equivalent to the Placemarks in a KML file, right? All my Placemarks are in a Document node. I want to be able to get to data directly under the Document node (or a better palace should it exist). I think you are allowed to give it a name, description, ExtendedData etc. I want to know how to get to that information. It is probably lost when parsed, in which case, I want to know if there still a reference to the raw KML which I could then parse myself. – zod Jan 2 '13 at 15:19
I am basically trying to create KML files that contain all the information needed to be understood (a title, a legend), and avoid multiple hits to get the same bit of information. If a Placemark is equivalent to a feature, what is the appropriate place to put information relating to the layer? – zod Jan 2 '13 at 15:21
i didnt change anything from raw kml. – Aragon Jan 2 '13 at 15:22
Sorry? A kml file has multiple placemarks. In my case, these are polygons. Each polygon has some data associated with it. I have no problem getting to that data (I can uses the description field, and in javascript it will be at feature.attributes.description). What I want is to get to some data that is at the document level (outside a feature). Data relevant to the whole "layer" not just a selected feature. – zod Jan 2 '13 at 15:27
AFAIK It is not possible. Until recently I used a patched code of KML.js to retrieve the <Document><name> as name at the first feature without geometry. (not very pretty, but it worked) – xamamano -jorix- Jan 2 '13 at 19:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.