Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:03:37+00:00 2026-06-18T00:03:37+00:00

I use this code to load a KML file into OpenLayers: var kmlLayer =

  • 0

I use this code to load a KML file into OpenLayers:

var kmlLayer =  new OpenLayers.Layer.Vector("KML", {
    projection: map.displayProjection,
    isBaseLayer: false,
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "mykml.kml",
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true,
            maxDepth: 2
        })
    })
});

Now I have to list all names of the polygons included in this file.

Trying console.log(kmlLayer.features) I can see the features but I have no idea how to access them. Please see http://s14.directupload.net/file/d/3148/2et4d7wf_png.htm because I’m not allowed to upload images yet.

How can I get name and description of those features?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:03:38+00:00Added an answer on June 18, 2026 at 12:03 am

    I think your problem is that the HTTP call happens asynchronously from your call to

    kmlLayer.features[0]
    

    So it seems empty. The solution would be to access the feature array only after the KML is loaded completely like so:

    kmlLayer.events.register("loadend", kmlLayer, function (e) {
        console.log(kmlLayer.features[0].attributes.name)
        });
    

    wether you use Firefox or Chrome just type into your developer web console kmlLayer.features[0] after you loaded the map and it will tell you that it is in fact not undefined.

    Let me know if this helped!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to load an Excel file into a datatable: public static
I use this line of code to load a local html file into a
I use this code to load the content from a different page into the
I use this code below to load CSS files. var i, a; for(i=0; (a
I want to import image file into JSF page. I use this code: <div
I use this code to load an image into matlab axes in gui :
I use this code to load data into my textarea: jQuery('.content_container').load('http://www.evedalsvardshus.se/plugins/calendar/edit_dates.php', {'value': datum} );
I use this code in my program to load a properties file: Properties properties
I use this code to load a .Net assembly to PowerShell: [System.Reflection.Assembly]::Load(System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
I use this code to load a htmlbox-instance to my page (this page also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.