Paul Meems
Paul Meems

Reputation: 3284

Openlayers: zooming WFS sometimes return to first zoom level

I have a GeoServer server that provides my layers using GeoWebCache. This works fine. I also have a WFS layer which it populated using a filter (address ID). Mostly this WFS layer has less than 5 features, but in some occasions it has around 20-30 features but always less than 100. I use OpenLayers to show the layers and I have a custom search box for the user to search for an address. As said before this works all fine.

But when I have a WFS layer with approx. more than 10-15 features and I (or the user) clicks the zoom out button on the default PanZoomBar after some clicking (probably too fast) the zoomlevel is reset to to original zoomlevel of the WFS layer (zoom to fit). This doesn't happen when having less than 10 features.

I don't have any fancy code that might cause this behavior and it is happening in FireFox, IE and Chrome.

This is my code the create the WFS layer:

var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
wfsLayer = new OpenLayers.Layer.Vector("Dakvlakken", { 
  renderers: renderer,
  displayInLayerSwitcher: true,
  strategies: [new OpenLayers.Strategy.BBOX()],
  filter: new OpenLayers.Filter.Comparison({ 
          type: OpenLayers.Filter.Comparison.EQUAL_TO,
          property: "adres_id",
          value: startAdresID}),
  protocol: new OpenLayers.Protocol.WFS({ 
    url: "http://MyIP/geoserver/wfs",
    featureType: "full",
    srsName: "EPSG:28992",
    geometryName: "geom_rd"
  })
});

This is how I change the filter after the user selects a different address:

function changeFilter(newValue, x, y, adres)
{ 
    wfsLayer.destroyFeatures();
    filter = new OpenLayers.Filter.Logical(
    { 
      type: OpenLayers.Filter.Logical.AND, 
      filters: [ 
        new OpenLayers.Filter.Comparison(
        { 
            type: OpenLayers.Filter.Comparison.EQUAL_TO, 
            property: "adres_id", 
            value: newValue 
        }), 
        new OpenLayers.Filter.Spatial(
        { 
            type: OpenLayers.Filter.Spatial.BBOX, 
            value: new OpenLayers.Bounds(x-50, y-50, x+50, y+50), 
            projection: "EPSG:28992" 
        }) 
      ]  
    });

    wfsLayer.filter = filter;
    wfsLayer.refresh({force: true});
  }
}

I've been debugging for several days now but I have no idea how to solve this. Any help will be much appreciated.

Upvotes: 0

Views: 772

Answers (1)

Paul Meems
Paul Meems

Reputation: 3284

I've found the problem. I did a check if the zoomlevel wasn't too high if so I changed it to a predefined level. This check was in a method that should only be called once to fill a table with the attributes of the WFS layer. Somehow this method is called after every zoom. This is not correct and I'll try to fix that as well. So my initial problem is solved, but I got a new one in return ;)

If I get stuck again I'll post a new question.

Thanks,

Paul

Upvotes: 1

Related Questions