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




        } );

        map.events.register('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?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.