Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 containt both polygons and points in it at the same time? What sollution would you suggest to solve this?

(I need these features in one layer and not seperate). Thank you.

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
                })
            })
        });
map.addLayer(Grid);
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

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.