[OpenLayers-Users] Using KML and retrieving features

Dylan Parry me at dylanparry.com
Thu Jun 30 11:27:16 EDT 2011


Hi,

I’ve added a KML layer to a map, and it’s a fairly big layer (~10MB) but
 the site I’m creating is to be ran locally so that shouldn’t matter too
much.

The first problem I’ve got is that the KML doesn’t actually seem to display.
The code I’ve got adding it as as follows:

data = new OpenLayers.Layer.Vector("KML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "/data/data.xml",
        format: new OpenLayers.Format.KML({
            extractAttributes: true,
            extractStyles: true
        })
    })
});
_map.addLayer(data);

I had to rename the file to .xml as the local server didn’t like the .kml
extension, so refused to serve the file. Now the file is definitely being
requested as Chrome inspector shows that it’s been downloaded successfully
and I get no JavaScript errors, but I’m not getting anything shown in the
map display.

Could this be because the KML file is too big? Or am I doing something
wrong?

I actually only want to display the file to check that it’s working
properly, but eventually I’ll be hiding the layer anyway, so if it’s not
displayable but still usable for querying, then that’s okay!

The second question I have is about interrogating the KML layer. What I want
to do is be able to double-click on the map, extract the coordinates of the
clicked location, and then retrieve the attributes of any feature within the
KML layer that was at the clicked location.

I’m able to do the double-click handler, and extract the coordinates simply
enough, but how do I then go about retrieving the features within the KML
file for the selected coordinates? How then would I extract the attributes
for that feature?

Thanks in advance,

-- 
Dylan Parry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110630/ecb5565c/attachment.html


More information about the Users mailing list