samedi 29 novembre 2014

OpenLayers Only draw features in a vector layer within view


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' } })
});

map.addLayers([kml]);




Aucun commentaire:

Enregistrer un commentaire