Sign up ×
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 WFS feature layer with ~25,000 features and have been experiencing significant performance issues with my OpenLayers map. My first approach to solving this has been to pre-compute feature clusters on the server side, instead of relying on the clustering in OpenLayers.

I wrote a script to cluster my features based on the resolution at each zoom level, and I placed the clusters for all of the zoom levels in my PostGIS database. My hope was to use a filter like the one below to select only those features in the database that are tagged with the zoom level equal to the current zoom level of the map:

function init() {

        var zoomLevelIndicator;
        var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
        renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;

        map = new OpenLayers.Map ("map", {
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.Permalink(),
                new OpenLayers.Control.ScaleLine({geodesic: true}),
                new OpenLayers.Control.Permalink('permalink'),
                new OpenLayers.Control.MousePosition(),                    
                new OpenLayers.Control.Attribution()],

            maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
            maxResolution: 156543.0339,
            numZoomLevels: 19,
            units: 'm',
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326"),

            layers: [new OpenLayers.Layer.OSM(),
                     new OpenLayers.Layer.Vector("Filtered by Zoom Level", {
                        strategies: [new OpenLayers.Strategy.BBOX()],
                        protocol: new OpenLayers.Protocol.WFS({
                            version: "1.1.0",
                            url: "http://localhost:8080/geoserver/wfs",
                            srsName: "EPSG:900913",
                            featureNS: "http://localhost:8080/myworkspaceuri",
                            featurePrefix: "MyWorkspace",
                            featureType: "clusteredtestpoints"
                        renderers: renderer,

                        filter: new OpenLayers.Filter.Comparison({
                            type: OpenLayers.Filter.Comparison.EQUAL_TO,
                            property: "zoomlevel",
                            value: zoomLevelIndicator




        } );'zoomend', this, function (event) {
            zoomLevelIndicator = map.getZoom();

            var switcherControl = new OpenLayers.Control.LayerSwitcher();

        if( ! map.getCenter() ){
            var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            map.setCenter (lonLat, zoom);

Specifically, I am trying to update the zoomLevelIndicator variable each time a zoom event occurs. When I test this, the features for the initial zoom level show up, but do not update when I change the zoom level.

Does anybody have any ideas as to why this is not working?



share|improve this question
In MapServer you can set a zoomlevel (with maxscaledenom and minscaledenom) for each layer. I am not sure, but I would guess GeoServer has a similar function. This might help:… –  Stefan Dec 11 '12 at 9:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.