I want to apply a form of generalization/specialization to my OpenLayers map. Is there a way to set the amount of WFS features to be rendered based on the zoom level?

In GeoServer you can set the maximum amount of features but not based on a zoom level. Would something like this be possible?


I think a good way to minimize unneccessary traffic is to use a BBOX-Strategy:

new OpenLayers.Layer.Vector("WFS", {
                strategies: [new OpenLayers.Strategy.BBOX()],
                protocol: new OpenLayers.Protocol.WFS({
                    url:  "http://demo.opengeo.org/geoserver/wfs",
                    featureType: "tasmania_roads",
                    featureNS: "http://www.openplans.org/topp"

Otherwise you can use "maxFeatures=xxxx" to limit the number of features delivered but with this solution you can't decide with features will be sent back.

  • Thanks. I am using alread a BBOX strategy. Setting the maxFeatures to be returned can not be per zoom level Only in total. Correct? – user1919 Mar 12 '15 at 15:17
  • 1
    you can just watch the zoomend-event,change the maxCount according to the zoomlevel and reload the layer – Thomas B Mar 13 '15 at 9:16
  • I think this is what I want. I already check the zoomend event: (map.events.register("zoomend", map, function(){... Can you please provide an example of to set the maxCount? – user1919 Mar 13 '15 at 9:36
  • 1
    layer.protocol.options.maxFeatures = 20 and refresh.refresh(); ( see jsfiddle.net/expedio/Le5wfgdy ) but as the maxCount gives you a random limitation still not very satisfying... – Thomas B Mar 13 '15 at 10:37
  • 1
    yes this should increase the speed a bit but it will still be a lot to render ;) – Thomas B Mar 13 '15 at 11:26

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.