I am dealing with a kml that I am importing into openlayers as a vector layer. This kml has many features so it dramatically slows down the web app. I would like to make it so only the features within a certain extent are drawn (based around the user's position and also only at a higher zoom level). So far I set up an event listener to check for the zoom level. Once the appropriate zoom level is reached the vector layer is drawn however, it draws the whole layer. Is there any way to do this such that it only shows part of the KML? I can't find the answer or an example anywhere.

map.events.register("zoomend", this, function(e) { var zoom = map.getZoom(); if (zoom > 10){

           kml = new OpenLayers.Layer.Vector("Deer Accident Locations", {visibility: true,
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
            url: "deer.kml",
            format: new OpenLayers.Format.KML({
                extractStyles: false, 
                extractAttributes: true,
                maxDepth: 0

            style: {externalGraphic: 'images/Deer_green.png'  }          })


1 Answer 1


In general, the library will not render data that is not shown in the viewport, but if there is a huge amount of data it might be taking some time to retrieve it and parse. Can you open a web-inspector and see how long it takes to get the data? And see if the profiler gives you any other info?

I don't know how OpenLayers handles KML, but you could also experiment with loading it using Leaflet (see an example here). From my experience, Leaflet renders large numbers of features quicker (but I don't know how big your KML is).

You could also simplify the features of your KML for different scales using QGIS. So at the highest zoom level, you display the most simplified version of your data, and reload depending on the scale of the users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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