I have a kml file which contains some polygon and some point features in the same file. I am trying to load and view this layer on my basemap in OpenLayers. The problem is that the polygon features will be drawn on map but not the points.

Does this mean that a layer cannot contain both polygons and points in it at the same time?

I need these features in one layer and not separate.

The code for loading the data in OpenLayers:

Grid = new OpenLayers.Layer.Vector("grid layer", { eventListeners: {
            'featureselected': function (evt) {},
            'featureunselected': function (evt) {},
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "sample.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: false,
                    extractAttributes: true,
                    maxDepth: 2
                styleMap: new OpenLayers.StyleMap({
                "default": new OpenLayers.Style(OpenLayers.Util.applyDefaults({
                    pointRadius: 6,                    
                    strokeWidth: 1,
                    strokeColor: "Black",
                    fillColor: "Gray",
                    fillOpacity: 0.4
                }, OpenLayers.Feature.Vector.style["default"])),
                "select": new OpenLayers.Style({
                    fillColor: "Blue",
                    fillOpacity: 1

1 Answer 1


Ok. Finally with doing some tests I was able to figure out where the problem was. KML structure does not have a Featurecollection type in its structure like the one that GeoJSON has. Instead, all you need to do is to store each feature in a separate placemark tag. This means that KML does not support multiple feature information in one placemark tag (which in fact is correct, a placemark is one placemark not more!). The code above for loading data doesn't have a problem and works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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