I use GeoServer and PostGIS and OpenLayers to show the data.<br>For one page I'm using a WFS layer and I filter on address.<br><br>The user first need to select an address. This is done with an AJAX call and the adresID and the location (X, Y) are returned.<br>


I zoom to that location and change my filter.<br>This is my initial set-up of my layer, an addressID of -1 doesn't exists so it starts with just the baselayer:<br><pre style="font-family:courier new,monospace"><span>var myLayer = new OpenLayers.Layer.Vector("tmp", { 
<span></span>  displayInLayerSwitcher: true,
<span></span>  strategies: [new OpenLayers.Strategy.BBOX()],
<span></span>  filter: new OpenLayers.Filter.Comparison({ 
<span></span>          type: OpenLayers.Filter.Comparison.EQUAL_TO,
<span></span>          property: "_adresid",
<span></span>          value: "-1"}),
<span></span>  styleMap: new OpenLayers.StyleMap(),
<span></span>  protocol: new OpenLayers.Protocol.WFS({ 
<span></span>    url: ".../wfs",
<span></span>    featureType: "myName",
<span></span>    srsName: "EPSG:3857",
<span></span>    geometryName: "geomgoogle"
<span></span>  })
<span></span>});</span></pre>But this call takes long because it tries to find the -1 value. <br><b>Q1</b>: How can I add a WFS layer without data?<br><br>And this is the method I call after the user selects an address:<br>

<pre><font style="font-family:courier new,monospace" size="2">function changeFilter(newValue, x, y)
<span></span>{ 
<span></span>  myLayer.destroyFeatures();
<span></span>  filter = new OpenLayers.Filter.Logical({ 
<span></span>    type: OpenLayers.Filter.Logical.AND, 
<span></span>    filters: [ 
<span></span>      new OpenLayers.Filter.Comparison({ 
<span></span>          type: OpenLayers.Filter.Comparison.EQUAL_TO, 
<span></span>          property: "_adresid", 
<span></span>          value: newValue 
<span></span>      }), 
<span></span>      new OpenLayers.Filter.Spatial({ 
<span></span>          type: OpenLayers.Filter.Spatial.BBOX, 
<span></span>          value: new OpenLayers.Bounds(x-50, y-50, x+50, y+50), 
<span></span>          projection: "EPSG:3857" 
<span></span>      }) 
<span></span>  ] 
<span></span>}); 
<span></span>  myLayer.filter = filter;
<span></span>  </font><font style="font-family:courier new,monospace" size="2">myLayer</font><font style="font-family:courier new,monospace" size="2">.refresh({force: true});<br>  showAttributes();<br></font><span><font style="font-family:courier new,monospace" size="2">}<br>

</font><br></span></pre>This is working great, but is does take a very long time: about 7-10 seconds.<br>The result are just a few features: 3-10<br><br>Of course I have an index in the database on _adresid and a spatial index.<br>


<br><b>Q2</b>: What else can I do to speed up this filter?<br><br>Thanks,<br>
<br>
Paul<br>